Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 59cb1e8

Browse files
committed
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>
1 parent 5ab5075 commit 59cb1e8

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

API-C.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ C Library for creating WebAssembly modules for use with NGINX Unit.
3838
* [luw_get_http_content](#luw_get_http_content)
3939
* [luw_get_http_content_len](#luw_get_http_content_len)
4040
* [luw_get_http_content_sent](#luw_get_http_content_sent)
41+
* [luw_get_http_total_content_sent](#luw_get_http_total_content_sent)
4142
* [luw_http_is_tls](#luw_http_is_tls)
4243
* [luw_http_hdr_iter](#luw_http_hdr_iter)
4344
* [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
657658
WebAssembly module in _this_ request. Remember, a single HTTP request may be
658659
split over several calls to luw_request_handler().
659660
661+
### luw_get_http_total_content_sent
662+
663+
```C
664+
size_t luw_get_http_total_content_sent(const luw_ctx_t *ctx);
665+
```
666+
667+
This function returns the total length of the content that was sent to the
668+
WebAssembly module so far. Remember, a single HTTP request may be split over
669+
several calls to luw_request_handler().
670+
660671
### luw_http_is_tls
661672

662673
```C

src/c/include/unit/unit-wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ extern const char *luw_get_http_server_name(const luw_ctx_t *ctx);
176176
extern const u8 *luw_get_http_content(const luw_ctx_t *ctx);
177177
extern size_t luw_get_http_content_len(const luw_ctx_t *ctx);
178178
extern size_t luw_get_http_content_sent(const luw_ctx_t *ctx);
179+
extern size_t luw_get_http_total_content_sent(const luw_ctx_t *ctx);
179180
extern bool luw_http_is_tls(const luw_ctx_t *ctx);
180181
extern void luw_http_hdr_iter(luw_ctx_t *ctx,
181182
bool (*luw_http_hdr_iter_func)(luw_ctx_t *ctx,

src/c/libunit-wasm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ size_t luw_get_http_content_sent(const luw_ctx_t *ctx)
207207
return ctx->req->content_sent;
208208
}
209209

210+
/* Returns the size of the overall content sent so far */
211+
size_t luw_get_http_total_content_sent(const luw_ctx_t *ctx)
212+
{
213+
return ctx->req->total_content_sent;
214+
}
215+
210216
bool luw_http_is_tls(const luw_ctx_t *ctx)
211217
{
212218
return ctx->req->tls;

0 commit comments

Comments
 (0)