Merge HTTP request / response parsing code

This change also fixes a bug so that DNS lookups work correctly when the
first answer is a CNAME record.
This commit is contained in:
Justine Tunney 2021-06-27 17:03:06 -07:00
parent 5a6c0f27c3
commit a68cc690ff
20 changed files with 561 additions and 616 deletions

View file

@ -38,12 +38,12 @@
#line 12 "gethttpheader.gperf"
struct thatispacked HttpHeaderSlot { char *name; char code; };
#define TOTAL_KEYWORDS 73
#define TOTAL_KEYWORDS 82
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 32
#define MIN_HASH_VALUE 6
#define MAX_HASH_VALUE 142
/* maximum key range = 137, duplicates = 0 */
#define MAX_HASH_VALUE 133
/* maximum key range = 128, duplicates = 0 */
#ifndef GPERF_DOWNCASE
#define GPERF_DOWNCASE 1
@ -72,7 +72,7 @@ static unsigned char gperf_downcase[256] =
#ifndef GPERF_CASE_STRNCMP
#define GPERF_CASE_STRNCMP 1
static inline int
static int
gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
{
for (; n > 0;)
@ -102,32 +102,32 @@ hash (register const char *str, register size_t len)
{
static const unsigned char asso_values[] =
{
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 0, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 0, 143, 20, 75, 5,
35, 30, 15, 30, 143, 55, 15, 40, 0, 65,
30, 143, 35, 20, 0, 50, 10, 30, 55, 45,
143, 143, 143, 143, 143, 143, 143, 0, 143, 20,
75, 5, 35, 30, 15, 30, 143, 55, 15, 40,
0, 65, 30, 143, 35, 20, 0, 50, 10, 30,
55, 45, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 20, 134, 134, 134, 134,
134, 134, 134, 0, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 0, 134, 20, 95, 5,
10, 70, 15, 30, 134, 5, 15, 20, 0, 75,
40, 134, 35, 20, 0, 50, 25, 30, 0, 30,
134, 134, 134, 134, 134, 134, 134, 0, 134, 20,
95, 5, 10, 70, 15, 30, 134, 5, 15, 20,
0, 75, 40, 134, 35, 20, 0, 50, 25, 30,
0, 30, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
134, 134, 134, 134, 134, 134
};
register unsigned int hval = len;
@ -165,7 +165,7 @@ hash (register const char *str, register size_t len)
return hval + asso_values[(unsigned char)str[len - 1]];
}
static inline const struct thatispacked HttpHeaderSlot *
static const struct thatispacked HttpHeaderSlot *
LookupHttpHeader (register const char *str, register size_t len)
{
static const struct thatispacked HttpHeaderSlot wordlist[] =
@ -185,18 +185,31 @@ LookupHttpHeader (register const char *str, register size_t len)
{"Authorization", kHttpAuthorization},
#line 48 "gethttpheader.gperf"
{"Accept-Charset", kHttpAcceptCharset},
{""}, {""}, {""}, {""},
{""},
#line 93 "gethttpheader.gperf"
{"X-XSS-Protection", kHttpXXssProtection},
#line 34 "gethttpheader.gperf"
{"X-CSRF-Token", kHttpXCsrfToken},
{""},
#line 14 "gethttpheader.gperf"
{"Host", kHttpHost},
#line 18 "gethttpheader.gperf"
{"Accept-Language", kHttpAcceptLanguage},
{""}, {""},
#line 32 "gethttpheader.gperf"
{"X-Forwarded-Host", kHttpXForwardedHost},
{""},
#line 73 "gethttpheader.gperf"
{"Location", kHttpLocation},
{""}, {""},
#line 72 "gethttpheader.gperf"
{"Link", kHttpLink},
#line 71 "gethttpheader.gperf"
{"Keep-Alive", kHttpKeepAlive},
#line 53 "gethttpheader.gperf"
{"Access-Control-MaxAge", kHttpAccessControlMaxAge},
{""}, {""},
#line 91 "gethttpheader.gperf"
{"Alt-Svc", kHttpAltSvc},
#line 87 "gethttpheader.gperf"
{"Via", kHttpVia},
#line 35 "gethttpheader.gperf"
{"Save-Data", kHttpSaveData},
#line 16 "gethttpheader.gperf"
@ -205,18 +218,21 @@ LookupHttpHeader (register const char *str, register size_t len)
{"Cookie", kHttpCookie},
#line 42 "gethttpheader.gperf"
{"Expires", kHttpExpires},
{""}, {""},
#line 94 "gethttpheader.gperf"
{"Accept-Ranges", kHttpAcceptRanges},
#line 29 "gethttpheader.gperf"
{"From", kHttpFrom},
#line 46 "gethttpheader.gperf"
{"Allow", kHttpAllow},
#line 25 "gethttpheader.gperf"
{"Pragma", kHttpPragma},
#line 31 "gethttpheader.gperf"
{"X-Requested-With", kHttpXRequestedWith},
#line 60 "gethttpheader.gperf"
{"Content-Base", kHttpContentBase},
#line 47 "gethttpheader.gperf"
{"Content-Range", kHttpContentRange},
#line 45 "gethttpheader.gperf"
{"ETag", kHttpEtag},
{""},
#line 95 "gethttpheader.gperf"
{"Set-Cookie", kHttpSetCookie},
#line 63 "gethttpheader.gperf"
{"Content-Language", kHttpContentLanguage},
#line 81 "gethttpheader.gperf"
@ -227,8 +243,8 @@ LookupHttpHeader (register const char *str, register size_t len)
{"Content-Description", kHttpContentDescription},
#line 36 "gethttpheader.gperf"
{"Range", kHttpRange},
#line 77 "gethttpheader.gperf"
{"Proxy-Connection", kHttpProxyConnection},
#line 25 "gethttpheader.gperf"
{"Pragma", kHttpPragma},
#line 28 "gethttpheader.gperf"
{"Sec-GPC", kHttpSecGpc},
#line 15 "gethttpheader.gperf"
@ -239,15 +255,15 @@ LookupHttpHeader (register const char *str, register size_t len)
{"Access-Control-Request-Methods", kHttpAccessControlRequestMethods},
#line 86 "gethttpheader.gperf"
{"WWW-Authenticate", kHttpWwwAuthenticate},
#line 82 "gethttpheader.gperf"
{"Transfer-Encoding", kHttpTransferEncoding},
{""},
#line 67 "gethttpheader.gperf"
{"If-Match", kHttpIfMatch},
#line 37 "gethttpheader.gperf"
{"Content-Length", kHttpContentLength},
{""},
#line 78 "gethttpheader.gperf"
{"Public", kHttpPublic},
#line 22 "gethttpheader.gperf"
{"X-Forwarded-For", kHttpXForwardedFor},
#line 77 "gethttpheader.gperf"
{"Proxy-Connection", kHttpProxyConnection},
#line 30 "gethttpheader.gperf"
{"If-Modified-Since", kHttpIfModifiedSince},
#line 68 "gethttpheader.gperf"
@ -262,86 +278,87 @@ LookupHttpHeader (register const char *str, register size_t len)
{"Upgrade", kHttpUpgrade},
#line 50 "gethttpheader.gperf"
{"Access-Control-Allow-Headers", kHttpAccessControlAllowHeaders},
#line 70 "gethttpheader.gperf"
{"If-Unmodified-Since", kHttpIfUnmodifiedSince},
{""},
#line 78 "gethttpheader.gperf"
{"Public", kHttpPublic},
#line 38 "gethttpheader.gperf"
{"Content-Type", kHttpContentType},
#line 51 "gethttpheader.gperf"
{"Access-Control-Allow-Methods", kHttpAccessControlAllowMethods},
#line 62 "gethttpheader.gperf"
{"Content-Disposition", kHttpContentDisposition},
{""}, {""},
#line 49 "gethttpheader.gperf"
{"Access-Control-Allow-Credentials", kHttpAccessControlAllowCredentials},
{""},
#line 76 "gethttpheader.gperf"
{"Proxy-Authorization", kHttpProxyAuthorization},
#line 89 "gethttpheader.gperf"
{"X-Frame-Options", kHttpXFrameOptions},
{""},
#line 21 "gethttpheader.gperf"
{"Referer", kHttpReferer},
#line 75 "gethttpheader.gperf"
{"Proxy-Authenticate", kHttpProxyAuthenticate},
#line 45 "gethttpheader.gperf"
{"ETag", kHttpEtag},
{""},
#line 23 "gethttpheader.gperf"
{"Origin", kHttpOrigin},
#line 90 "gethttpheader.gperf"
{"X-Content-Type-Options", kHttpXContentTypeOptions},
#line 84 "gethttpheader.gperf"
{"Uri", kHttpUri},
{""}, {""},
#line 79 "gethttpheader.gperf"
{"Retry-After", kHttpRetryAfter},
#line 74 "gethttpheader.gperf"
{"Max-Forwards", kHttpMaxForwards},
{""}, {""}, {""}, {""},
#line 82 "gethttpheader.gperf"
{"Transfer-Encoding", kHttpTransferEncoding},
{""}, {""}, {""}, {""},
#line 33 "gethttpheader.gperf"
{"X-Forwarded-Proto", kHttpXForwardedProto},
#line 27 "gethttpheader.gperf"
{"DNT", kHttpDnt},
{""},
#line 24 "gethttpheader.gperf"
{"Upgrade-Insecure-Requests", kHttpUpgradeInsecureRequests},
{""},
#line 52 "gethttpheader.gperf"
{"Access-Control-Allow-Origin", kHttpAccessControlAllowOrigin},
{""},
#line 40 "gethttpheader.gperf"
{"Date", kHttpDate},
#line 19 "gethttpheader.gperf"
{"Accept-Encoding", kHttpAcceptEncoding},
#line 43 "gethttpheader.gperf"
{"Content-Encoding", kHttpContentEncoding},
#line 85 "gethttpheader.gperf"
{"Warning", kHttpWarning},
#line 75 "gethttpheader.gperf"
{"Proxy-Authenticate", kHttpProxyAuthenticate},
#line 62 "gethttpheader.gperf"
{"Content-Disposition", kHttpContentDisposition},
{""},
#line 23 "gethttpheader.gperf"
{"Origin", kHttpOrigin},
#line 49 "gethttpheader.gperf"
{"Access-Control-Allow-Credentials", kHttpAccessControlAllowCredentials},
{""},
#line 72 "gethttpheader.gperf"
{"Link", kHttpLink},
#line 71 "gethttpheader.gperf"
{"Keep-Alive", kHttpKeepAlive},
#line 32 "gethttpheader.gperf"
{"X-Forwarded-Host", kHttpXForwardedHost},
#line 21 "gethttpheader.gperf"
{"Referer", kHttpReferer},
#line 27 "gethttpheader.gperf"
{"DNT", kHttpDnt},
#line 29 "gethttpheader.gperf"
{"From", kHttpFrom},
{""}, {""},
#line 38 "gethttpheader.gperf"
{"Content-Type", kHttpContentType},
#line 84 "gethttpheader.gperf"
{"Uri", kHttpUri},
#line 40 "gethttpheader.gperf"
{"Date", kHttpDate},
{""},
#line 79 "gethttpheader.gperf"
{"Retry-After", kHttpRetryAfter},
{""},
#line 51 "gethttpheader.gperf"
{"Access-Control-Allow-Methods", kHttpAccessControlAllowMethods},
#line 70 "gethttpheader.gperf"
{"If-Unmodified-Since", kHttpIfUnmodifiedSince},
{""},
#line 31 "gethttpheader.gperf"
{"X-Requested-With", kHttpXRequestedWith},
#line 52 "gethttpheader.gperf"
{"Access-Control-Allow-Origin", kHttpAccessControlAllowOrigin},
{""}, {""}, {""},
#line 88 "gethttpheader.gperf"
{"Strict-Transport-Security", kHttpStrictTransportSecurity},
#line 64 "gethttpheader.gperf"
{"Content-Location", kHttpContentLocation},
{""}, {""}, {""}, {""},
#line 54 "gethttpheader.gperf"
{"Access-Control-Method", kHttpAccessControlMethod},
{""}, {""}, {""},
#line 24 "gethttpheader.gperf"
{"Upgrade-Insecure-Requests", kHttpUpgradeInsecureRequests},
#line 64 "gethttpheader.gperf"
{"Content-Location", kHttpContentLocation},
{""}, {""},
#line 92 "gethttpheader.gperf"
{"Referrer-Policy", kHttpReferrerPolicy},
{""}, {""}, {""},
#line 56 "gethttpheader.gperf"
{"Access-Control-Request-Method", kHttpAccessControlRequestMethod},
{""},
#line 65 "gethttpheader.gperf"
{"Content-MD5", kHttpContentMd5},
#line 74 "gethttpheader.gperf"
{"Max-Forwards", kHttpMaxForwards},
{""}, {""},
#line 22 "gethttpheader.gperf"
{"X-Forwarded-For", kHttpXForwardedFor},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""},
#line 34 "gethttpheader.gperf"
{"X-CSRF-Token", kHttpXCsrfToken},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""},
#line 44 "gethttpheader.gperf"
{"Last-Modified", kHttpLastModified},
{""}, {""}, {""},
#line 33 "gethttpheader.gperf"
{"X-Forwarded-Proto", kHttpXForwardedProto}
{"Last-Modified", kHttpLastModified}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)