Skip to content

Commit

Permalink
nghttpx: Send non-final response to HTTP/1.1 or HTTP/2 client only
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Sep 21, 2017
1 parent 7d4d48a commit 2576855
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/shrpx-unittest.cc
Expand Up @@ -115,6 +115,8 @@ int main(int argc, char *argv[]) {
shrpx::test_downstream_assemble_request_cookie) ||
!CU_add_test(pSuite, "downstream_rewrite_location_response_header",
shrpx::test_downstream_rewrite_location_response_header) ||
!CU_add_test(pSuite, "downstream_supports_non_final_response",
shrpx::test_downstream_supports_non_final_response) ||
!CU_add_test(pSuite, "config_parse_header",
shrpx::test_shrpx_config_parse_header) ||
!CU_add_test(pSuite, "config_parse_log_format",
Expand Down
4 changes: 4 additions & 0 deletions src/shrpx_downstream.cc
Expand Up @@ -743,6 +743,10 @@ bool Downstream::get_non_final_response() const {
return !upgraded_ && resp_.http_status / 100 == 1;
}

bool Downstream::supports_non_final_response() const {
return req_.http_major == 2 || (req_.http_major == 1 && req_.http_minor == 1);
}

bool Downstream::get_upgraded() const { return upgraded_; }

bool Downstream::get_http2_upgrade_request() const {
Expand Down
3 changes: 3 additions & 0 deletions src/shrpx_downstream.h
Expand Up @@ -348,6 +348,9 @@ class Downstream {
// True if the response is non-final (1xx status code). Note that
// if connection was upgraded, 101 status code is treated as final.
bool get_non_final_response() const;
// True if protocol version used by client supports non final
// response. Only HTTP/1.1 and HTTP/2 clients support it.
bool supports_non_final_response() const;
void set_expect_final_response(bool f);
bool get_expect_final_response() const;

Expand Down
25 changes: 25 additions & 0 deletions src/shrpx_downstream_test.cc
Expand Up @@ -164,4 +164,29 @@ void test_downstream_rewrite_location_response_header(void) {
CU_ASSERT("https://localhost:8443/" == (*location).value);
}

void test_downstream_supports_non_final_response(void) {
Downstream d(nullptr, nullptr, 0);
auto &req = d.request();

req.http_major = 2;
req.http_minor = 0;

CU_ASSERT(d.supports_non_final_response());

req.http_major = 1;
req.http_minor = 1;

CU_ASSERT(d.supports_non_final_response());

req.http_major = 1;
req.http_minor = 0;

CU_ASSERT(!d.supports_non_final_response());

req.http_major = 0;
req.http_minor = 9;

CU_ASSERT(!d.supports_non_final_response());
}

} // namespace shrpx
1 change: 1 addition & 0 deletions src/shrpx_downstream_test.h
Expand Up @@ -36,6 +36,7 @@ void test_downstream_field_store_header(void);
void test_downstream_crumble_request_cookie(void);
void test_downstream_assemble_request_cookie(void);
void test_downstream_rewrite_location_response_header(void);
void test_downstream_supports_non_final_response(void);

} // namespace shrpx

Expand Down
5 changes: 5 additions & 0 deletions src/shrpx_https_upstream.cc
Expand Up @@ -1022,6 +1022,11 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
auto &resp = downstream->response();
auto &balloc = downstream->get_block_allocator();

if (!downstream->supports_non_final_response()) {
resp.fs.clear_headers();
return 0;
}

#ifdef HAVE_MRUBY
if (!downstream->get_non_final_response()) {
auto worker = handler_->get_worker();
Expand Down

0 comments on commit 2576855

Please sign in to comment.