aboutsummaryrefslogtreecommitdiff
path: root/fasthttpadaptor
diff options
context:
space:
mode:
authorGravatar Victor Gaydov <victor@enise.org> 2016-06-29 18:36:40 +0400
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-06-29 17:36:40 +0300
commit97d96cb3b7feaf22ce9b813313cd8ae20b3589b9 (patch)
tree6de5361500f14b0389e8a166d5822c0d3dd57720 /fasthttpadaptor
parentSecurity fix: limit request body size by default (diff)
downloadfasthttp-97d96cb3b7feaf22ce9b813313cd8ae20b3589b9.tar.gz
fasthttp-97d96cb3b7feaf22ce9b813313cd8ae20b3589b9.tar.bz2
fasthttp-97d96cb3b7feaf22ce9b813313cd8ae20b3589b9.zip
Handle TransferEncoding in fasthttpadaptor (#124)
When incoming http.Request is constructed, "Transfer-Encoding" header is removed, and http.Request.TransferEncoding is set instead. This behaviour is now emulated in fasthttpadaptor.
Diffstat (limited to 'fasthttpadaptor')
-rw-r--r--fasthttpadaptor/adaptor.go9
-rw-r--r--fasthttpadaptor/adaptor_test.go5
2 files changed, 13 insertions, 1 deletions
diff --git a/fasthttpadaptor/adaptor.go b/fasthttpadaptor/adaptor.go
index 6fe0728..46b19aa 100644
--- a/fasthttpadaptor/adaptor.go
+++ b/fasthttpadaptor/adaptor.go
@@ -62,7 +62,14 @@ func NewFastHTTPHandler(h http.Handler) fasthttp.RequestHandler {
hdr := make(http.Header)
ctx.Request.Header.VisitAll(func(k, v []byte) {
- hdr.Set(string(k), string(v))
+ sk := string(k)
+ sv := string(v)
+ switch sk {
+ case "Transfer-Encoding":
+ r.TransferEncoding = append(r.TransferEncoding, sv)
+ default:
+ hdr.Set(sk, sv)
+ }
})
r.Header = hdr
r.Body = &netHTTPBody{body}
diff --git a/fasthttpadaptor/adaptor_test.go b/fasthttpadaptor/adaptor_test.go
index a0bcd32..80c1948 100644
--- a/fasthttpadaptor/adaptor_test.go
+++ b/fasthttpadaptor/adaptor_test.go
@@ -20,6 +20,7 @@ func TestNewFastHTTPHandler(t *testing.T) {
expectedRequestURI := "/foo/bar?baz=123"
expectedBody := "body 123 foo bar baz"
expectedContentLength := len(expectedBody)
+ expectedTransferEncoding := "encoding"
expectedHost := "foobar.com"
expectedRemoteAddr := "1.2.3.4:6789"
expectedHeader := map[string]string{
@@ -53,6 +54,9 @@ func TestNewFastHTTPHandler(t *testing.T) {
if r.ContentLength != int64(expectedContentLength) {
t.Fatalf("unexpected contentLength %d. Expecting %d", r.ContentLength, expectedContentLength)
}
+ if len(r.TransferEncoding) != 1 || r.TransferEncoding[0] != expectedTransferEncoding {
+ t.Fatalf("unexpected transferEncoding %d. Expecting %d", r.TransferEncoding, expectedTransferEncoding)
+ }
if r.Host != expectedHost {
t.Fatalf("unexpected host %q. Expecting %q", r.Host, expectedHost)
}
@@ -91,6 +95,7 @@ func TestNewFastHTTPHandler(t *testing.T) {
req.Header.SetMethod(expectedMethod)
req.SetRequestURI(expectedRequestURI)
req.Header.SetHost(expectedHost)
+ req.Header.Add("Transfer-Encoding", expectedTransferEncoding)
req.BodyWriter().Write([]byte(expectedBody))
for k, v := range expectedHeader {
req.Header.Set(k, v)