diff --git a/docs/man/nng_http_req_get_header.3http.adoc b/docs/man/nng_http_req_get_header.3http.adoc index 2b01f959d..cbc6ec493 100644 --- a/docs/man/nng_http_req_get_header.3http.adoc +++ b/docs/man/nng_http_req_get_header.3http.adoc @@ -20,7 +20,7 @@ nng_http_req_get_header - return HTTP request header #include #include -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 diff --git a/docs/man/nng_http_req_get_method.3http.adoc b/docs/man/nng_http_req_get_method.3http.adoc index 85e81278b..20f6010b1 100644 --- a/docs/man/nng_http_req_get_method.3http.adoc +++ b/docs/man/nng_http_req_get_method.3http.adoc @@ -20,7 +20,7 @@ nng_http_req_get_method - return HTTP request method #include #include -const char *nng_http_req_get_method(nng_http_req *req); +const char *nng_http_req_get_method(const nng_http_req *req); ---- == DESCRIPTION diff --git a/docs/man/nng_http_req_get_uri.3http.adoc b/docs/man/nng_http_req_get_uri.3http.adoc index 6239efce8..8e664a1fd 100644 --- a/docs/man/nng_http_req_get_uri.3http.adoc +++ b/docs/man/nng_http_req_get_uri.3http.adoc @@ -20,7 +20,7 @@ nng_http_req_get_uri - return HTTP request URI #include #include -const char *nng_http_req_get_uri(nng_http_req *req); +const char *nng_http_req_get_uri(const nng_http_req *req); ---- == DESCRIPTION diff --git a/docs/man/nng_http_req_get_version.3http.adoc b/docs/man/nng_http_req_get_version.3http.adoc index ef526df83..537f6caf3 100644 --- a/docs/man/nng_http_req_get_version.3http.adoc +++ b/docs/man/nng_http_req_get_version.3http.adoc @@ -20,7 +20,7 @@ nng_http_req_get_version - return HTTP request protocol version #include #include -const char *nng_http_req_get_version(nng_http_req *req); +const char *nng_http_req_get_version(const nng_http_req *req); ---- == DESCRIPTION diff --git a/docs/man/nng_http_res_get_header.3http.adoc b/docs/man/nng_http_res_get_header.3http.adoc index 34c5b0150..51d37abab 100644 --- a/docs/man/nng_http_res_get_header.3http.adoc +++ b/docs/man/nng_http_res_get_header.3http.adoc @@ -20,7 +20,7 @@ nng_http_res_get_header - return HTTP response header #include #include -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 diff --git a/docs/man/nng_http_res_get_reason.3http.adoc b/docs/man/nng_http_res_get_reason.3http.adoc index a4167a0ac..3b9fdd587 100644 --- a/docs/man/nng_http_res_get_reason.3http.adoc +++ b/docs/man/nng_http_res_get_reason.3http.adoc @@ -20,7 +20,7 @@ nng_http_res_get_reason - return HTTP response reason #include #include -const char *nng_http_res_get_reason(nng_http_res *res); +const char *nng_http_res_get_reason(const nng_http_res *res); ---- == DESCRIPTION diff --git a/docs/man/nng_http_res_get_status.3http.adoc b/docs/man/nng_http_res_get_status.3http.adoc index 0ad9092ad..827cfbf6b 100644 --- a/docs/man/nng_http_res_get_status.3http.adoc +++ b/docs/man/nng_http_res_get_status.3http.adoc @@ -20,7 +20,7 @@ nng_http_res_get_status - return HTTP status code #include #include -uint16_t nng_http_res_get_status(nng_http_res *res); +uint16_t nng_http_res_get_status(const nng_http_res *res); ---- == DESCRIPTION diff --git a/include/nng/supplemental/http/http.h b/include/nng/supplemental/http/http.h index ff8616ca3..fa81f984d 100644 --- a/include/nng/supplemental/http/http.h +++ b/include/nng/supplemental/http/http.h @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2020 Dirac Research // @@ -22,7 +22,7 @@ extern "C" { #include -struct nng_tls_config; +#include // HTTP status codes. This list is not exhaustive. enum nng_http_status { @@ -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. @@ -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. @@ -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. @@ -202,7 +203,8 @@ 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 @@ -210,7 +212,7 @@ NNG_DECL const char *nng_http_res_get_header(nng_http_res *, const char *); 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 *); @@ -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 @@ -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 diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index dbda53ae9..46a022113 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -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 *); @@ -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 diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c index 2c258e2c0..5a0baf370 100644 --- a/src/supplemental/http/http_msg.c +++ b/src/supplemental/http/http_msg.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -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) { @@ -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)); } @@ -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"); } @@ -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); } @@ -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)); } diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 633f83c78..161aefd88 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -72,7 +72,7 @@ nng_http_res_alloc_error(nng_http_res **resp, uint16_t code) } const char * -nng_http_req_get_header(nng_http_req *req, const char *key) +nng_http_req_get_header(const nng_http_req *req, const char *key) { #ifdef NNG_SUPP_HTTP return (nni_http_req_get_header(req, key)); @@ -84,7 +84,7 @@ nng_http_req_get_header(nng_http_req *req, const char *key) } const char * -nng_http_res_get_header(nng_http_res *res, const char *key) +nng_http_res_get_header(const nng_http_res *res, const char *key) { #ifdef NNG_SUPP_HTTP return (nni_http_res_get_header(res, key)); @@ -248,7 +248,7 @@ nng_http_res_get_data(nng_http_res *res, void **datap, size_t *lenp) } const char * -nng_http_req_get_method(nng_http_req *req) +nng_http_req_get_method(const nng_http_req *req) { #ifdef NNG_SUPP_HTTP return (nni_http_req_get_method(req)); @@ -259,7 +259,7 @@ nng_http_req_get_method(nng_http_req *req) } const char * -nng_http_req_get_version(nng_http_req *req) +nng_http_req_get_version(const nng_http_req *req) { #ifdef NNG_SUPP_HTTP return (nni_http_req_get_version(req)); @@ -270,7 +270,7 @@ nng_http_req_get_version(nng_http_req *req) } const char * -nng_http_req_get_uri(nng_http_req *req) +nng_http_req_get_uri(const nng_http_req *req) { #ifdef NNG_SUPP_HTTP return (nni_http_req_get_uri(req)); @@ -317,7 +317,7 @@ nng_http_req_set_uri(nng_http_req *req, const char *uri) } uint16_t -nng_http_res_get_status(nng_http_res *res) +nng_http_res_get_status(const nng_http_res *res) { #ifdef NNG_SUPP_HTTP return (nni_http_res_get_status(res)); @@ -328,7 +328,7 @@ nng_http_res_get_status(nng_http_res *res) } const char * -nng_http_res_get_version(nng_http_res *res) +nng_http_res_get_version(const nng_http_res *res) { #ifdef NNG_SUPP_HTTP return (nni_http_res_get_version(res)); @@ -339,7 +339,7 @@ nng_http_res_get_version(nng_http_res *res) } const char * -nng_http_res_get_reason(nng_http_res *res) +nng_http_res_get_reason(const nng_http_res *res) { #ifdef NNG_SUPP_HTTP return (nni_http_res_get_reason(res)); @@ -765,7 +765,7 @@ nng_http_server_set_error_file( } int -nng_http_server_set_tls(nng_http_server *srv, struct nng_tls_config *cfg) +nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_set_tls(srv, cfg)); @@ -777,7 +777,7 @@ nng_http_server_set_tls(nng_http_server *srv, struct nng_tls_config *cfg) } int -nng_http_server_get_tls(nng_http_server *srv, struct nng_tls_config **cfg) +nng_http_server_get_tls(nng_http_server *srv, nng_tls_config **cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_get_tls(srv, cfg)); @@ -850,7 +850,7 @@ nng_http_client_free(nng_http_client *cli) } int -nng_http_client_set_tls(nng_http_client *cli, struct nng_tls_config *cfg) +nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_client_set_tls(cli, cfg)); @@ -862,7 +862,7 @@ nng_http_client_set_tls(nng_http_client *cli, struct nng_tls_config *cfg) } int -nng_http_client_get_tls(nng_http_client *cli, struct nng_tls_config **cfgp) +nng_http_client_get_tls(nng_http_client *cli, nng_tls_config **cfgp) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_client_get_tls(cli, cfgp));