Skip to content

Commit

Permalink
#1122 do not set transfer encoding header for 204 response while doin…
Browse files Browse the repository at this point in the history
…g https proxy
  • Loading branch information
tommysitu committed Jul 17, 2024
1 parent ed78ba2 commit 5db744a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
53 changes: 49 additions & 4 deletions functional-tests/core/ft_proxy_https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/dghubble/sling"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
)
Expand Down Expand Up @@ -87,7 +87,7 @@ var _ = Describe("When I run Hoverfly", func() {
response := hoverfly.Proxy(sling.New().Get("https://hoverfly.io/path"))
Expect(response.StatusCode).To(Equal(http.StatusOK))

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("OK"))

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

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("OK"))

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

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal("OK"))

Expand All @@ -183,6 +183,51 @@ var _ = Describe("When I run Hoverfly", func() {
Expect(response.ContentLength).To(Equal(int64(-1)))
Expect(response.TransferEncoding).To(Equal([]string{"chunked"}))
})

It("should not set transfer encoding header for 204 response", func() {

hoverfly.ImportSimulation(`{
"data": {
"pairs": [
{
"request": {
"path": [
{
"matcher": "exact",
"value": "/path"
}
],
"scheme": [
{
"matcher": "exact",
"value": "https"
}
]
},
"response": {
"status": 204,
"body": ""
}
}
]
},
"meta": {
"schemaVersion": "v5.2"
}
}`)
response := hoverfly.Proxy(sling.New().Get("https://hoverfly.io/path"))
Expect(response.StatusCode).To(Equal(http.StatusNoContent))

body, err := io.ReadAll(response.Body)
Expect(err).To(BeNil())
Expect(string(body)).To(Equal(""))

Expect(response.Header.Get("Content-Length")).To(Equal(""))
Expect(response.Header.Get("Transfer-Encoding")).To(Equal(""))

Expect(response.ContentLength).To(Equal(int64(0)))
Expect(response.TransferEncoding).To(BeNil())
})
})

Context("and it uses default certificate and key configuration", func() {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.22.4

require (
github.com/ChrisTrenkamp/xsel v0.9.6
github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7
github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae
github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea
github.com/SpectoLabs/raymond v2.0.3-0.20240313210732-e0e216cf0920+incompatible
github.com/antonholmquist/jason v1.0.1-0.20160829104012-962e09b85496
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChrisTrenkamp/xsel v0.9.6 h1:0TmX81Wq2v2SnssP9SwBzz68KArsj5a8Dt9Ppj095QM=
github.com/ChrisTrenkamp/xsel v0.9.6/go.mod h1:72u+GN8aQUQNyZ5B+QIqWy7WPUey921sjN1k9FJ6Hbo=
github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7 h1:TTZvVLRa0sjoFrxBOQdmuktR/IueSVyPA1Q+D8pHr9w=
github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7/go.mod h1:tj8G0iNIS9fkG5PSrzQYLUXcvhtqI8XbIld9PqpYaFw=
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7 h1:MxMvFwL66nKnrmjHhp9GODbHVZ+/qS2MmvnXz/nDdR4=
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7/go.mod h1:rnDN1CpKP9iJXwxRtnvM7d5wdPHQY0K5NkHeXWPlQ+o=
github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9 h1:KLYZMZu6prwwPmCalgoE+ah7FxANPjMH9kERMN9TMfc=
github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9/go.mod h1:43+j4Hye/DLXHbJHM0O5dcwOkQp7zGCgDKTq6nzGXQM=
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae h1:3Qfw4yZArPnqymR+G9sHRNBXHbrtj84wXaj6+EGkBjs=
github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae/go.mod h1:rnDN1CpKP9iJXwxRtnvM7d5wdPHQY0K5NkHeXWPlQ+o=
github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea h1:VAu3xT0OShIqnm4K3TdPpxCd3k4uyXq/H6W76ueIWf0=
github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea/go.mod h1:P8Yk6l9gKxTfgnJeXVEQKCH7nGgvhNdeLs0zVs2h2KM=
github.com/SpectoLabs/raymond v2.0.3-0.20240313210732-e0e216cf0920+incompatible h1:qI0OVNVzpRLUMHD3lxGOXSHsH87xHp09IuQm9hjTfTA=
Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/SpectoLabs/goproxy/https.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ github.com/ChrisTrenkamp/xsel/grammar/token
github.com/ChrisTrenkamp/xsel/node
github.com/ChrisTrenkamp/xsel/parser
github.com/ChrisTrenkamp/xsel/store
# github.com/SpectoLabs/goproxy v0.0.0-20220724221645-71c396c297b7
## explicit
# github.com/SpectoLabs/goproxy v0.0.0-20240717215706-55e01f38b2c9
## explicit; go 1.18
github.com/SpectoLabs/goproxy
# github.com/SpectoLabs/goproxy/ext v0.0.0-20220724221645-71c396c297b7
# github.com/SpectoLabs/goproxy/ext v0.0.0-20220724222243-c982a2c966ae
## explicit
github.com/SpectoLabs/goproxy/ext/auth
# github.com/SpectoLabs/goxml2json v0.0.0-20240121223617-8e03292c14ea
Expand Down

0 comments on commit 5db744a

Please sign in to comment.