diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2023-08-29 22:22:01 +0100 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2023-08-29 23:12:56 +0100 |
commit | 59cb1e8000e1b18e317cb1c19185eb3a1b5d4e9f (patch) | |
tree | 12b36375a6a17ffae594b99c6b4b0951d911ae0b | |
parent | 5ab50752824ca605cb9a03da9807d70f588d9a6b (diff) | |
download | unit-wasm-59cb1e8000e1b18e317cb1c19185eb3a1b5d4e9f.tar.gz unit-wasm-59cb1e8000e1b18e317cb1c19185eb3a1b5d4e9f.tar.bz2 |
libunit-wasm: Add a luw_get_http_total_content_sent() function
This function returns the total amount of content that the Wasm module
has received so far.
This will be used in the rusty API's uwr_get_http_content_str() function
which returns the body content as a string. Due to the body content not
being null-terminated we need to know how much data to use for the
string, for which we are currently using uwr_get_http_content_len(),
which could in some cases return too much if a request is being split
over multiple calls the module.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r-- | API-C.md | 11 | ||||
-rw-r--r-- | src/c/include/unit/unit-wasm.h | 1 | ||||
-rw-r--r-- | src/c/libunit-wasm.c | 6 |
3 files changed, 18 insertions, 0 deletions
@@ -38,6 +38,7 @@ C Library for creating WebAssembly modules for use with NGINX Unit. * [luw_get_http_content](#luw_get_http_content) * [luw_get_http_content_len](#luw_get_http_content_len) * [luw_get_http_content_sent](#luw_get_http_content_sent) + * [luw_get_http_total_content_sent](#luw_get_http_total_content_sent) * [luw_http_is_tls](#luw_http_is_tls) * [luw_http_hdr_iter](#luw_http_hdr_iter) * [luw_http_hdr_get_value](#luw_http_hdr_get_value) @@ -657,6 +658,16 @@ This function returns the length of the content that was sent to the WebAssembly module in _this_ request. Remember, a single HTTP request may be split over several calls to luw_request_handler(). +### luw_get_http_total_content_sent + +```C +size_t luw_get_http_total_content_sent(const luw_ctx_t *ctx); +``` + +This function returns the total length of the content that was sent to the +WebAssembly module so far. Remember, a single HTTP request may be split over +several calls to luw_request_handler(). + ### luw_http_is_tls ```C diff --git a/src/c/include/unit/unit-wasm.h b/src/c/include/unit/unit-wasm.h index cc14b9d..834e4f1 100644 --- a/src/c/include/unit/unit-wasm.h +++ b/src/c/include/unit/unit-wasm.h @@ -176,6 +176,7 @@ extern const char *luw_get_http_server_name(const luw_ctx_t *ctx); extern const u8 *luw_get_http_content(const luw_ctx_t *ctx); extern size_t luw_get_http_content_len(const luw_ctx_t *ctx); extern size_t luw_get_http_content_sent(const luw_ctx_t *ctx); +extern size_t luw_get_http_total_content_sent(const luw_ctx_t *ctx); extern bool luw_http_is_tls(const luw_ctx_t *ctx); extern void luw_http_hdr_iter(luw_ctx_t *ctx, bool (*luw_http_hdr_iter_func)(luw_ctx_t *ctx, diff --git a/src/c/libunit-wasm.c b/src/c/libunit-wasm.c index c0c02c5..69fe4c0 100644 --- a/src/c/libunit-wasm.c +++ b/src/c/libunit-wasm.c @@ -207,6 +207,12 @@ size_t luw_get_http_content_sent(const luw_ctx_t *ctx) return ctx->req->content_sent; } +/* Returns the size of the overall content sent so far */ +size_t luw_get_http_total_content_sent(const luw_ctx_t *ctx) +{ + return ctx->req->total_content_sent; +} + bool luw_http_is_tls(const luw_ctx_t *ctx) { return ctx->req->tls; |