diff options
| author | Andrew Clayton <a.clayton@nginx.com> | 2023-09-14 21:58:58 +0100 |
|---|---|---|
| committer | Andrew Clayton <a.clayton@nginx.com> | 2023-09-25 17:36:24 +0100 |
| commit | 1dd1b34194573661b10015fbc60d6910dbea8fcc (patch) | |
| tree | 6c6359b58c0ae90edfc0643823de7589228e9fa6 /src/c/include/unit/unit-wasm.h | |
| parent | 263541e24546ba0a75e26fef3c5442238d9fcac2 (diff) | |
| download | unit-wasm-1dd1b34194573661b10015fbc60d6910dbea8fcc.tar.gz unit-wasm-1dd1b34194573661b10015fbc60d6910dbea8fcc.tar.bz2 | |
libunit-wasm: Add a luw_req_buf_copy() function
This is analogous to luw_req_buf_append() but rather than appending
request data to the buffer it simply overwrites what's currently there.
This is needed to take advantage of the new ability to receive >4GiB
requests/payloads.
On a new request you would call luw_init_ctx(), luw_set_req_buf() &
open(2).
On subsequent calls to the request_handler (for this same HTTP
request/upload) you would call this new function and then write out the
data to a file.
E.g
/* In the request_handler */
if (total_bytes_wrote == 0) {
luw_init_ctx(&ctx, addr, 0);
luw_set_req_buf(&ctx, &request_buf, LUW_SRB_NONE);
fd = open("/var/tmp/large-file.dat", O_CREAT|O_TRUNC|O_WRONLY,
0666);
} else {
luw_req_buf_copy(&ctx, addr);
}
buf = luw_get_http_content(&ctx);
bytes_wrote = write(fd, buf, luw_get_http_content_sent(&ctx));
total_bytes_wrote += bytes_wrote;
if (total_bytes_wrote == luw_get_http_content_len(&ctx)) {
close(fd);
total_bytes_wrote = 0;
luw_http_response_end();
}
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to '')
| -rw-r--r-- | src/c/include/unit/unit-wasm.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/c/include/unit/unit-wasm.h b/src/c/include/unit/unit-wasm.h index f698c97..48079b1 100644 --- a/src/c/include/unit/unit-wasm.h +++ b/src/c/include/unit/unit-wasm.h @@ -238,6 +238,7 @@ extern size_t luw_get_response_data_size(const luw_ctx_t *ctx); extern int luw_mem_writep(luw_ctx_t *ctx, const char *fmt, ...); extern size_t luw_mem_writep_data(luw_ctx_t *ctx, const u8 *src, size_t size); extern void luw_req_buf_append(luw_ctx_t *ctx, const u8 *src); +extern void luw_req_buf_copy(luw_ctx_t *ctx, const u8 *src); extern size_t luw_mem_fill_buf_from_req(luw_ctx_t *ctx, size_t from); extern void luw_mem_reset(luw_ctx_t *ctx); extern void luw_http_set_response_status(luw_http_status_t status); |
