From 9a89db575a8cbbc802f74fa7256f482af6623ec0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 24 Jan 2015 00:07:28 +0900 Subject: [PATCH] nghttpx: Reject multiple Content-Length even if their values are identical --- integration-tests/nghttpx_http1_test.go | 2 +- integration-tests/nghttpx_http2_test.go | 4 ++-- integration-tests/nghttpx_spdy_test.go | 2 +- src/shrpx_downstream.cc | 2 +- src/shrpx_http2_session.cc | 3 +-- src/shrpx_http2_upstream.cc | 3 +-- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/integration-tests/nghttpx_http1_test.go b/integration-tests/nghttpx_http1_test.go index 47630cdf..e1299a2a 100644 --- a/integration-tests/nghttpx_http1_test.go +++ b/integration-tests/nghttpx_http1_test.go @@ -62,7 +62,7 @@ func TestH1H1MultipleRequestCL(t *testing.T) { Host: %v Test-Case: TestH1H1MultipleRequestCL Content-Length: 0 -Content-Length: 1 +Content-Length: 0 `, st.authority)); err != nil { t.Fatalf("Error io.WriteString() = %v", err) diff --git a/integration-tests/nghttpx_http2_test.go b/integration-tests/nghttpx_http2_test.go index b112835c..435bc7b9 100644 --- a/integration-tests/nghttpx_http2_test.go +++ b/integration-tests/nghttpx_http2_test.go @@ -234,7 +234,7 @@ func TestH2H1MultipleRequestCL(t *testing.T) { name: "TestH2H1MultipleRequestCL", header: []hpack.HeaderField{ pair("content-length", "1"), - pair("content-length", "2"), + pair("content-length", "1"), }, }) if err != nil { @@ -372,7 +372,7 @@ func TestH2H1GracefulShutdown(t *testing.T) { func TestH2H2MultipleResponseCL(t *testing.T) { st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) { w.Header().Add("content-length", "1") - w.Header().Add("content-length", "2") + w.Header().Add("content-length", "1") }) defer st.Close() diff --git a/integration-tests/nghttpx_spdy_test.go b/integration-tests/nghttpx_spdy_test.go index 06be3834..6cf356d9 100644 --- a/integration-tests/nghttpx_spdy_test.go +++ b/integration-tests/nghttpx_spdy_test.go @@ -64,7 +64,7 @@ func TestS3H1MultipleRequestCL(t *testing.T) { name: "TestS3H1MultipleRequestCL", header: []hpack.HeaderField{ pair("content-length", "1"), - pair("content-length", "2"), + pair("content-length", "1"), }, }) if err != nil { diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 797e9f4e..0a6450ad 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -306,7 +306,7 @@ int index_headers(int *hdidx, Headers &headers, int64_t &content_length) { if (len == -1) { return -1; } - if (content_length != -1 && content_length != len) { + if (content_length != -1) { return -1; } content_length = len; diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 14dfdebf..2a0f19c1 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -742,8 +742,7 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame, downstream->set_response_state(Downstream::MSG_BAD_HEADER); return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } - auto cl = downstream->get_response_content_length(); - if (cl != -1 && cl != len) { + if (downstream->get_response_content_length() != -1) { http2session->submit_rst_stream(frame->hd.stream_id, NGHTTP2_PROTOCOL_ERROR); downstream->set_response_state(Downstream::MSG_BAD_HEADER); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 5741975a..4edb1606 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -206,8 +206,7 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame, } return 0; } - auto cl = downstream->get_request_content_length(); - if (cl != -1 && cl != len) { + if (downstream->get_request_content_length() != -1) { if (upstream->error_reply(downstream, 400) != 0) { return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; }