Consume the HTTP headers after processing a request

Remember the amount of space consumed by the HTTP headers, then
move any trailing data to the start of the httpd->recvbuf once
we have finished processing the request.
This commit is contained in:
Mark Andrews
2021-10-26 11:54:31 +11:00
committed by Evan Hunt
parent cbf8c2e019
commit e46c64bf42

View File

@@ -87,6 +87,7 @@ struct isc_httpd {
*/
char recvbuf[HTTP_RECVLEN]; /*%< receive buffer */
uint32_t recvlen; /*%< length recv'd */
uint32_t consume; /*%< length of last command */
char *headers; /*%< set in process_request() */
method_t method;
char *url;
@@ -417,9 +418,12 @@ process_request(isc_httpd_t *httpd, isc_region_t *region, size_t *buflen) {
if (s == NULL) {
s = strstr(httpd->recvbuf, "\n\n");
delim = 1;
}
if (s == NULL) {
return (ISC_R_NOTFOUND);
if (s == NULL) {
return (ISC_R_NOTFOUND);
}
httpd->consume = s + 2 - httpd->recvbuf;
} else {
httpd->consume = s + 4 - httpd->recvbuf;
}
/*
@@ -580,7 +584,6 @@ process_request(isc_httpd_t *httpd, isc_region_t *region, size_t *buflen) {
* to the buffer.
*/
*urlend = 0;
httpd->recvlen = 0;
return (ISC_R_SUCCESS);
}
@@ -602,6 +605,7 @@ httpd_reset(void *arg) {
httpd->recvbuf[0] = 0;
httpd->recvlen = 0;
httpd->consume = 0;
httpd->headers = NULL;
httpd->method = METHOD_UNKNOWN;
httpd->url = NULL;
@@ -952,6 +956,17 @@ httpd_request(isc_nmhandle_t *handle, isc_result_t eresult,
result = isc_buffer_copyregion(httpd->sendbuffer, &r);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
/* Consume the request from the recv buffer. */
if (httpd->consume != 0U) {
INSIST(httpd->consume <= httpd->recvlen);
if (httpd->consume < httpd->recvlen) {
memmove(httpd->recvbuf, httpd->recvbuf + httpd->consume,
httpd->recvlen - httpd->consume);
}
httpd->recvlen -= httpd->consume;
httpd->consume = 0;
}
/*
* Determine total response size.
*/