comparison src/http/v2/ngx_http_v2_filter_module.c @ 6401:6812ca9a8002

HTTP/2: added debug logging of response headers. Because of HPACK compression it's hard to see what headers are actually sent by the server.
author Valentin Bartenev <vbart@nginx.com>
date Tue, 16 Feb 2016 17:49:14 +0300
parents b4c28876d2c3
children 4ba91a4c66a3
comparison
equal deleted inserted replaced
6400:b4c28876d2c3 6401:6812ca9a8002
419 return NGX_ERROR; 419 return NGX_ERROR;
420 } 420 }
421 421
422 start = pos; 422 start = pos;
423 423
424 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
425 "http2 output header: \":status: %03ui\"",
426 r->headers_out.status);
427
424 if (status) { 428 if (status) {
425 *pos++ = status; 429 *pos++ = status;
426 430
427 } else { 431 } else {
428 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX); 432 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX);
429 *pos++ = NGX_HTTP_V2_ENCODE_RAW | 3; 433 *pos++ = NGX_HTTP_V2_ENCODE_RAW | 3;
430 pos = ngx_sprintf(pos, "%03ui", r->headers_out.status); 434 pos = ngx_sprintf(pos, "%03ui", r->headers_out.status);
431 } 435 }
432 436
433 if (r->headers_out.server == NULL) { 437 if (r->headers_out.server == NULL) {
438 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
439 "http2 output header: \"server: %s\"",
440 clcf->server_tokens ? NGINX_VER : "nginx");
441
434 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SERVER_INDEX); 442 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SERVER_INDEX);
435 443
436 if (clcf->server_tokens) { 444 if (clcf->server_tokens) {
437 if (nginx_ver[0] == '\0') { 445 if (nginx_ver[0] == '\0') {
438 p = ngx_http_v2_write_value(nginx_ver, (u_char *) NGINX_VER, 446 p = ngx_http_v2_write_value(nginx_ver, (u_char *) NGINX_VER,
446 pos = ngx_cpymem(pos, nginx, sizeof(nginx)); 454 pos = ngx_cpymem(pos, nginx, sizeof(nginx));
447 } 455 }
448 } 456 }
449 457
450 if (r->headers_out.date == NULL) { 458 if (r->headers_out.date == NULL) {
459 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
460 "http2 output header: \"date: %V\"",
461 &ngx_cached_http_time);
462
451 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_DATE_INDEX); 463 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_DATE_INDEX);
452 pos = ngx_http_v2_write_value(pos, ngx_cached_http_time.data, 464 pos = ngx_http_v2_write_value(pos, ngx_cached_http_time.data,
453 ngx_cached_http_time.len, tmp); 465 ngx_cached_http_time.len, tmp);
454 } 466 }
455 467
479 491
480 r->headers_out.content_type.len = len; 492 r->headers_out.content_type.len = len;
481 r->headers_out.content_type.data = p - len; 493 r->headers_out.content_type.data = p - len;
482 } 494 }
483 495
496 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
497 "http2 output header: \"content-type: %V\"",
498 &r->headers_out.content_type);
499
484 pos = ngx_http_v2_write_value(pos, r->headers_out.content_type.data, 500 pos = ngx_http_v2_write_value(pos, r->headers_out.content_type.data,
485 r->headers_out.content_type.len, tmp); 501 r->headers_out.content_type.len, tmp);
486 } 502 }
487 503
488 if (r->headers_out.content_length == NULL 504 if (r->headers_out.content_length == NULL
489 && r->headers_out.content_length_n >= 0) 505 && r->headers_out.content_length_n >= 0)
490 { 506 {
507 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
508 "http2 output header: \"content-length: %O\"",
509 r->headers_out.content_length_n);
510
491 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_LENGTH_INDEX); 511 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_LENGTH_INDEX);
492 512
493 p = pos; 513 p = pos;
494 pos = ngx_sprintf(pos + 1, "%O", r->headers_out.content_length_n); 514 pos = ngx_sprintf(pos + 1, "%O", r->headers_out.content_length_n);
495 *p = NGX_HTTP_V2_ENCODE_RAW | (u_char) (pos - p - 1); 515 *p = NGX_HTTP_V2_ENCODE_RAW | (u_char) (pos - p - 1);
500 { 520 {
501 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LAST_MODIFIED_INDEX); 521 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LAST_MODIFIED_INDEX);
502 522
503 ngx_http_time(pos, r->headers_out.last_modified_time); 523 ngx_http_time(pos, r->headers_out.last_modified_time);
504 len = sizeof("Wed, 31 Dec 1986 18:00:00 GMT") - 1; 524 len = sizeof("Wed, 31 Dec 1986 18:00:00 GMT") - 1;
525
526 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, fc->log, 0,
527 "http2 output header: \"last-modified: %*s\"",
528 len, pos);
505 529
506 /* 530 /*
507 * Date will always be encoded using huffman in the temporary buffer, 531 * Date will always be encoded using huffman in the temporary buffer,
508 * so it's safe here to use src and dst pointing to the same address. 532 * so it's safe here to use src and dst pointing to the same address.
509 */ 533 */
510 pos = ngx_http_v2_write_value(pos, pos, len, tmp); 534 pos = ngx_http_v2_write_value(pos, pos, len, tmp);
511 } 535 }
512 536
513 if (r->headers_out.location && r->headers_out.location->value.len) { 537 if (r->headers_out.location && r->headers_out.location->value.len) {
538 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
539 "http2 output header: \"location: %V\"",
540 &r->headers_out.location->value);
541
514 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LOCATION_INDEX); 542 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LOCATION_INDEX);
515 pos = ngx_http_v2_write_value(pos, r->headers_out.location->value.data, 543 pos = ngx_http_v2_write_value(pos, r->headers_out.location->value.data,
516 r->headers_out.location->value.len, tmp); 544 r->headers_out.location->value.len, tmp);
517 } 545 }
518 546
519 #if (NGX_HTTP_GZIP) 547 #if (NGX_HTTP_GZIP)
520 if (r->gzip_vary) { 548 if (r->gzip_vary) {
549 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
550 "http2 output header: \"vary: Accept-Encoding\"");
551
521 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_VARY_INDEX); 552 *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_VARY_INDEX);
522 pos = ngx_cpymem(pos, accept_encoding, sizeof(accept_encoding)); 553 pos = ngx_cpymem(pos, accept_encoding, sizeof(accept_encoding));
523 } 554 }
524 #endif 555 #endif
525 556
539 } 570 }
540 571
541 if (header[i].hash == 0) { 572 if (header[i].hash == 0) {
542 continue; 573 continue;
543 } 574 }
575
576 #if (NGX_DEBUG)
577 if (fc->log->log_level & NGX_LOG_DEBUG_HTTP) {
578 ngx_strlow(tmp, header[i].key.data, header[i].key.len);
579
580 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, fc->log, 0,
581 "http2 output header: \"%*s: %V\"",
582 header[i].key.len, tmp, &header[i].value);
583 }
584 #endif
544 585
545 *pos++ = 0; 586 *pos++ = 0;
546 587
547 pos = ngx_http_v2_write_name(pos, header[i].key.data, 588 pos = ngx_http_v2_write_name(pos, header[i].key.data,
548 header[i].key.len, tmp); 589 header[i].key.len, tmp);