| 253 | } |
| 254 | |
| 255 | func TestProxyPrependsPath(t *testing.T) { |
| 256 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 257 | switch r.RequestURI { |
| 258 | case "/foo/bar": |
| 259 | w.Write([]byte("OK")) |
| 260 | default: |
| 261 | w.WriteHeader(404) |
| 262 | } |
| 263 | })) |
| 264 | |
| 265 | proxy := httptest.NewServer(&HTTPProxy{ |
| 266 | ProtectHeaders: testProtectHeaders, |
| 267 | Transport: http.DefaultTransport, |
| 268 | Lookup: func(r *http.Request) *route.Target { |
| 269 | tbl, _ := route.NewTable(bytes.NewBufferString("route add mock /bar " + server.URL + ` opts "prepend=/foo"`)) |
| 270 | return tbl.Lookup(r, route.Picker["rr"], route.Matcher["prefix"], globCache, globEnabled) |
| 271 | }, |
| 272 | }) |
| 273 | defer proxy.Close() |
| 274 | |
| 275 | resp, body := mustGet(proxy.URL + "/bar") |
| 276 | if got, want := resp.StatusCode, http.StatusOK; got != want { |
| 277 | t.Fatalf("got status %d want %d", got, want) |
| 278 | } |
| 279 | if got, want := string(body), "OK"; got != want { |
| 280 | t.Fatalf("got body %q want %q", got, want) |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | func TestProxyHost(t *testing.T) { |
| 285 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |