mg_http_parse_header.md 769 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
---
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);
---

10 11
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
12 13
otherwise.

14 15
This function is supposed to parse cookies, authentication headers, etc.
Example (error handling omitted):
16 17 18 19 20

    char user[20];
    struct mg_str *hdr = mg_get_http_header(hm, "Authorization");
    mg_http_parse_header(hdr, "username", user, sizeof(user));

21
Returns the length of the variable's value. If buffer is not large enough,
22 23
or variable not found, 0 is returned.