diff options
Diffstat (limited to 'src/response.c')
-rw-r--r-- | src/response.c | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/src/response.c b/src/response.c index 12bf648e..1bebea4a 100644 --- a/src/response.c +++ b/src/response.c @@ -11,7 +11,6 @@ #include "stat_cache.h" #include "chunk.h" #include "http_chunk.h" -#include "http_date.h" #include "http_range.h" #include "plugin.h" @@ -66,133 +65,6 @@ http_response_omit_header (request_st * const r, const data_string * const ds) __attribute_cold__ -static void -http_response_write_header_partial_1xx (request_st * const r, buffer * const b) -{ - /* take data in con->write_queue and move into b - * (to be sent prior to final response headers in r->write_queue) */ - connection * const con = r->con; - /*assert(&r->write_queue != con->write_queue);*/ - chunkqueue * const cq = con->write_queue; - con->write_queue = &r->write_queue; - - /*assert(0 == buffer_clen(b));*//*expect empty buffer from caller*/ - uint32_t len = (uint32_t)chunkqueue_length(cq); - /*(expecting MEM_CHUNK(s), so not expecting error reading files)*/ - if (chunkqueue_read_data(cq, buffer_string_prepare_append(b, len), - len, r->conf.errh) < 0) - len = 0; - buffer_truncate(b, len);/*expect initial empty buffer from caller*/ - chunkqueue_free(cq); -} - - -void -http_response_write_header (request_st * const r) -{ - /* disable keep-alive if requested */ - - 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 - && (NULL == r->handler_module - || 0 == (r->conf.stream_request_body - & (FDEVENT_STREAM_REQUEST - | FDEVENT_STREAM_REQUEST_BUFMIN)))) { - r->keep_alive = 0; - } - - if (light_btst(r->resp_htags, HTTP_HEADER_UPGRADE) - && r->http_version == HTTP_VERSION_1_1) { - http_header_response_set(r, HTTP_HEADER_CONNECTION, CONST_STR_LEN("Connection"), CONST_STR_LEN("upgrade")); - } else if (r->keep_alive <= 0) { - if (r->keep_alive < 0) - http_response_delay(r->con); - http_header_response_set(r, HTTP_HEADER_CONNECTION, CONST_STR_LEN("Connection"), CONST_STR_LEN("close")); - } else if (r->http_version == HTTP_VERSION_1_0) {/*(&& r->keep_alive > 0)*/ - http_header_response_set(r, HTTP_HEADER_CONNECTION, CONST_STR_LEN("Connection"), CONST_STR_LEN("keep-alive")); - } - - if (304 == r->http_status - && light_btst(r->resp_htags, HTTP_HEADER_CONTENT_ENCODING)) { - 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, 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_clen(&ds->key); - const uint32_t vlen = buffer_clen(&ds->value); - 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); - 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)) { - /* HTTP/1.1 and later requires a Date: header */ - /* "\r\nDate: " 8-chars + 30-chars "%a, %d %b %Y %T GMT" + '\0' */ - static unix_time64_t tlast = 0; - static char tstr[40] = "\r\nDate: "; - - /* cache the generated timestamp */ - const unix_time64_t cur_ts = log_epoch_secs; - if (__builtin_expect ( (tlast != cur_ts), 0)) - http_date_time_to_str(tstr+8, sizeof(tstr)-8, (tlast = cur_ts)); - - buffer_append_string_len(b, tstr, 37); - } - - if (!light_btst(r->resp_htags, HTTP_HEADER_SERVER) && r->conf.server_tag) - buffer_append_str2(b, CONST_STR_LEN("\r\nServer: "), - BUF_PTR_LEN(r->conf.server_tag)); - - buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n")); - - r->resp_header_len = buffer_clen(b); - - if (r->conf.log_response_header) { - log_error_multiline(r->conf.errh, __FILE__, __LINE__, - BUF_PTR_LEN(b), "fd:%d resp: ", r->con->fd); - } - - chunkqueue_prepend_buffer_commit(cq); - - /*(optimization to use fewer syscalls to send a small response)*/ - off_t cqlen; - if (r->resp_body_finished - && light_btst(r->resp_htags, HTTP_HEADER_CONTENT_LENGTH) - && (cqlen = chunkqueue_length(cq) - r->resp_header_len) > 0 - && cqlen < 16384) - chunkqueue_small_resp_optim(cq); -} - - -__attribute_cold__ static handler_t http_response_physical_path_error (request_st * const r, const int code, const char * const msg) { |