From 2d790edac596da5da361475c949aec3e4ffedbb1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 20 Nov 2022 16:55:58 +0900 Subject: [PATCH] integration: Add http3 test which verifies chunked encoding ends prematurely --- integration-tests/nghttpx_http3_test.go | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/integration-tests/nghttpx_http3_test.go b/integration-tests/nghttpx_http3_test.go index 11b36c6c..ee4a8ebf 100644 --- a/integration-tests/nghttpx_http3_test.go +++ b/integration-tests/nghttpx_http3_test.go @@ -356,3 +356,35 @@ func TestH3ResponseBeforeRequestEnd(t *testing.T) { t.Errorf("res.status: %v; want %v", got, want) } } + +// TestH3H1ChunkedEndsPrematurely tests that a stream is reset if the +// backend chunked encoded response ends prematurely. +func TestH3H1ChunkedEndsPrematurely(t *testing.T) { + opts := options{ + handler: func(w http.ResponseWriter, r *http.Request) { + hj, ok := w.(http.Hijacker) + if !ok { + http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) + return + } + conn, bufrw, err := hj.Hijack() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + defer conn.Close() + bufrw.WriteString("HTTP/1.1 200\r\nTransfer-Encoding: chunked\r\n\r\n") + bufrw.Flush() + }, + quic: true, + } + st := newServerTester(t, opts) + defer st.Close() + + _, err := st.http3(requestParam{ + name: "TestH3H1ChunkedEndsPrematurely", + }) + if err == nil { + t.Fatal("st.http3() should fail") + } +}