MCPcopy
hub / github.com/willnorris/imageproxy / TestProxy_ServeHTTP_is304

Function TestProxy_ServeHTTP_is304

imageproxy_test.go:583–601  ·  view source on GitHub ↗

test that 304 Not Modified responses are returned properly.

(t *testing.T)

Source from the content-addressed store, hash-verified

581
582// test that 304 Not Modified responses are returned properly.
583func TestProxy_ServeHTTP_is304(t *testing.T) {
584 p := &Proxy{
585 Client: &http.Client{
586 Transport: &testTransport{},
587 },
588 }
589
590 req, _ := http.NewRequest("GET", "http://localhost/http://good.test/etag", nil)
591 req.Header.Add("If-None-Match", `"tag"`)
592 resp := httptest.NewRecorder()
593 p.ServeHTTP(resp, req)
594
595 if got, want := resp.Code, http.StatusNotModified; got != want {
596 t.Errorf("ServeHTTP(%v) returned status %d, want %d", req, got, want)
597 }
598 if got, want := resp.Header().Get("Etag"), `"tag"`; got != want {
599 t.Errorf("ServeHTTP(%v) returned etag header %v, want %v", req, got, want)
600 }
601}
602
603func TestProxy_ServeHTTP_cached304(t *testing.T) {
604 cache := lrucache.New(1024*1024*8, 0)

Callers

nothing calls this directly

Calls 3

ServeHTTPMethod · 0.95
HeaderMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected