mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-23 11:44:53 +00:00
Implement mg_http_parse_header2()
Which is a replacement of (deprecated) `mg_http_parse_header`, but, similarly to `asprintf`, allocates a new buffer if the client-provided one is not large enough. Also use it throughout mongoose code, and thus some header-related limitations are removed; in particular, https://github.com/cesanta/mongoose/issues/813 is fixed. CL: Mongoose Web Server: Deprecate `mg_http_parse_header()` and implement `mg_http_parse_header2()` instead, which allocates a new buffer if the client-provided one is not large enough (similarly to `asprintf`). CL: Mongoose Web Server: Fix limitations of header value lengths, e.g. when parsing authentication headers such as nonce, etc. PUBLISHED_FROM=c75b1bbbbdb294ea85075ce69b1368f115fdd1ef
This commit is contained in:
1 parent
a8a7d2cf7e
commit
b9b20c6494
10 files changed
+541
-109
No files matched your search
@@ -10,6 +10,7 @@ items:
|
||||
- { name: mg_get_http_var.md }
|
||||
- { name: mg_http_check_digest_auth.md }
|
||||
- { name: mg_http_parse_header.md }
|
||||
- { name: mg_http_parse_header2.md }
|
||||
- { name: mg_http_reverse_proxy.md }
|
||||
- { name: mg_http_send_error.md }
|
||||
- { name: mg_http_send_redirect.md }
|
||||
|
||||
@@ -7,17 +7,9 @@ signature: |
|
||||
size_t buf_size);
|
||||
---
|
||||
|
||||
Parses the HTTP header `hdr`. Finds variable `var_name` and stores its value
|
||||
in the buffer `buf`, `buf_size`. Returns 0 if variable not found, non-zero
|
||||
otherwise.
|
||||
DEPRECATED: use mg_http_parse_header2() instead.
|
||||
|
||||
This function is supposed to parse cookies, authentication headers, etc.
|
||||
Example (error handling omitted):
|
||||
|
||||
char user[20];
|
||||
struct mg_str *hdr = mg_get_http_header(hm, "Authorization");
|
||||
mg_http_parse_header(hdr, "username", user, sizeof(user));
|
||||
|
||||
Returns the length of the variable's value. If buffer is not large enough,
|
||||
or variable not found, 0 is returned.
|
||||
Same as mg_http_parse_header2(), but takes buffer as a `char *` (instead of
|
||||
`char **`), and thus it cannot allocate a new buffer if the provided one
|
||||
is not enough, and just returns 0 in that case.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
title: "mg_http_parse_header2()"
|
||||
decl_name: "mg_http_parse_header2"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
int mg_http_parse_header2(struct mg_str *hdr, const char *var_name, char **buf,
|
||||
size_t buf_size);
|
||||
---
|
||||
|
||||
Parses the HTTP header `hdr`. Finds variable `var_name` and stores its value
|
||||
in the buffer `*buf`, `buf_size`. If the buffer size is not enough,
|
||||
allocates a buffer of required size and writes it to `*buf`, similar to
|
||||
asprintf(). The caller should always check whether the buffer was updated,
|
||||
and free it if so.
|
||||
|
||||
This function is supposed to parse cookies, authentication headers, etc.
|
||||
Example (error handling omitted):
|
||||
|
||||
char user_buf[20];
|
||||
char *user = user_buf;
|
||||
struct mg_str *hdr = mg_get_http_header(hm, "Authorization");
|
||||
mg_http_parse_header2(hdr, "username", &user, sizeof(user_buf));
|
||||
// ... do something useful with user
|
||||
if (user != user_buf) {
|
||||
free(user);
|
||||
}
|
||||
|
||||
Returns the length of the variable's value. If variable is not found, 0 is
|
||||
returned.
|
||||
|
||||
Reference in new issue
Block a user