git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #74 from jehiah/request_path_74
e1f4941Jehiah Czebotar
oauthproxy.go+3−2
@@ -67,7 +67,8 @@ func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
67 proxy.Director = func(req *http.Request) {
67 proxy.Director = func(req *http.Request) {
68 director(req)
68 director(req)
69 // use RequestURI so that we aren't unescaping encoded slashes in the request path
69 // use RequestURI so that we aren't unescaping encoded slashes in the request path
70+ req.Host = target.Host
70− req.URL.Opaque = fmt.Sprintf("//%s%s", target.Host, req.RequestURI)
71+ req.URL.Opaque = req.RequestURI
71 req.URL.RawQuery = ""
72 req.URL.RawQuery = ""
72 }
73 }
73}
74}
@@ -76,7 +77,7 @@ func setProxyDirector(proxy *httputil.ReverseProxy) {
76 proxy.Director = func(req *http.Request) {
77 proxy.Director = func(req *http.Request) {
77 director(req)
78 director(req)
78 // use RequestURI so that we aren't unescaping encoded slashes in the request path
79 // use RequestURI so that we aren't unescaping encoded slashes in the request path
79− req.URL.Opaque = fmt.Sprintf("//%s%s", req.URL.Host, req.RequestURI)
80+ req.URL.Opaque = req.RequestURI
80 req.URL.RawQuery = ""
81 req.URL.RawQuery = ""
81 }
82 }
82}
83}
oauthproxy_test.go+3−4
@@ -51,14 +51,13 @@ func TestEncodedSlashes(t *testing.T) {
51 defer frontend.Close()
51 defer frontend.Close()
52
52
53 f, _ := url.Parse(frontend.URL)
53 f, _ := url.Parse(frontend.URL)
54− encodedPath := "/a%2Fb/"
54+ encodedPath := "/a%2Fb/?c=1"
55 getReq := &http.Request{URL: &url.URL{Scheme: "http", Host: f.Host, Opaque: encodedPath}}
55 getReq := &http.Request{URL: &url.URL{Scheme: "http", Host: f.Host, Opaque: encodedPath}}
56 _, err := http.DefaultClient.Do(getReq)
56 _, err := http.DefaultClient.Do(getReq)
57 if err != nil {
57 if err != nil {
58 t.Fatalf("err %s", err)
58 t.Fatalf("err %s", err)
59 }
59 }
60− expected := backend.URL + encodedPath
60+ if seen != encodedPath {
61− if seen != expected {
62− t.Errorf("got bad request %q expected %q", seen, expected)
61+ t.Errorf("got bad request %q expected %q", seen, encodedPath)
63 }
62 }
64}
63}