[PATCH 1 of 3] Added support for trailers in HTTP responses
Piotr Sikora
piotrsikora at google.com
Tue Jun 6 04:56:03 UTC 2017
Hey Maxim,
> I would prefer to preserve the typical code path (when there are no
> trailers) without an extra allocation. It looks like it would be
> as trivail as:
>
> @@ -273,14 +273,18 @@ ngx_http_chunked_create_trailers(ngx_htt
> b->memory = 1;
> b->last_buf = 1;
>
> + if (len == sizeof(CRLF "0" CRLF CRLF) - 1) {
> + b->pos = (u_char *) CRLF "0" CRLF CRLF;
> + b->last = b->pos + sizeof(CRLF "0" CRLF CRLF) - 1;
> + return cl;
> + }
Sounds good, but the if statement reads a bit weird.
What about this instead, even though it might be a bit more expensive?
@@ -236,7 +236,7 @@ ngx_http_chunked_create_trailers(ngx_http_request_t *r,
ngx_list_part_t *part;
ngx_table_elt_t *header;
- len = sizeof(CRLF "0" CRLF CRLF) - 1;
+ len = 0;
part = &r->headers_out.trailers.part;
header = part->elts;
@@ -273,12 +273,14 @@ ngx_http_chunked_create_trailers(ngx_http_request_t *r,
b->memory = 1;
b->last_buf = 1;
- if (len == sizeof(CRLF "0" CRLF CRLF) - 1) {
+ if (len == 0) {
b->pos = (u_char *) CRLF "0" CRLF CRLF;
b->last = b->pos + sizeof(CRLF "0" CRLF CRLF) - 1;
return cl;
}
+ len += sizeof(CRLF "0" CRLF CRLF) - 1;
+
b->pos = ngx_palloc(r->pool, len);
if (b->pos == NULL) {
return NULL;
Best regards,
Piotr Sikora
More information about the nginx-devel
mailing list