defer choosing "Transfer-Encoding: chunked"
defer choosing "Transfer-Encoding: chunked" until response header is about to be written
This commit is contained in:
parent
bfac0285a7
commit
5863cb5752
|
@ -341,7 +341,21 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
|
|||
|
||||
if (((con->parsed_response & HTTP_CONTENT_LENGTH) == 0) &&
|
||||
((con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) == 0)) {
|
||||
con->keep_alive = 0;
|
||||
if (con->request.http_version == HTTP_VERSION_1_1) {
|
||||
off_t qlen = chunkqueue_length(con->write_queue);
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
if (qlen) {
|
||||
/* create initial Transfer-Encoding: chunked segment */
|
||||
buffer *b = srv->tmp_chunk_len;
|
||||
buffer_string_set_length(b, 0);
|
||||
buffer_append_uint_hex(b, (uintmax_t)qlen);
|
||||
buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
|
||||
chunkqueue_prepend_buffer(con->write_queue, b);
|
||||
chunkqueue_append_mem(con->write_queue, CONST_STR_LEN("\r\n"));
|
||||
}
|
||||
} else {
|
||||
con->keep_alive = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -490,11 +490,6 @@ static int cgi_demux_response(server *srv, handler_ctx *hctx) {
|
|||
if (is_header_end) {
|
||||
if (!is_header) {
|
||||
/* no header, but a body */
|
||||
|
||||
if (con->request.http_version == HTTP_VERSION_1_1) {
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
}
|
||||
|
||||
if (0 != http_chunk_append_buffer(srv, con, hctx->response_header)) {
|
||||
return FDEVENT_HANDLED_ERROR;
|
||||
}
|
||||
|
@ -531,12 +526,6 @@ static int cgi_demux_response(server *srv, handler_ctx *hctx) {
|
|||
}
|
||||
}
|
||||
|
||||
/* enable chunked-transfer-encoding */
|
||||
if (con->request.http_version == HTTP_VERSION_1_1 &&
|
||||
!(con->parsed_response & HTTP_CONTENT_LENGTH)) {
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
}
|
||||
|
||||
if (blen > 0) {
|
||||
if (0 != http_chunk_append_mem(srv, con, bstart, blen)) {
|
||||
return FDEVENT_HANDLED_ERROR;
|
||||
|
|
|
@ -2642,12 +2642,6 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
|
|||
hctx->send_content_body = 0; /* ignore the content */
|
||||
break;
|
||||
}
|
||||
|
||||
/* enable chunked-transfer-encoding */
|
||||
if (con->request.http_version == HTTP_VERSION_1_1 &&
|
||||
!(con->parsed_response & HTTP_CONTENT_LENGTH)) {
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
}
|
||||
}
|
||||
|
||||
if (hctx->send_content_body && !buffer_string_is_empty(packet.b)) {
|
||||
|
|
|
@ -708,12 +708,6 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) {
|
|||
/* parse the response header */
|
||||
proxy_response_parse(srv, con, p, hctx->response_header);
|
||||
|
||||
/* enable chunked-transfer-encoding */
|
||||
if (con->request.http_version == HTTP_VERSION_1_1 &&
|
||||
!(con->parsed_response & HTTP_CONTENT_LENGTH)) {
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
}
|
||||
|
||||
con->file_started = 1;
|
||||
if (blen > 0) {
|
||||
if (0 != http_chunk_append_mem(srv, con, c + 4, blen)) {
|
||||
|
|
|
@ -1938,11 +1938,6 @@ static int scgi_demux_response(server *srv, handler_ctx *hctx) {
|
|||
if (header_end) {
|
||||
if (c == NULL) {
|
||||
/* no header, but a body */
|
||||
|
||||
if (con->request.http_version == HTTP_VERSION_1_1) {
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
}
|
||||
|
||||
if (0 != http_chunk_append_buffer(srv, con, hctx->response_header)) {
|
||||
/* error writing to tempfile;
|
||||
* truncate response or send 500 if nothing sent yet */
|
||||
|
@ -1965,12 +1960,6 @@ static int scgi_demux_response(server *srv, handler_ctx *hctx) {
|
|||
}
|
||||
}
|
||||
|
||||
/* enable chunked-transfer-encoding */
|
||||
if (con->request.http_version == HTTP_VERSION_1_1 &&
|
||||
!(con->parsed_response & HTTP_CONTENT_LENGTH)) {
|
||||
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
|
||||
}
|
||||
|
||||
if (blen > 0) {
|
||||
if (0 != http_chunk_append_mem(srv, con, hctx->response_header->ptr + hlen, blen)) {
|
||||
/* error writing to tempfile;
|
||||
|
|
Loading…
Reference in New Issue