Populate Request.URL.Path correctly.
Before, the Request.URL.Path was blank, causing the DefaultServeMux to
redirect in a loop forever.
This is the first version I've verified to work with both Firefox
Nightly and Chrome, both with their respective HTTP/2 modes enabled.
diff --git a/server.go b/server.go
index 15ef9d9..8ae0bab 100644
--- a/server.go
+++ b/server.go
@@ -718,9 +718,14 @@
sc: sc,
streamID: rp.stream.id,
}
+ url, err := url.ParseRequestURI(rp.path)
+ if err != nil {
+ // TODO: find the right error code?
+ return nil, nil, StreamError{rp.stream.id, ErrCodeProtocol}
+ }
req := &http.Request{
Method: rp.method,
- URL: &url.URL{},
+ URL: url,
RemoteAddr: sc.conn.RemoteAddr().String(),
Header: rp.header,
RequestURI: rp.path,
diff --git a/server_test.go b/server_test.go
index 1a03fd6..064296b 100644
--- a/server_test.go
+++ b/server_test.go
@@ -294,6 +294,9 @@
if r.Method != "GET" {
t.Errorf("Method = %q; want GET", r.Method)
}
+ if r.URL.Path != "/" {
+ t.Errorf("URL.Path = %q; want /", r.URL.Path)
+ }
if r.ContentLength != 0 {
t.Errorf("ContentLength = %v; want 0", r.ContentLength)
}
@@ -318,6 +321,24 @@
})
}
+func TestServer_Request_Get_PathSlashes(t *testing.T) {
+ testServerRequest(t, func(st *serverTester) {
+ st.writeHeaders(HeadersFrameParam{
+ StreamID: 1, // clients send odd numbers
+ BlockFragment: encodeHeader(t, ":path", "/%2f/"),
+ EndStream: true, // no DATA frames
+ EndHeaders: true,
+ })
+ }, func(r *http.Request) {
+ if r.RequestURI != "/%2f/" {
+ t.Errorf("RequestURI = %q; want /%2f/", r.RequestURI)
+ }
+ if r.URL.Path != "///" {
+ t.Errorf("URL.Path = %q; want ///", r.URL.Path)
+ }
+ })
+}
+
// TODO: add a test with EndStream=true on the HEADERS but setting a
// Content-Length anyway. Should we just omit it and force it to
// zero?