mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 16:15:27 +00:00
Enhance the have_header() function to find the HTTP header's value
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.
This commit is contained in:
@@ -319,10 +319,12 @@ destroy_httpdmgr(isc_httpdmgr_t *httpdmgr) {
|
|||||||
/*
|
/*
|
||||||
* Look for the given header in headers.
|
* Look for the given header in headers.
|
||||||
* If value is specified look for it terminated with a character in eov.
|
* 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
|
static bool
|
||||||
have_header(isc_httpd_t *httpd, const char *header, const char *value,
|
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;
|
char *cr, *nl, *h;
|
||||||
size_t hlen, vlen = 0;
|
size_t hlen, vlen = 0;
|
||||||
|
|
||||||
@@ -356,10 +358,6 @@ have_header(isc_httpd_t *httpd, const char *header, const char *value,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == NULL) {
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip optional leading white space.
|
* 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') {
|
while (*h == ' ' || *h == '\t') {
|
||||||
h++;
|
h++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the found value.
|
||||||
|
*/
|
||||||
|
if (fvalue != NULL) {
|
||||||
|
*fvalue = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == NULL) {
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Terminate token search on NULL or EOL.
|
* 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;
|
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;
|
httpd->flags |= HTTPD_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (have_header(httpd, "Host:", NULL, NULL)) {
|
if (have_header(httpd, "Host:", NULL, NULL, NULL)) {
|
||||||
httpd->flags |= HTTPD_FOUNDHOST;
|
httpd->flags |= HTTPD_FOUNDHOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(httpd->protocol, "HTTP/1.0", 8) == 0) {
|
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;
|
httpd->flags |= HTTPD_KEEPALIVE;
|
||||||
} else {
|
} else {
|
||||||
httpd->flags |= HTTPD_CLOSE;
|
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:
|
* Check for Accept-Encoding:
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_ZLIB
|
#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;
|
httpd->flags |= HTTPD_ACCEPT_DEFLATE;
|
||||||
}
|
}
|
||||||
#endif /* ifdef HAVE_ZLIB */
|
#endif /* ifdef HAVE_ZLIB */
|
||||||
|
Reference in New Issue
Block a user