comparison src/http/v3/ngx_http_v3_filter_module.c @ 8849:2cb697e7d77f quic

HTTP/3: Huffman encoding for the Content-Type response field.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 13 Sep 2021 16:25:23 +0300
parents 07f90cb79fec
children 355461f0cc3b
comparison
equal deleted inserted replaced
8848:b5a305db30e0 8849:2cb697e7d77f
357 ngx_cached_http_time.data, 357 ngx_cached_http_time.data,
358 ngx_cached_http_time.len); 358 ngx_cached_http_time.len);
359 } 359 }
360 360
361 if (r->headers_out.content_type.len) { 361 if (r->headers_out.content_type.len) {
362 n = r->headers_out.content_type.len;
363
364 if (r->headers_out.content_type_len == r->headers_out.content_type.len 362 if (r->headers_out.content_type_len == r->headers_out.content_type.len
365 && r->headers_out.charset.len) 363 && r->headers_out.charset.len)
366 { 364 {
367 n += sizeof("; charset=") - 1 + r->headers_out.charset.len; 365 n = r->headers_out.content_type.len + sizeof("; charset=") - 1
366 + r->headers_out.charset.len;
367
368 p = ngx_pnalloc(r->pool, n);
369 if (p == NULL) {
370 return NGX_ERROR;
371 }
372
373 p = ngx_cpymem(p, r->headers_out.content_type.data,
374 r->headers_out.content_type.len);
375
376 p = ngx_cpymem(p, "; charset=", sizeof("; charset=") - 1);
377
378 p = ngx_cpymem(p, r->headers_out.charset.data,
379 r->headers_out.charset.len);
380
381 /* updated r->headers_out.content_type is also needed for logging */
382
383 r->headers_out.content_type.len = n;
384 r->headers_out.content_type.data = p - n;
368 } 385 }
369 386
370 b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0, 387 b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
371 NGX_HTTP_V3_HEADER_CONTENT_TYPE_TEXT_PLAIN, 388 NGX_HTTP_V3_HEADER_CONTENT_TYPE_TEXT_PLAIN,
372 NULL, n); 389 r->headers_out.content_type.data,
373 390 r->headers_out.content_type.len);
374 p = b->last;
375 b->last = ngx_cpymem(b->last, r->headers_out.content_type.data,
376 r->headers_out.content_type.len);
377
378 if (r->headers_out.content_type_len == r->headers_out.content_type.len
379 && r->headers_out.charset.len)
380 {
381 b->last = ngx_cpymem(b->last, "; charset=",
382 sizeof("; charset=") - 1);
383 b->last = ngx_cpymem(b->last, r->headers_out.charset.data,
384 r->headers_out.charset.len);
385
386 /* update r->headers_out.content_type for possible logging */
387
388 r->headers_out.content_type.len = b->last - p;
389 r->headers_out.content_type.data = p;
390 }
391 } 391 }
392 392
393 if (r->headers_out.content_length == NULL) { 393 if (r->headers_out.content_length == NULL) {
394 if (r->headers_out.content_length_n > 0) { 394 if (r->headers_out.content_length_n > 0) {
395 p = ngx_sprintf(b->last, "%O", r->headers_out.content_length_n); 395 p = ngx_sprintf(b->last, "%O", r->headers_out.content_length_n);