From da5d9dc03b14b4d0f1ce0ce3ff093f387e148706 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Mon, 28 Aug 2023 16:11:15 +0100 Subject: libunit-wasm: Remove the idx argument from luw_http_add_header() This was used to specify the index of the response header being added, starting at 0 and incrementing by one for each header. Instead of having the programmer specify this, track it internally. We add an extra check in luw_http_add_header() to make sure we aren't trying to add more headers than we said with luw_http_init_headers(), if we are, simply return. This updates the API-C.md and the various examples and 'rusty' API wrapper. Suggested-by: Liam Crilly Signed-off-by: Andrew Clayton --- src/c/include/unit/unit-wasm.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/c/include') diff --git a/src/c/include/unit/unit-wasm.h b/src/c/include/unit/unit-wasm.h index dedf15a..cfff906 100644 --- a/src/c/include/unit/unit-wasm.h +++ b/src/c/include/unit/unit-wasm.h @@ -118,6 +118,9 @@ typedef struct { /* points to the end of ctx->req_buf */ u8 *reqp; + + /* tracks the response header index number */ + s32 resp_hdr_idx; } luw_ctx_t; typedef enum { @@ -189,7 +192,7 @@ 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_send_response(const luw_ctx_t *ctx); extern void luw_http_init_headers(luw_ctx_t *ctx, size_t nr, size_t offset); -extern void luw_http_add_header(luw_ctx_t *ctx, u16 idx, const char *name, +extern void luw_http_add_header(luw_ctx_t *ctx, const char *name, const char *value); extern void luw_http_send_headers(const luw_ctx_t *ctx); extern void luw_http_response_end(void); -- cgit