Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty body with chunked encoding will return 500 Internal server error #240

Open
vincentob opened this issue Oct 15, 2023 · 0 comments
Open
Labels

Comments

@vincentob
Copy link

Hi guys,

I found that oxy/buffer can't handle response with chunked encoding and empty body. I can reproduce it by adding the testcase below:

func TestEmptyChunkedResponse(t *testing.T) {
	srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
		h := w.(http.Hijacker)
		conn, _, _ := h.Hijack()
		_, _ = fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n")
		_ = conn.Close()
	})
	t.Cleanup(srv.Close)

	fwd := forward.New(false)

	rdr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		req.URL = testutils.ParseURI(srv.URL)
		fwd.ServeHTTP(w, req)
	})
	st, err := New(rdr)
	require.NoError(t, err)
	proxy := httptest.NewServer(st)

	t.Cleanup(proxy.Close)

	re, body, err := testutils.Get(proxy.URL)
	require.NoError(t, err)
	assert.Equal(t, "", string(body))
	assert.Equal(t, http.StatusOK, re.StatusCode)
}

I have test proxys like nginx and traefik with curl, they all looks fine. But if i use oxy/buffer, it will return 500 Internal Server Error

@ldez ldez added the question label Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants