Skip to content

Commit 5db744a

Browse files
committed
#1122 do not set transfer encoding header for 204 response while doing https proxy
1 parent ed78ba2 commit 5db744a

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

functional-tests/core/ft_proxy_https_test.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/dghubble/sling"
66
. "github.com/onsi/ginkgo"
77
. "github.com/onsi/gomega"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"net/http/httptest"
1111
)
@@ -87,7 +87,7 @@ var _ = Describe("When I run Hoverfly", func() {
8787
response := hoverfly.Proxy(sling.New().Get("https://hoverfly.io/path"))
8888
Expect(response.StatusCode).To(Equal(http.StatusOK))
8989

90-
body, err := ioutil.ReadAll(response.Body)
90+
body, err := io.ReadAll(response.Body)
9191
Expect(err).To(BeNil())
9292
Expect(string(body)).To(Equal("OK"))
9393

@@ -131,7 +131,7 @@ var _ = Describe("When I run Hoverfly", func() {
131131
response := hoverfly.Proxy(sling.New().Get("https://hoverfly.io/path"))
132132
Expect(response.StatusCode).To(Equal(http.StatusOK))
133133

134-
body, err := ioutil.ReadAll(response.Body)
134+
body, err := io.ReadAll(response.Body)
135135
Expect(err).To(BeNil())
136136
Expect(string(body)).To(Equal("OK"))
137137

@@ -173,7 +173,7 @@ var _ = Describe("When I run Hoverfly", func() {
173173
response := hoverfly.Proxy(sling.New().Get("https://hoverfly.io/path"))
174174
Expect(response.StatusCode).To(Equal(http.StatusOK))
175175

176-
body, err := ioutil.ReadAll(response.Body)
176+
body, err := io.ReadAll(response.Body)
177177
Expect(err).To(BeNil())
178178
Expect(string(body)).To(Equal("OK"))
179179

@@ -183,6 +183,51 @@ var _ = Describe("When I run Hoverfly", func() {
183183
Expect(response.ContentLength).To(Equal(int64(-1)))
184184
Expect(response.TransferEncoding).To(Equal([]string{"chunked"}))
185185
})
186+
187+
It("should not set transfer encoding header for 204 response", func() {
188+
189+
hoverfly.ImportSimulation(`{
190+
"data": {
191+
"pairs": [
192+
{
193+
"request": {
194+
"path": [
195+
{
196+
"matcher": "exact",
197+
"value": "/path"
198+
}
199+
],
200+
"scheme": [
201+
{
202+
"matcher": "exact",
203+
"value": "https"
204+
}
205+
]
206+
},
207+
"response": {
208+
"status": 204,
209+
"body": ""
210+
}
211+
}
212+
]
213+
},
214+
"meta": {
215+
"schemaVersion": "v5.2"
216+
}
217+
}`)
218+
response := hoverfly.Proxy(sling.New().Get("https://hoverfly.io/path"))
219+
Expect(response.StatusCode).To(Equal(http.StatusNoContent))
220+
221+
body, err := io.ReadAll(response.Body)
222+
Expect(err).To(BeNil())
223+
Expect(string(body)).To(Equal(""))
224+
225+
Expect(response.Header.Get("Content-Length")).To(Equal(""))
226+
Expect(response.Header.Get("Transfer-Encoding")).To(Equal(""))
227+
228+
Expect(response.ContentLength).To(Equal(int64(0)))
229+
Expect(response.TransferEncoding).To(BeNil())
230+
})
186231
})
187232

188233
Context("and it uses default certificate and key configuration", func() {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.22.4
44

55
require (
66
github.com/ChrisTrenkamp/xsel v0.9.6
7-
github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7
8-
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7
7+
github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9
8+
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae
99
github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea
1010
github.com/SpectoLabs/raymond v2.0.3-0.20240313210732-e0e216cf0920+incompatible
1111
github.com/antonholmquist/jason v1.0.1-0.20160829104012-962e09b85496

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
33
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
44
github.com/ChrisTrenkamp/xsel v0.9.6 h1:0TmX81Wq2v2SnssP9SwBzz68KArsj5a8Dt9Ppj095QM=
55
github.com/ChrisTrenkamp/xsel v0.9.6/go.mod h1:72u+GN8aQUQNyZ5B+QIqWy7WPUey921sjN1k9FJ6Hbo=
6-
github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7 h1:TTZvVLRa0sjoFrxBOQdmuktR/IueSVyPA1Q+D8pHr9w=
7-
github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7/go.mod h1:tj8G0iNIS9fkG5PSrzQYLUXcvhtqI8XbIld9PqpYaFw=
8-
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7 h1:MxMvFwL66nKnrmjHhp9GODbHVZ+/qS2MmvnXz/nDdR4=
9-
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7/go.mod h1:rnDN1CpKP9iJXwxRtnvM7d5wdPHQY0K5NkHeXWPlQ+o=
6+
github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9 h1:KLYZMZu6prwwPmCalgoE+ah7FxANPjMH9kERMN9TMfc=
7+
github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9/go.mod h1:43+j4Hye/DLXHbJHM0O5dcwOkQp7zGCgDKTq6nzGXQM=
8+
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae h1:3Qfw4yZArPnqymR+G9sHRNBXHbrtj84wXaj6+EGkBjs=
9+
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae/go.mod h1:rnDN1CpKP9iJXwxRtnvM7d5wdPHQY0K5NkHeXWPlQ+o=
1010
github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea h1:VAu3xT0OShIqnm4K3TdPpxCd3k4uyXq/H6W76ueIWf0=
1111
github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea/go.mod h1:P8Yk6l9gKxTfgnJeXVEQKCH7nGgvhNdeLs0zVs2h2KM=
1212
github.com/SpectoLabs/raymond v2.0.3-0.20240313210732-e0e216cf0920+incompatible h1:qI0OVNVzpRLUMHD3lxGOXSHsH87xHp09IuQm9hjTfTA=

vendor/github.com/SpectoLabs/goproxy/https.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ github.com/ChrisTrenkamp/xsel/grammar/token
1515
github.com/ChrisTrenkamp/xsel/node
1616
github.com/ChrisTrenkamp/xsel/parser
1717
github.com/ChrisTrenkamp/xsel/store
18-
# github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7
19-
## explicit
18+
# github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9
19+
## explicit; go 1.18
2020
github.com/SpectoLabs/goproxy
21-
# github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7
21+
# github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae
2222
## explicit
2323
github.com/SpectoLabs/goproxy/ext/auth
2424
# github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea

0 commit comments

Comments
 (0)