2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +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:
Aram Sargsyan
2022-07-20 10:06:56 +00:00
parent 1c19a6aae8
commit 86b8e62106

View 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 */