diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index 278683121f..368b9cd2e1 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -319,10 +319,12 @@ destroy_httpdmgr(isc_httpdmgr_t *httpdmgr) { /* * Look for the given header in headers. * If value is specified look for it terminated with a character in eov. + * If fvalue is specified and the header was found, then *fvalue will point to + * the found header's value. */ static bool have_header(isc_httpd_t *httpd, const char *header, const char *value, - const char *eov) { + const char *eov, const char **fvalue) { char *cr, *nl, *h; size_t hlen, vlen = 0; @@ -356,10 +358,6 @@ have_header(isc_httpd_t *httpd, const char *header, const char *value, continue; } - if (value == NULL) { - return (true); - } - /* * Skip optional leading white space. */ @@ -367,6 +365,18 @@ have_header(isc_httpd_t *httpd, const char *header, const char *value, while (*h == ' ' || *h == '\t') { h++; } + + /* + * Set the found value. + */ + if (fvalue != NULL) { + *fvalue = h; + } + + if (value == NULL) { + return (true); + } + /* * Terminate token search on NULL or EOL. */ @@ -556,17 +566,17 @@ process_request(isc_httpd_t *httpd, isc_region_t *region, size_t *buflen) { httpd->headers = s; - if (have_header(httpd, "Connection:", "close", ", \t\r\n")) { + if (have_header(httpd, "Connection:", "close", ", \t\r\n", NULL)) { httpd->flags |= HTTPD_CLOSE; } - if (have_header(httpd, "Host:", NULL, NULL)) { + if (have_header(httpd, "Host:", NULL, NULL, NULL)) { httpd->flags |= HTTPD_FOUNDHOST; } if (strncmp(httpd->protocol, "HTTP/1.0", 8) == 0) { - if (have_header(httpd, "Connection:", "Keep-Alive", ", \t\r\n")) - { + if (have_header(httpd, "Connection:", "Keep-Alive", ", \t\r\n", + NULL)) { httpd->flags |= HTTPD_KEEPALIVE; } else { httpd->flags |= HTTPD_CLOSE; @@ -577,7 +587,8 @@ process_request(isc_httpd_t *httpd, isc_region_t *region, size_t *buflen) { * Check for Accept-Encoding: */ #ifdef HAVE_ZLIB - if (have_header(httpd, "Accept-Encoding:", "deflate", ";, \t\r\n")) { + if (have_header(httpd, "Accept-Encoding:", "deflate", ";, \t\r\n", + NULL)) { httpd->flags |= HTTPD_ACCEPT_DEFLATE; } #endif /* ifdef HAVE_ZLIB */