diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/supplemental/http/http.h | 6 | ||||
| -rw-r--r-- | src/supplemental/http/http_client.c | 1 | ||||
| -rw-r--r-- | src/supplemental/http/http_msg.c | 25 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 16 |
4 files changed, 33 insertions, 15 deletions
diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h index f6656fce..cffd1a8b 100644 --- a/src/supplemental/http/http.h +++ b/src/supplemental/http/http.h @@ -275,6 +275,12 @@ NNG_DECL void nng_http_conn_read_req( NNG_DECL void nng_http_conn_read_res( nng_http_conn *, nng_http_res *, nng_aio *); +// nng_http_req_reset resets the request to an initially allocated state. +NNG_DECL void nng_http_req_reset(nng_http_req *); + +// nng_http_res_reset resets the response to an initially allocated state. +NNG_DECL void nng_http_res_reset(nng_http_res *); + // nng_http_handler is a handler used on the server side to handle HTTP // requests coming into a specific URL. typedef struct nng_http_handler nng_http_handler; diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c index f8b1c8ab..a61f7884 100644 --- a/src/supplemental/http/http_client.c +++ b/src/supplemental/http/http_client.c @@ -303,6 +303,7 @@ http_txn_reap(void *arg) // We only close the connection if we created it. if (txn->conn != NULL) { nni_http_conn_fini(txn->conn); + txn->conn = NULL; } } nni_aio_fini(txn->aio); diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c index 1a651352..6d7e9f8a 100644 --- a/src/supplemental/http/http_msg.c +++ b/src/supplemental/http/http_msg.c @@ -103,9 +103,9 @@ nni_http_req_reset(nni_http_req *req) nni_strfree(req->meth); nni_strfree(req->uri); req->vers = req->meth = req->uri = NULL; - if (req->bufsz) { - req->buf[0] = '\0'; - } + nni_free(req->buf, req->bufsz); + req->bufsz = 0; + req->buf = NULL; req->parsed = false; } @@ -120,18 +120,15 @@ nni_http_res_reset(nni_http_res *res) res->rsn = NULL; res->code = 0; res->parsed = false; - if (res->bufsz) { - res->buf[0] = '\0'; - } + nni_free(res->buf, res->bufsz); + res->buf = NULL; + res->bufsz = 0; } void nni_http_req_free(nni_http_req *req) { nni_http_req_reset(req); - if (req->bufsz) { - nni_free(req->buf, req->bufsz); - } NNI_FREE_STRUCT(req); } @@ -139,9 +136,6 @@ void nni_http_res_free(nni_http_res *res) { nni_http_res_reset(res); - if (res->bufsz) { - nni_free(res->buf, res->bufsz); - } NNI_FREE_STRUCT(res); } @@ -490,7 +484,7 @@ http_asprintf(char **bufp, size_t *szp, nni_list *hdrs, const char *fmt, ...) va_end(ap); len += http_sprintf_headers(NULL, 0, hdrs); - len += 5; // \r\n\r\n\0 + len += 3; // \r\n\0 if (len <= *szp) { buf = *bufp; @@ -511,6 +505,7 @@ http_asprintf(char **bufp, size_t *szp, nni_list *hdrs, const char *fmt, ...) buf += n; len -= n; snprintf(buf, len, "\r\n"); + NNI_ASSERT(len == 3); return (0); } @@ -572,7 +567,7 @@ nni_http_req_get_buf(nni_http_req *req, void **data, size_t *szp) return (rv); } *data = req->buf; - *szp = strlen(req->buf); + *szp = req->bufsz - 1; // exclude terminating NUL return (0); } @@ -585,7 +580,7 @@ nni_http_res_get_buf(nni_http_res *res, void **data, size_t *szp) return (rv); } *data = res->buf; - *szp = strlen(res->buf); + *szp = res->bufsz - 1; // exclude terminating NUL return (0); } diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 84811e54..389b74c8 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -867,3 +867,19 @@ nng_http_conn_transact( } #endif } + +void +nng_http_req_reset(nng_http_req *req) +{ +#ifdef NNG_SUPP_HTTP + nni_http_req_reset(req); +#endif +} + +void +nng_http_res_reset(nng_http_res *res) +{ +#ifdef NNG_SUPP_HTTP + nni_http_res_reset(res); +#endif +} |
