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)