From: Michał Kępień Date: Wed, 31 Oct 2018 12:46:52 +0000 (+0100) Subject: [squash] Rework code preparing a HTTP response for sending in lib/isc/httpd.c X-Git-Tag: v9.13.4~64^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e979358ee6a64e21512c5ed65584332797e9336;p=thirdparty%2Fbind9.git [squash] Rework code preparing a HTTP response for sending in lib/isc/httpd.c --- diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index 476a573c47e..2eeb047f1d1 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -842,10 +842,10 @@ isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) { isc_result_t result; isc_httpd_t *httpd = ev->ev_arg; isc_socketevent_t *sev = (isc_socketevent_t *)ev; + isc_buffer_t *databuffer; isc_httpdurl_t *url; isc_time_t now; - isc_region_t headerr, datar, r; - size_t total; + isc_region_t r; bool is_compressed = false; char datebuf[ISC_FORMATHTTPTIMESTAMP_SIZE]; @@ -963,16 +963,20 @@ isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) { isc_httpd_endheaders(httpd); /* done */ - isc_buffer_usedregion(&httpd->headerbuffer, &headerr); - if (is_compressed == true) { - isc_buffer_usedregion(&httpd->compbuffer, &datar); - } else { - isc_buffer_usedregion(&httpd->bodybuffer, &datar); - } - total = headerr.length + datar.length; - isc_buffer_allocate(httpd->mgr->mctx, &httpd->sendbuffer, total); - isc_buffer_copyregion(httpd->sendbuffer, &headerr); - isc_buffer_copyregion(httpd->sendbuffer, &datar); + /* + * Append either the compressed or the non-compressed response body to + * the response headers and store the result in httpd->sendbuffer. + */ + isc_buffer_dup(httpd->mgr->mctx, + &httpd->sendbuffer, &httpd->headerbuffer); + isc_buffer_setautorealloc(httpd->sendbuffer, true); + databuffer = (is_compressed ? &httpd->compbuffer : &httpd->bodybuffer); + isc_buffer_usedregion(databuffer, &r); + result = isc_buffer_copyregion(httpd->sendbuffer, &r); + RUNTIME_CHECK(result == ISC_R_SUCCESS); + /* + * Determine total response size. + */ isc_buffer_usedregion(httpd->sendbuffer, &r); /* check return code? */