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

Function TestProxy_ServeHTTP_cached304

imageproxy_test.go:603–648  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

601}
602
603func TestProxy_ServeHTTP_cached304(t *testing.T) {
604 cache := lrucache.New(1024*1024*8, 0)
605 client := new(http.Client)
606 tt := testTransport{}
607 client.Transport = &httpcache.Transport{
608 Transport: &TransformingTransport{
609 Transport: &tt,
610 CachingClient: client,
611 },
612 Cache: cache,
613 MarkCachedResponses: true,
614 }
615
616 p := &Proxy{
617 Client: client,
618 FollowRedirects: true,
619 }
620
621 // prime the cache
622 req := httptest.NewRequest("GET", "http://localhost//http://good.test/redirect-to-notmodified", nil)
623 recorder := httptest.NewRecorder()
624 p.ServeHTTP(recorder, req)
625
626 resp := recorder.Result()
627 if got, want := resp.StatusCode, http.StatusOK; got != want {
628 t.Errorf("ServeHTTP(%v) returned status %d, want %d", req, got, want)
629 }
630 if _, found := cache.Get("http://good.test/redirect-to-notmodified#0x0"); !found {
631 t.Errorf("Response to http://good.test/redirect-to-notmodified#0x0 should be cached")
632 }
633
634 // now make the same request again, but this time make sure the server responds with a 304
635 tt.replyNotModified = true
636 req = httptest.NewRequest("GET", "http://localhost//http://good.test/redirect-to-notmodified", nil)
637 recorder = httptest.NewRecorder()
638 p.ServeHTTP(recorder, req)
639
640 resp = recorder.Result()
641 if got, want := resp.StatusCode, http.StatusOK; got != want {
642 t.Errorf("ServeHTTP(%v) returned status %d, want %d", req, got, want)
643 }
644
645 if recorder.Body.String() != "Original response\n" {
646 t.Errorf("Response isn't what we expected: %v", recorder.Body.String())
647 }
648}
649
650func TestProxy_ServeHTTP_maxRedirects(t *testing.T) {
651 p := &Proxy{

Callers

nothing calls this directly

Calls 3

ServeHTTPMethod · 0.95
GetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected