summaryrefslogtreecommitdiff
path: root/src/response.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-03-16 01:05:47 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2021-03-26 07:33:42 -0400
commit38c873585020ac35f04cd2a7a2a56c8ecd7b0064 (patch)
tree277cd740fec455850e618cb30f3a40f4e402f5f1 /src/response.c
parentf9cd50b782e860b54feee2b0ae8f0279058e85fe (diff)
downloadlighttpd-git-38c873585020ac35f04cd2a7a2a56c8ecd7b0064.tar.gz
[multiple] optimize primitives, buffer_extend()
optimize buffer_* primitives Other than buffer_string_set_length(), reallocate with one power-2 step in size (or use the requested size, if larger). This replaces the fixed BUFFER_PIECE_SIZE round-up of only 64 bytes extension each reallocation, which could lead to excessive reallocations in some scenarios. buffer_extend() convenience routine to prep for batch append (combines buffer_string_prepare_append() and buffer_commit()) mod_fastcgi, mod_scgi, mod_proxy and others now leverage buffer_extend() mod_scgi directly performs little-endian encoding of short ints http_response_write_header() optimizes writing response header, leveraging buffer_extend() modify mod_proxy to append line ends similar to how it is done in http_response_write_header() (removes one call to buffer_append_string_len())
Diffstat (limited to 'src/response.c')
-rw-r--r--src/response.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/response.c b/src/response.c
index 2ef00032..721e47cd 100644
--- a/src/response.c
+++ b/src/response.c
@@ -118,16 +118,20 @@ http_response_write_header (request_st * const r)
/* add all headers */
for (size_t i = 0; i < r->resp_headers.used; ++i) {
const data_string * const ds = (data_string *)r->resp_headers.data[i];
-
- if (buffer_string_is_empty(&ds->value)) continue;
- if (buffer_string_is_empty(&ds->key)) continue;
+ const uint32_t klen = buffer_string_length(&ds->key);
+ const uint32_t vlen = buffer_string_length(&ds->value);
+ if (0 == klen || 0 == vlen)
+ continue;
if ((ds->key.ptr[0] & 0xdf) == 'X' && http_response_omit_header(r, ds))
continue;
-
- buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
- buffer_append_string_buffer(b, &ds->key);
- buffer_append_string_len(b, CONST_STR_LEN(": "));
- buffer_append_string_buffer(b, &ds->value);
+ char * restrict s = buffer_extend(b, klen+vlen+4);
+ s[0] = '\r';
+ s[1] = '\n';
+ memcpy(s+2, ds->key.ptr, klen);
+ s += 2+klen;
+ s[0] = ':';
+ s[1] = ' ';
+ memcpy(s+2, ds->value.ptr, vlen);
}
if (!light_btst(r->resp_htags, HTTP_HEADER_DATE)) {