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 --- API-C.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'API-C.md') diff --git a/API-C.md b/API-C.md index 1899f05..c0cfc02 100644 --- a/API-C.md +++ b/API-C.md @@ -212,6 +212,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; ``` @@ -864,14 +867,11 @@ luw_http_init_headers(ctx, 2, 0); ### luw_http_add_header ```C -void luw_http_add_header(luw_ctx_t *ctx, u16 idx, const char *name, - const char *value); +void luw_http_add_header(luw_ctx_t *ctx, const char *name, const char *value); ``` This function is used to add a header to the response. -_idx_ is the index (starting at 0) of the header we are adding. - _name_ is the name of the header. _value_ is the value of the header. @@ -882,8 +882,8 @@ Example char clen[32]; /* ... */ snprintf(clen, sizeof(clen), "%lu", luw_get_response_data_size(&ctx)); -luw_http_add_header(&ctx, 0, "Content-Type", "text/plain"); -luw_http_add_header(&ctx, 1, "Content-Length", clen); +luw_http_add_header(&ctx, "Content-Type", "text/plain"); +luw_http_add_header(&ctx, "Content-Length", clen); ``` ### luw_http_send_headers -- cgit