MCPcopy
hub / github.com/fabiolb/fabio / TestProxyPrependsPath

Function TestProxyPrependsPath

proxy/http_integration_test.go:255–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

253}
254
255func 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
284func TestProxyHost(t *testing.T) {
285 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 6

LookupMethod · 0.95
CloseMethod · 0.95
NewTableFunction · 0.92
mustGetFunction · 0.85
WriteMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected