diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-06-04 05:18:21 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-08-27 02:16:53 -0400 |
commit | a8b5ad2b5c81876bb8b0bead0950f0ad11bae8bc (patch) | |
tree | b422982dea4d39170ba922d9ccc6c6b889d70fbc /src/response.c | |
parent | db853f9c0574813f6bc8f4016b814e6819ac67f3 (diff) | |
download | lighttpd-git-a8b5ad2b5c81876bb8b0bead0950f0ad11bae8bc.tar.gz |
[core] tweaks writing response header (better asm)
Diffstat (limited to 'src/response.c')
-rw-r--r-- | src/response.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/response.c b/src/response.c index da780a53..b9883384 100644 --- a/src/response.c +++ b/src/response.c @@ -76,19 +76,11 @@ http_response_write_header_partial_1xx (request_st * const r, buffer * const b) void http_response_write_header (request_st * const r) { - chunkqueue * const cq = &r->write_queue; - buffer * const b = chunkqueue_prepend_buffer_open(cq); - - if (cq != r->con->write_queue) - http_response_write_header_partial_1xx(r, b); - - const char * const httpv = (r->http_version == HTTP_VERSION_1_1) ? "HTTP/1.1 " : "HTTP/1.0 "; - buffer_append_string_len(b, httpv, sizeof("HTTP/1.1 ")-1); - http_status_append(b, r->http_status); - /* disable keep-alive if requested */ - if (r->con->request_count > r->conf.max_keep_alive_requests || 0 == r->conf.max_keep_alive_idle) { + r->con->keep_alive_idle = r->conf.max_keep_alive_idle; + if (__builtin_expect( (0 == r->conf.max_keep_alive_idle), 0) + || r->con->request_count > r->conf.max_keep_alive_requests) { r->keep_alive = 0; } else if (0 != r->reqbody_length && r->reqbody_length != r->reqbody_queue.bytes_in @@ -97,8 +89,6 @@ http_response_write_header (request_st * const r) & (FDEVENT_STREAM_REQUEST | FDEVENT_STREAM_REQUEST_BUFMIN)))) { r->keep_alive = 0; - } else { - r->con->keep_alive_idle = r->conf.max_keep_alive_idle; } if (light_btst(r->resp_htags, HTTP_HEADER_UPGRADE) @@ -115,13 +105,26 @@ http_response_write_header (request_st * const r) http_header_response_unset(r, HTTP_HEADER_CONTENT_ENCODING, CONST_STR_LEN("Content-Encoding")); } + chunkqueue * const cq = &r->write_queue; + buffer * const b = chunkqueue_prepend_buffer_open(cq); + + if (cq != r->con->write_queue) + http_response_write_header_partial_1xx(r, b); + + buffer_append_string_len(b, + (r->http_version == HTTP_VERSION_1_1) + ? "HTTP/1.1 " + : "HTTP/1.0 ", + sizeof("HTTP/1.1 ")-1); + http_status_append(b, r->http_status); + /* add all headers */ - for (size_t i = 0; i < r->resp_headers.used; ++i) { + for (size_t i = 0, used = r->resp_headers.used; i < used; ++i) { const data_string * const ds = (data_string *)r->resp_headers.data[i]; 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 (__builtin_expect( (0 == klen), 0)) continue; + if (__builtin_expect( (0 == vlen), 0)) continue; if ((ds->key.ptr[0] & 0xdf) == 'X' && http_response_omit_header(r, ds)) continue; char * restrict s = buffer_extend(b, klen+vlen+4); |