mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Follow-up for pull request #42: properly initialize Request.URL field
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user