comparison src/http/v2/ngx_http_v2_filter_module.c @ 6276:0efc16d55adb

HTTP/2: introduced NGX_HTTP_V2_ENCODE_* macros. No functional changes.
author Valentin Bartenev <vbart@nginx.com>
date Mon, 26 Oct 2015 17:43:08 +0300
parents 39fa0b7e3a67
children b930e598a199
comparison
equal deleted inserted replaced
6275:39fa0b7e3a67 6276:0efc16d55adb
18 (ngx_http_v2_integer_octets(sizeof(h) - 1) + sizeof(h) - 1) 18 (ngx_http_v2_integer_octets(sizeof(h) - 1) + sizeof(h) - 1)
19 19
20 #define ngx_http_v2_indexed(i) (128 + (i)) 20 #define ngx_http_v2_indexed(i) (128 + (i))
21 #define ngx_http_v2_inc_indexed(i) (64 + (i)) 21 #define ngx_http_v2_inc_indexed(i) (64 + (i))
22 22
23 #define NGX_HTTP_V2_ENCODE_RAW 0
24 #define NGX_HTTP_V2_ENCODE_HUFF 0x80
23 25
24 #define NGX_HTTP_V2_STATUS_INDEX 8 26 #define NGX_HTTP_V2_STATUS_INDEX 8
25 #define NGX_HTTP_V2_STATUS_200_INDEX 8 27 #define NGX_HTTP_V2_STATUS_200_INDEX 8
26 #define NGX_HTTP_V2_STATUS_204_INDEX 9 28 #define NGX_HTTP_V2_STATUS_204_INDEX 9
27 #define NGX_HTTP_V2_STATUS_206_INDEX 10 29 #define NGX_HTTP_V2_STATUS_206_INDEX 10
404 if (status) { 406 if (status) {
405 *b->last++ = status; 407 *b->last++ = status;
406 408
407 } else { 409 } else {
408 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX); 410 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX);
409 *b->last++ = 3; 411 *b->last++ = NGX_HTTP_V2_ENCODE_RAW | 3;
410 b->last = ngx_sprintf(b->last, "%03ui", r->headers_out.status); 412 b->last = ngx_sprintf(b->last, "%03ui", r->headers_out.status);
411 } 413 }
412 414
413 if (r->headers_out.server == NULL) { 415 if (r->headers_out.server == NULL) {
414 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SERVER_INDEX); 416 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SERVER_INDEX);
415 417
416 if (clcf->server_tokens) { 418 if (clcf->server_tokens) {
417 *b->last++ = sizeof(NGINX_VER) - 1; 419 *b->last++ = NGX_HTTP_V2_ENCODE_RAW | (sizeof(NGINX_VER) - 1);
418 b->last = ngx_cpymem(b->last, NGINX_VER, sizeof(NGINX_VER) - 1); 420 b->last = ngx_cpymem(b->last, NGINX_VER, sizeof(NGINX_VER) - 1);
419 421
420 } else { 422 } else {
421 *b->last++ = sizeof("nginx") - 1; 423 *b->last++ = NGX_HTTP_V2_ENCODE_RAW | (sizeof("nginx") - 1);
422 b->last = ngx_cpymem(b->last, "nginx", sizeof("nginx") - 1); 424 b->last = ngx_cpymem(b->last, "nginx", sizeof("nginx") - 1);
423 } 425 }
424 } 426 }
425 427
426 if (r->headers_out.date == NULL) { 428 if (r->headers_out.date == NULL) {
435 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_TYPE_INDEX); 437 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_TYPE_INDEX);
436 438
437 if (r->headers_out.content_type_len == r->headers_out.content_type.len 439 if (r->headers_out.content_type_len == r->headers_out.content_type.len
438 && r->headers_out.charset.len) 440 && r->headers_out.charset.len)
439 { 441 {
440 *b->last = 0; 442 *b->last = NGX_HTTP_V2_ENCODE_RAW;
441 b->last = ngx_http_v2_write_int(b->last, ngx_http_v2_prefix(7), 443 b->last = ngx_http_v2_write_int(b->last, ngx_http_v2_prefix(7),
442 r->headers_out.content_type.len 444 r->headers_out.content_type.len
443 + sizeof("; charset=") - 1 445 + sizeof("; charset=") - 1
444 + r->headers_out.charset.len); 446 + r->headers_out.charset.len);
445 447
458 460
459 r->headers_out.content_type.len = b->last - p; 461 r->headers_out.content_type.len = b->last - p;
460 r->headers_out.content_type.data = p; 462 r->headers_out.content_type.data = p;
461 463
462 } else { 464 } else {
463 *b->last = 0; 465 *b->last = NGX_HTTP_V2_ENCODE_RAW;
464 b->last = ngx_http_v2_write_int(b->last, ngx_http_v2_prefix(7), 466 b->last = ngx_http_v2_write_int(b->last, ngx_http_v2_prefix(7),
465 r->headers_out.content_type.len); 467 r->headers_out.content_type.len);
466 b->last = ngx_cpymem(b->last, r->headers_out.content_type.data, 468 b->last = ngx_cpymem(b->last, r->headers_out.content_type.data,
467 r->headers_out.content_type.len); 469 r->headers_out.content_type.len);
468 } 470 }
474 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_LENGTH_INDEX); 476 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_LENGTH_INDEX);
475 477
476 p = b->last; 478 p = b->last;
477 b->last = ngx_sprintf(b->last + 1, "%O", 479 b->last = ngx_sprintf(b->last + 1, "%O",
478 r->headers_out.content_length_n); 480 r->headers_out.content_length_n);
479 *p = (u_char) (b->last - p - 1); 481 *p = NGX_HTTP_V2_ENCODE_RAW | (u_char) (b->last - p - 1);
480 } 482 }
481 483
482 if (r->headers_out.last_modified == NULL 484 if (r->headers_out.last_modified == NULL
483 && r->headers_out.last_modified_time != -1) 485 && r->headers_out.last_modified_time != -1)
484 { 486 {
485 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LAST_MODIFIED_INDEX); 487 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LAST_MODIFIED_INDEX);
486 488
487 *b->last++ = sizeof("Wed, 31 Dec 1986 18:00:00 GMT") - 1; 489 *b->last++ = NGX_HTTP_V2_ENCODE_RAW
490 | (sizeof("Wed, 31 Dec 1986 18:00:00 GMT") - 1);
488 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time); 491 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);
489 } 492 }
490 493
491 if (r->headers_out.location && r->headers_out.location->value.len) { 494 if (r->headers_out.location && r->headers_out.location->value.len) {
492 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LOCATION_INDEX); 495 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LOCATION_INDEX);
493 496
494 *b->last = 0; 497 *b->last = NGX_HTTP_V2_ENCODE_RAW;
495 b->last = ngx_http_v2_write_int(b->last, ngx_http_v2_prefix(7), 498 b->last = ngx_http_v2_write_int(b->last, ngx_http_v2_prefix(7),
496 r->headers_out.location->value.len); 499 r->headers_out.location->value.len);
497 b->last = ngx_cpymem(b->last, r->headers_out.location->value.data, 500 b->last = ngx_cpymem(b->last, r->headers_out.location->value.data,
498 r->headers_out.location->value.len); 501 r->headers_out.location->value.len);
499 } 502 }
500 503
501 #if (NGX_HTTP_GZIP) 504 #if (NGX_HTTP_GZIP)
502 if (r->gzip_vary) { 505 if (r->gzip_vary) {
503 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_VARY_INDEX); 506 *b->last++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_VARY_INDEX);
504 *b->last++ = sizeof("Accept-Encoding") - 1; 507 *b->last++ = NGX_HTTP_V2_ENCODE_RAW | (sizeof("Accept-Encoding") - 1);
505 b->last = ngx_cpymem(b->last, "Accept-Encoding", 508 b->last = ngx_cpymem(b->last, "Accept-Encoding",
506 sizeof("Accept-Encoding") - 1); 509 sizeof("Accept-Encoding") - 1);
507 } 510 }
508 #endif 511 #endif
509 512
556 559
557 p = b->last; 560 p = b->last;
558 561
559 *p++ = 0; 562 *p++ = 0;
560 563
561 *p = 0; 564 *p = NGX_HTTP_V2_ENCODE_RAW;
562 p = ngx_http_v2_write_int(p, ngx_http_v2_prefix(7), header[i].key.len); 565 p = ngx_http_v2_write_int(p, ngx_http_v2_prefix(7), header[i].key.len);
563 ngx_strlow(p, header[i].key.data, header[i].key.len); 566 ngx_strlow(p, header[i].key.data, header[i].key.len);
564 p += header[i].key.len; 567 p += header[i].key.len;
565 568
566 *p = 0; 569 *p = NGX_HTTP_V2_ENCODE_RAW;
567 p = ngx_http_v2_write_int(p, ngx_http_v2_prefix(7), 570 p = ngx_http_v2_write_int(p, ngx_http_v2_prefix(7),
568 header[i].value.len); 571 header[i].value.len);
569 p = ngx_cpymem(p, header[i].value.data, header[i].value.len); 572 p = ngx_cpymem(p, header[i].value.data, header[i].value.len);
570 573
571 rest -= p - b->last; 574 rest -= p - b->last;