aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-11-18 00:56:04 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-11-18 01:03:12 +0100
commit65031ca3502e0c27780be847fd97c112546741a9 (patch)
tree31c8ac5bb815baf5e4b63bde3af9076eb30a30ed /include
parentb71a6174e12b4709acaf8bc151938ba12d2a54f6 (diff)
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.
Diffstat (limited to 'include')
-rw-r--r--include/libweb/handler.h1
-rw-r--r--include/libweb/http.h14
2 files changed, 10 insertions, 5 deletions
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 <stddef.h>
#include <stdio.h>
+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);