nghttpx: Cleanup code where request content-length is involved

This commit is contained in:
Tatsuhiro Tsujikawa 2016-05-28 16:44:04 +09:00
parent 631f977236
commit 852a320586
3 changed files with 11 additions and 10 deletions

View File

@ -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);

View File

@ -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");
}

View File

@ -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);