]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Enhance the have_header() function to find the HTTP header's value
authorAram Sargsyan <aram@isc.org>
Wed, 20 Jul 2022 10:06:56 +0000 (10:06 +0000)
committerAram Sargsyan <aram@isc.org>
Fri, 19 Aug 2022 08:10:54 +0000 (08:10 +0000)
Add a new `const char **fvalue` parameter to the httpd.c:have_header()
function which, when set, will point to the found header's value.

lib/isc/httpd.c

index 278683121f85cea4db4c25022231ed552845cd09..368b9cd2e1695905c88a2e1ced826702a72cb9f9 100644 (file)
@@ -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 */