2016-05-12 04:36:12 +08:00
|
|
|
---
|
|
|
|
title: "mg_http_parse_header()"
|
|
|
|
decl_name: "mg_http_parse_header"
|
|
|
|
symbol_kind: "func"
|
|
|
|
signature: |
|
|
|
|
int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf,
|
|
|
|
size_t buf_size);
|
|
|
|
---
|
|
|
|
|
2016-07-23 00:08:14 +08:00
|
|
|
Parse HTTP header `hdr`. Find variable `var_name` and store it's value
|
|
|
|
in the buffer `buf`, `buf_size`. Return 0 if variable not found, non-zero
|
2016-05-12 04:36:12 +08:00
|
|
|
otherwise.
|
|
|
|
|
|
|
|
This function is supposed to parse
|
2016-07-23 00:08:14 +08:00
|
|
|
cookies, authentication headers, etcetera. Example (error handling omitted):
|
2016-05-12 04:36:12 +08:00
|
|
|
|
|
|
|
char user[20];
|
|
|
|
struct mg_str *hdr = mg_get_http_header(hm, "Authorization");
|
|
|
|
mg_http_parse_header(hdr, "username", user, sizeof(user));
|
|
|
|
|
2016-07-23 00:08:14 +08:00
|
|
|
Return length of the variable's value. If buffer is not large enough,
|
2016-05-12 04:36:12 +08:00
|
|
|
or variable not found, 0 is returned.
|
|
|
|
|