aboutsummaryrefslogtreecommitdiff
path: root/fasthttpadaptor
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-01-28 11:31:53 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-01-28 11:31:53 +0200
commit2af858a7da1c711db19b3dab618094e8a24799c9 (patch)
tree1af7ed236cfa1c301ee872e1e4f73d737db1ec1c /fasthttpadaptor
parentMerge pull request #42 from zviadm/master (diff)
downloadfasthttp-2af858a7da1c711db19b3dab618094e8a24799c9.tar.gz
fasthttp-2af858a7da1c711db19b3dab618094e8a24799c9.tar.bz2
fasthttp-2af858a7da1c711db19b3dab618094e8a24799c9.zip
Follow-up for pull request #42: properly initialize Request.URL field
Diffstat (limited to 'fasthttpadaptor')
-rw-r--r--fasthttpadaptor/adaptor.go10
-rw-r--r--fasthttpadaptor/adaptor_test.go9
2 files changed, 16 insertions, 3 deletions
diff --git a/fasthttpadaptor/adaptor.go b/fasthttpadaptor/adaptor.go
index 6171cfd..6fe0728 100644
--- a/fasthttpadaptor/adaptor.go
+++ b/fasthttpadaptor/adaptor.go
@@ -66,9 +66,13 @@ func NewFastHTTPHandler(h http.Handler) fasthttp.RequestHandler {
})
r.Header = hdr
r.Body = &netHTTPBody{body}
- // After Go1.5 http.ServeMux uses URL field to get the path for
- // request routing purposes.
- r.URL = &url.URL{Path: string(ctx.Path())}
+ rURL, err := url.ParseRequestURI(r.RequestURI)
+ if err != nil {
+ ctx.Logger().Printf("cannot parse requestURI %q: %s", r.RequestURI, err)
+ ctx.Error("Internal Server Error", fasthttp.StatusInternalServerError)
+ return
+ }
+ r.URL = rURL
var w netHTTPResponseWriter
h.ServeHTTP(&w, &r)
diff --git a/fasthttpadaptor/adaptor_test.go b/fasthttpadaptor/adaptor_test.go
index 13a7ee5..a0bcd32 100644
--- a/fasthttpadaptor/adaptor_test.go
+++ b/fasthttpadaptor/adaptor_test.go
@@ -5,6 +5,8 @@ import (
"io/ioutil"
"net"
"net/http"
+ "net/url"
+ "reflect"
"testing"
"github.com/valyala/fasthttp"
@@ -25,6 +27,10 @@ func TestNewFastHTTPHandler(t *testing.T) {
"Abc": "defg",
"XXX-Remote-Addr": "123.43.4543.345",
}
+ expectedURL, err := url.ParseRequestURI(expectedRequestURI)
+ if err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
callsCount := 0
nethttpH := func(w http.ResponseWriter, r *http.Request) {
@@ -61,6 +67,9 @@ func TestNewFastHTTPHandler(t *testing.T) {
if string(body) != expectedBody {
t.Fatalf("unexpected body %q. Expecting %q", body, expectedBody)
}
+ if !reflect.DeepEqual(r.URL, expectedURL) {
+ t.Fatalf("unexpected URL: %#v. Expecting %#v", r.URL, expectedURL)
+ }
for k, expectedV := range expectedHeader {
v := r.Header.Get(k)