Corrected allocation size of HTTP response header.

This commit is contained in:
Igor Sysoev
2017-12-29 18:43:54 +03:00
parent 965a95d602
commit bcbe6df8af

View File

@@ -626,8 +626,9 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
status = &unknown_status; status = &unknown_status;
} }
size = status->length + sizeof("\r\n"); size = status->length;
size += sizeof("\r\n"); /* Trailing CRLF. */ /* Trailing CRLF at the end of header. */
size += sizeof("\r\n") - 1;
http11 = (h1p->parser.version.str[7] != '0'); http11 = (h1p->parser.version.str[7] != '0');
@@ -635,6 +636,8 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
if (http11) { if (http11) {
h1p->chunked = 1; h1p->chunked = 1;
size += sizeof(chunked) - 1; size += sizeof(chunked) - 1;
/* Trailing CRLF will be added by the first chunk header. */
size -= sizeof("\r\n") - 1;
} else { } else {
h1p->keepalive = 0; h1p->keepalive = 0;
@@ -686,6 +689,7 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
if (h1p->chunked) { if (h1p->chunked) {
p = nxt_cpymem(p, chunked, sizeof(chunked) - 1); p = nxt_cpymem(p, chunked, sizeof(chunked) - 1);
/* Trailing CRLF will be added by the first chunk header. */
} else { } else {
*p++ = '\r'; *p++ = '\n'; *p++ = '\r'; *p++ = '\n';