From 852a320586c21075ddf0a86d8cde04cac3e89f6e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 May 2016 16:44:04 +0900 Subject: [PATCH] nghttpx: Cleanup code where request content-length is involved --- src/shrpx_http2_downstream_connection.cc | 9 ++++----- src/shrpx_http_downstream_connection.cc | 6 +++--- src/shrpx_https_upstream.cc | 6 ++++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index 8d89e48d..ab5c20d2 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -426,11 +426,10 @@ int Http2DownstreamConnection::push_request_headers() { DCLOG(INFO, this) << "HTTP request headers\n" << ss.str(); } - auto content_length = req.fs.header(http2::HD_CONTENT_LENGTH); - // TODO check content-length: 0 case - - if (req.method == HTTP_CONNECT || chunked_encoding || content_length || - req.http2_expect_body) { + // Add body as long as transfer-encoding is given even if + // req.fs.content_length == 0 to forward trailer fields. + if (req.method == HTTP_CONNECT || transfer_encoding || + req.fs.content_length > 0 || req.http2_expect_body) { // Request-body is expected. nghttp2_data_provider data_prd{{}, http2_data_read_callback}; rv = http2session_->submit_request(this, nva.data(), nva.size(), &data_prd); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index b6337c7b..d2251789 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -373,9 +373,9 @@ int HttpDownstreamConnection::push_request_headers() { buf->append("\r\n"); } - if (!connect_method && req.http2_expect_body && - !req.fs.header(http2::HD_CONTENT_LENGTH)) { - + // set transfer-encoding only when content-length is unknown and + // request body is expected. + if (!connect_method && req.http2_expect_body && req.fs.content_length == -1) { downstream_->set_chunked_request(true); buf->append("Transfer-Encoding: chunked\r\n"); } diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 86195019..1dff8cd6 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -312,8 +312,10 @@ int htp_hdrs_completecb(http_parser *htp) { ULOG(INFO, upstream) << "HTTP request headers\n" << ss.str(); } - if (req.fs.parse_content_length() != 0) { - return -1; + // set content-length if no transfer-encoding is given. If + // transfer-encoding is given, leave req.fs.content_length to -1. + if (!req.fs.header(http2::HD_TRANSFER_ENCODING)) { + req.fs.content_length = htp->content_length; } auto host = req.fs.header(http2::HD_HOST);