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

fix Issue 136 - chunked transfer bodies are reencoded #149

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions output_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ func ParseRequest(data []byte) (request *http.Request, err error) {
return
}

// preserve chunked encoding (see #136)
for _, encoding := range request.TransferEncoding {
if encoding == "chunked" {
return
}
}

if request.Method == "POST" {
body, _ := ioutil.ReadAll(reader)
bodyBuf := bytes.NewBuffer(body)
Expand Down
7 changes: 4 additions & 3 deletions output_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestHTTPOutput(t *testing.T) {
defer req.Body.Close()
body, _ := ioutil.ReadAll(req.Body)

if string(body) != "a=1&b=2\r\n\r\n" {
if string(body) != "xyzxyzxyz" {
buf, _ := httputil.DumpRequest(req, true)
t.Error("Wrong POST body:", string(buf))
}
Expand All @@ -84,9 +84,10 @@ func TestHTTPOutput(t *testing.T) {
go Start(quit)

for i := 0; i < 100; i++ {
wg.Add(2)
wg.Add(3)
input.EmitPOST()
input.EmitOPTIONS()
input.EmitChunkedPOST()
input.EmitOPTIONS() // filtered out
input.EmitGET()
}

Expand Down
6 changes: 5 additions & 1 deletion test_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func (i *TestInput) EmitGET() {
}

func (i *TestInput) EmitPOST() {
i.data <- []byte("POST /pub/WWW/ HTTP/1.1\nHost: www.w3.org\r\n\r\na=1&b=2\r\n\r\n")
i.data <- []byte("POST /pub/WWW/ HTTP/1.1\nHost: www.w3.org\r\n\r\nxyzxyzxyz")
}

func (i *TestInput) EmitChunkedPOST() {
i.data <- []byte("POST /pub/WWW/ HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n9\r\nxyzxyzxyz\r\n0\r\n\r\n")
}

func (i *TestInput) EmitFile() {
Expand Down