Skip to content

Commit

Permalink
http: constify some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Nov 24, 2024
1 parent c79d87a commit a2b6d6a
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docs/man/nng_http_req_get_header.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_req_get_header - return HTTP request header
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_header(nng_http_req *req, const char *key);
const char *nng_http_req_get_header(const nng_http_req *req, const char *key);
----

== DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nng_http_req_get_method.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_req_get_method - return HTTP request method
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_method(nng_http_req *req);
const char *nng_http_req_get_method(const nng_http_req *req);
----

== DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nng_http_req_get_uri.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_req_get_uri - return HTTP request URI
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_uri(nng_http_req *req);
const char *nng_http_req_get_uri(const nng_http_req *req);
----

== DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nng_http_req_get_version.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_req_get_version - return HTTP request protocol version
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
const char *nng_http_req_get_version(nng_http_req *req);
const char *nng_http_req_get_version(const nng_http_req *req);
----

== DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nng_http_res_get_header.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_res_get_header - return HTTP response header
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
const char *nng_http_res_get_header(nng_http_res *res, const char *key);
const char *nng_http_res_get_header(const nng_http_res *res, const char *key);
----

== DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nng_http_res_get_reason.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_res_get_reason - return HTTP response reason
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
const char *nng_http_res_get_reason(nng_http_res *res);
const char *nng_http_res_get_reason(const nng_http_res *res);
----

== DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion docs/man/nng_http_res_get_status.3http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nng_http_res_get_status - return HTTP status code
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
uint16_t nng_http_res_get_status(nng_http_res *res);
uint16_t nng_http_res_get_status(const nng_http_res *res);
----

== DESCRIPTION
Expand Down
34 changes: 16 additions & 18 deletions include/nng/supplemental/http/http.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2020 Dirac Research <[email protected]>
//
Expand All @@ -22,7 +22,7 @@ extern "C" {

#include <stdint.h>

struct nng_tls_config;
#include <nng/nng.h>

// HTTP status codes. This list is not exhaustive.
enum nng_http_status {
Expand Down Expand Up @@ -101,14 +101,14 @@ NNG_DECL int nng_http_req_alloc(nng_http_req **, const nng_url *);
NNG_DECL void nng_http_req_free(nng_http_req *);

// nng_http_req_get_method returns the method.
NNG_DECL const char *nng_http_req_get_method(nng_http_req *);
NNG_DECL const char *nng_http_req_get_method(const nng_http_req *);

// nng_http_req_get_version returns the version, usually HTTP/1.1.
NNG_DECL const char *nng_http_req_get_version(nng_http_req *);
NNG_DECL const char *nng_http_req_get_version(const nng_http_req *);

// nng_http_req_get_uri returns the "abs-uri", which is URL without
// the scheme, host, or port.
NNG_DECL const char *nng_http_req_get_uri(nng_http_req *);
NNG_DECL const char *nng_http_req_get_uri(const nng_http_req *);

// nng_http_req_set_header sets an HTTP header, replacing any previous value
// that might have been present.
Expand All @@ -125,7 +125,8 @@ NNG_DECL int nng_http_req_del_header(nng_http_req *, const char *);

// nng_http_req_get_header looks up a header with the named, returns NULL
// if not found.
NNG_DECL const char *nng_http_req_get_header(nng_http_req *, const char *);
NNG_DECL const char *nng_http_req_get_header(
const nng_http_req *, const char *);

// nng_http_req_set_method is used to change the method of a request.
// The method should be an upper case HTTP method, like POST, or DELETE.
Expand Down Expand Up @@ -174,14 +175,14 @@ NNG_DECL int nng_http_res_alloc_error(nng_http_res **, uint16_t);
NNG_DECL void nng_http_res_free(nng_http_res *);

// nng_http_res_get_status returns the HTTP status code from the server.
NNG_DECL uint16_t nng_http_res_get_status(nng_http_res *);
NNG_DECL uint16_t nng_http_res_get_status(const nng_http_res *);

// nng_http_res_set_status sets the HTTP status code.
NNG_DECL int nng_http_res_set_status(nng_http_res *, uint16_t);

// nng_http_res_get_reason returns the human readable status message
// that the server responds (or responded) with.
NNG_DECL const char *nng_http_res_get_reason(nng_http_res *);
NNG_DECL const char *nng_http_res_get_reason(const nng_http_res *);

// nng_http_res_set_reason sets the human readable status message.
// NULL means that a default reason is used based on the status code.
Expand All @@ -202,15 +203,16 @@ NNG_DECL int nng_http_res_del_header(nng_http_res *, const char *);

// nng_http_res_get_header looks up a header with the named, returns NULL
// if not found.
NNG_DECL const char *nng_http_res_get_header(nng_http_res *, const char *);
NNG_DECL const char *nng_http_res_get_header(
const nng_http_res *, const char *);

// nng_http_res_set_version is used to change the version of a response.
// Normally the version is "HTTP/1.1". Note that the framework does
// not support HTTP/2 at all. NULL sets the default ("HTTP/1.1").
NNG_DECL int nng_http_res_set_version(nng_http_res *, const char *);

// nng_http_res_get_version returns the version, usually HTTP/1.1.
NNG_DECL const char *nng_http_res_get_version(nng_http_res *);
NNG_DECL const char *nng_http_res_get_version(const nng_http_res *);

// nng_http_res_get_data gets the data for the response.
NNG_DECL void nng_http_res_get_data(nng_http_res *, void **, size_t *);
Expand Down Expand Up @@ -437,14 +439,12 @@ NNG_DECL int nng_http_server_del_handler(
// server client, so the caller must have configured it reasonably.
// This API is not recommended unless the caller needs complete control
// over the TLS configuration.
NNG_DECL int nng_http_server_set_tls(
nng_http_server *, struct nng_tls_config *);
NNG_DECL int nng_http_server_set_tls(nng_http_server *, nng_tls_config *);

// nng_http_server_get_tls obtains the TLS configuration if one is present,
// or returns NNG_EINVAL. The TLS configuration is invalidated if the
// nng_http_server_set_tls function is called, so be careful.
NNG_DECL int nng_http_server_get_tls(
nng_http_server *, struct nng_tls_config **);
NNG_DECL int nng_http_server_get_tls(nng_http_server *, nng_tls_config **);

// nng_http_server_get_addr obtains the address with which the server was
// initialized or returns NNG_EINVAL. Useful for instance when the port has
Expand Down Expand Up @@ -504,14 +504,12 @@ NNG_DECL void nng_http_client_free(nng_http_client *);
// the entire TLS configuration on the client, so the caller must have
// configured it reasonably. This API is not recommended unless the
// caller needs complete control over the TLS configuration.
NNG_DECL int nng_http_client_set_tls(
nng_http_client *, struct nng_tls_config *);
NNG_DECL int nng_http_client_set_tls(nng_http_client *, nng_tls_config *);

// nng_http_client_get_tls obtains the TLS configuration if one is present,
// or returns NNG_EINVAL. The supplied TLS configuration object may
// be invalidated by any future calls to nni_http_client_set_tls.
NNG_DECL int nng_http_client_get_tls(
nng_http_client *, struct nng_tls_config **);
NNG_DECL int nng_http_client_get_tls(nng_http_client *, nng_tls_config **);

// nng_http_client_connect establishes a new connection with the server
// named in the URL used when the client was created. Once the connection
Expand Down
16 changes: 8 additions & 8 deletions src/supplemental/http/http_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ extern void nni_http_write_res(nni_http_conn *, nni_http_res *, nni_aio *);
extern void nni_http_read_req(nni_http_conn *, nni_http_req *, nni_aio *);
extern void nni_http_read_res(nni_http_conn *, nni_http_res *, nni_aio *);

extern const char *nni_http_req_get_header(nni_http_req *, const char *);
extern const char *nni_http_res_get_header(nni_http_res *, const char *);
extern const char *nni_http_req_get_header(const nni_http_req *, const char *);
extern const char *nni_http_res_get_header(const nni_http_res *, const char *);
extern int nni_http_req_add_header(nni_http_req *, const char *, const char *);
extern int nni_http_res_add_header(nni_http_res *, const char *, const char *);
extern int nni_http_req_set_header(nni_http_req *, const char *, const char *);
Expand All @@ -132,17 +132,17 @@ extern int nni_http_req_set_data(nni_http_req *, const void *, size_t);
extern int nni_http_res_set_data(nni_http_res *, const void *, size_t);
extern int nni_http_req_alloc_data(nni_http_req *, size_t);
extern int nni_http_res_alloc_data(nni_http_res *, size_t);
extern const char *nni_http_req_get_method(nni_http_req *);
extern const char *nni_http_req_get_version(nni_http_req *);
extern const char *nni_http_req_get_uri(nni_http_req *);
extern const char *nni_http_req_get_method(const nni_http_req *);
extern const char *nni_http_req_get_version(const nni_http_req *);
extern const char *nni_http_req_get_uri(const nni_http_req *);
extern int nni_http_req_set_method(nni_http_req *, const char *);
extern int nni_http_req_set_version(nni_http_req *, const char *);
extern int nni_http_req_set_uri(nni_http_req *, const char *);
extern uint16_t nni_http_res_get_status(nni_http_res *);
extern uint16_t nni_http_res_get_status(const nni_http_res *);
extern int nni_http_res_set_status(nni_http_res *, uint16_t);
extern const char *nni_http_res_get_version(nni_http_res *);
extern const char *nni_http_res_get_version(const nni_http_res *);
extern int nni_http_res_set_version(nni_http_res *, const char *);
extern const char *nni_http_res_get_reason(nni_http_res *);
extern const char *nni_http_res_get_reason(const nni_http_res *);
extern int nni_http_res_set_reason(nni_http_res *, const char *);

// nni_http_res_is_error is true if the status was allocated as part of
Expand Down
20 changes: 10 additions & 10 deletions src/supplemental/http/http_msg.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2019 Staysail Systems, Inc. <[email protected]>
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -262,7 +262,7 @@ nni_http_res_add_header(nni_http_res *res, const char *key, const char *val)
}

static const char *
http_get_header(nni_list *hdrs, const char *key)
http_get_header(const nni_list *hdrs, const char *key)
{
http_header *h;
NNI_LIST_FOREACH (hdrs, h) {
Expand All @@ -274,13 +274,13 @@ http_get_header(nni_list *hdrs, const char *key)
}

const char *
nni_http_req_get_header(nni_http_req *req, const char *key)
nni_http_req_get_header(const nni_http_req *req, const char *key)
{
return (http_get_header(&req->hdrs, key));
}

const char *
nni_http_res_get_header(nni_http_res *res, const char *key)
nni_http_res_get_header(const nni_http_res *res, const char *key)
{
return (http_get_header(&res->hdrs, key));
}
Expand Down Expand Up @@ -672,25 +672,25 @@ nni_http_res_alloc(nni_http_res **resp)
}

const char *
nni_http_req_get_method(nni_http_req *req)
nni_http_req_get_method(const nni_http_req *req)
{
return (req->meth != NULL ? req->meth : "GET");
}

const char *
nni_http_req_get_uri(nni_http_req *req)
nni_http_req_get_uri(const nni_http_req *req)
{
return (req->uri != NULL ? req->uri : "");
}

const char *
nni_http_req_get_version(nni_http_req *req)
nni_http_req_get_version(const nni_http_req *req)
{
return (req->vers != NULL ? req->vers : "HTTP/1.1");
}

const char *
nni_http_res_get_version(nni_http_res *res)
nni_http_res_get_version(const nni_http_res *res)
{
return (res->vers != NULL ? res->vers : "HTTP/1.1");
}
Expand Down Expand Up @@ -736,7 +736,7 @@ nni_http_res_set_status(nni_http_res *res, uint16_t status)
}

uint16_t
nni_http_res_get_status(nni_http_res *res)
nni_http_res_get_status(const nni_http_res *res)
{
return (res->code);
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ nni_http_reason(uint16_t code)
}

const char *
nni_http_res_get_reason(nni_http_res *res)
nni_http_res_get_reason(const nni_http_res *res)
{
return (res->rsn ? res->rsn : nni_http_reason(res->code));
}
Expand Down
Loading

0 comments on commit a2b6d6a

Please sign in to comment.