From 65031ca3502e0c27780be847fd97c112546741a9 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 18 Nov 2023 00:56:04 +0100 Subject: Send HTTP headers to payload callback Even if libweb already parses some common headers, such as Content-Length, some users might find it interesting to inspect which headers were received from a request. Since HTTP/1.1 does not define a limit on the number of maximum headers a client can send, for security reasons a maximum value must be provided by the user. Any extra headers shall be then discarded by libweb. An example application showing this new feature is also provided. --- include/libweb/handler.h | 1 + include/libweb/http.h | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/libweb/handler.h b/include/libweb/handler.h index 9cde129..f7bc76a 100644 --- a/include/libweb/handler.h +++ b/include/libweb/handler.h @@ -13,6 +13,7 @@ struct handler_cfg int (*length)(unsigned long long len, const struct http_cookie *c, struct http_response *r, void *user); void *user; + size_t max_headers; }; struct handler *handler_alloc(const struct handler_cfg *cfg); diff --git a/include/libweb/http.h b/include/libweb/http.h index 80030fb..ddb6a89 100644 --- a/include/libweb/http.h +++ b/include/libweb/http.h @@ -5,6 +5,11 @@ #include #include +struct http_header +{ + char *header, *value; +}; + struct http_payload { enum http_op @@ -46,7 +51,8 @@ struct http_payload char *key, *value; } *args; - size_t n_args; + size_t n_args, n_headers; + const struct http_header *headers; }; #define HTTP_STATUSES \ @@ -69,10 +75,7 @@ struct http_response #undef X } status; - struct http_header - { - char *header, *value; - } *headers; + struct http_header *headers; union { @@ -96,6 +99,7 @@ struct http_cfg struct http_response *r, void *user); const char *tmpdir; void *user; + size_t max_headers; }; struct http_ctx *http_alloc(const struct http_cfg *cfg); -- cgit v1.2.3