Browse Source

[core] http_header_hkey_get_lc() for HTTP/2

header field-names are required to be lowercase for HTTP/2
so specialize http_header_hkey_get() as http_header_hkey_get_lc()
for simpler comparison

lowercase field-names in http_headers[], as it does not matter for
buffer_eq_icase_ssn(), which is used with http_headers[] for HTTP/1.x
master
Glenn Strauss 1 year ago
parent
commit
92e5a021d2
  1. 69
      src/http_header.c
  2. 2
      src/http_header.h
  3. 2
      src/request.c

69
src/http_header.c

@ -29,35 +29,35 @@ int8_t http_headers_off[] = {
-1, -1, -1, -1, 0, 4, 5, 9, 10, 11, 12, -1, 15, 16, 20, 22, 24, 26
};
static const keyvlenvalue http_headers[] = {
{ HTTP_HEADER_HOST, CONST_LEN_STR("Host") }
,{ HTTP_HEADER_DATE, CONST_LEN_STR("Date") }
,{ HTTP_HEADER_ETAG, CONST_LEN_STR("ETag") }
,{ HTTP_HEADER_VARY, CONST_LEN_STR("Vary") }
,{ HTTP_HEADER_RANGE, CONST_LEN_STR("Range") }
,{ HTTP_HEADER_COOKIE, CONST_LEN_STR("Cookie") }
,{ HTTP_HEADER_EXPECT, CONST_LEN_STR("Expect") }
,{ HTTP_HEADER_STATUS, CONST_LEN_STR("Status") }
,{ HTTP_HEADER_SERVER, CONST_LEN_STR("Server") }
,{ HTTP_HEADER_UPGRADE, CONST_LEN_STR("Upgrade") }
,{ HTTP_HEADER_LOCATION, CONST_LEN_STR("Location") }
,{ HTTP_HEADER_FORWARDED, CONST_LEN_STR("Forwarded") }
,{ HTTP_HEADER_CONNECTION, CONST_LEN_STR("Connection") }
,{ HTTP_HEADER_SET_COOKIE, CONST_LEN_STR("Set-Cookie") }
,{ HTTP_HEADER_USER_AGENT, CONST_LEN_STR("User-Agent") }
,{ HTTP_HEADER_CONTENT_TYPE, CONST_LEN_STR("Content-Type") }
,{ HTTP_HEADER_LAST_MODIFIED, CONST_LEN_STR("Last-Modified") }
,{ HTTP_HEADER_AUTHORIZATION, CONST_LEN_STR("Authorization") }
,{ HTTP_HEADER_IF_NONE_MATCH, CONST_LEN_STR("If-None-Match") }
,{ HTTP_HEADER_CACHE_CONTROL, CONST_LEN_STR("Cache-Control") }
,{ HTTP_HEADER_CONTENT_LENGTH, CONST_LEN_STR("Content-Length") }
,{ HTTP_HEADER_HTTP2_SETTINGS, CONST_LEN_STR("HTTP2-Settings") }
,{ HTTP_HEADER_ACCEPT_ENCODING, CONST_LEN_STR("Accept-Encoding") }
,{ HTTP_HEADER_X_FORWARDED_FOR, CONST_LEN_STR("X-Forwarded-For") }
,{ HTTP_HEADER_CONTENT_ENCODING, CONST_LEN_STR("Content-Encoding") }
,{ HTTP_HEADER_CONTENT_LOCATION, CONST_LEN_STR("Content-Location") }
,{ HTTP_HEADER_IF_MODIFIED_SINCE, CONST_LEN_STR("If-Modified-Since") }
,{ HTTP_HEADER_TRANSFER_ENCODING, CONST_LEN_STR("Transfer-Encoding") }
,{ HTTP_HEADER_X_FORWARDED_PROTO, CONST_LEN_STR("X-Forwarded-Proto") }
{ HTTP_HEADER_HOST, CONST_LEN_STR("host") }
,{ HTTP_HEADER_DATE, CONST_LEN_STR("date") }
,{ HTTP_HEADER_ETAG, CONST_LEN_STR("etag") }
,{ HTTP_HEADER_VARY, CONST_LEN_STR("vary") }
,{ HTTP_HEADER_RANGE, CONST_LEN_STR("range") }
,{ HTTP_HEADER_COOKIE, CONST_LEN_STR("cookie") }
,{ HTTP_HEADER_EXPECT, CONST_LEN_STR("expect") }
,{ HTTP_HEADER_STATUS, CONST_LEN_STR("status") }
,{ HTTP_HEADER_SERVER, CONST_LEN_STR("server") }
,{ HTTP_HEADER_UPGRADE, CONST_LEN_STR("upgrade") }
,{ HTTP_HEADER_LOCATION, CONST_LEN_STR("location") }
,{ HTTP_HEADER_FORWARDED, CONST_LEN_STR("forwarded") }
,{ HTTP_HEADER_CONNECTION, CONST_LEN_STR("connection") }
,{ HTTP_HEADER_SET_COOKIE, CONST_LEN_STR("set-cookie") }
,{ HTTP_HEADER_USER_AGENT, CONST_LEN_STR("user-agent") }
,{ HTTP_HEADER_CONTENT_TYPE, CONST_LEN_STR("content-type") }
,{ HTTP_HEADER_LAST_MODIFIED, CONST_LEN_STR("last-modified") }
,{ HTTP_HEADER_AUTHORIZATION, CONST_LEN_STR("authorization") }
,{ HTTP_HEADER_IF_NONE_MATCH, CONST_LEN_STR("if-none-match") }
,{ HTTP_HEADER_CACHE_CONTROL, CONST_LEN_STR("cache-control") }
,{ HTTP_HEADER_CONTENT_LENGTH, CONST_LEN_STR("content-length") }
,{ HTTP_HEADER_HTTP2_SETTINGS, CONST_LEN_STR("http2-settings") }
,{ HTTP_HEADER_ACCEPT_ENCODING, CONST_LEN_STR("accept-encoding") }
,{ HTTP_HEADER_X_FORWARDED_FOR, CONST_LEN_STR("x-forwarded-for") }
,{ HTTP_HEADER_CONTENT_ENCODING, CONST_LEN_STR("content-encoding") }
,{ HTTP_HEADER_CONTENT_LOCATION, CONST_LEN_STR("content-location") }
,{ HTTP_HEADER_IF_MODIFIED_SINCE, CONST_LEN_STR("if-modified-since") }
,{ HTTP_HEADER_TRANSFER_ENCODING, CONST_LEN_STR("transfer-encoding") }
,{ HTTP_HEADER_X_FORWARDED_PROTO, CONST_LEN_STR("x-forwarded-proto") }
,{ HTTP_HEADER_OTHER, 0, "" }
};
@ -72,6 +72,17 @@ enum http_header_e http_header_hkey_get(const char * const s, const uint32_t sle
return HTTP_HEADER_OTHER;
}
enum http_header_e http_header_hkey_get_lc(const char * const s, const uint32_t slen) {
const struct keyvlenvalue * const kv = http_headers;
int i = slen < sizeof(http_headers_off) ? http_headers_off[slen] : -1;
if (i < 0) return HTTP_HEADER_OTHER;
do {
if (0 == memcmp(s, kv[i].value, slen))
return (enum http_header_e)kv[i].key;
} while (slen == kv[++i].vlen);
return HTTP_HEADER_OTHER;
}
int http_header_str_to_code (const char * const s)
{

2
src/http_header.h

@ -43,6 +43,8 @@ enum http_header_e {
__attribute_pure__
enum http_header_e http_header_hkey_get(const char *s, uint32_t slen);
__attribute_pure__
enum http_header_e http_header_hkey_get_lc(const char *s, uint32_t slen);
__attribute_pure__
int http_header_str_to_code (const char * const s);

2
src/request.c

@ -807,7 +807,7 @@ http_request_parse_header (request_st * const restrict r, http_header_parse_ctx
"invalid character in header -> 400");
}
const enum http_header_e id = http_header_hkey_get(k, klen);
const enum http_header_e id = http_header_hkey_get_lc(k, klen);
return http_request_parse_single_header(r, id, k, klen, v, vlen);
}
}

Loading…
Cancel
Save