diff --git a/main.go b/main.go index a766814..8463213 100644 --- a/main.go +++ b/main.go @@ -87,7 +87,7 @@ func proxy(w http.ResponseWriter, r *http.Request) { orgRes, err = client.Do(req) } - if err != nil || orgRes.StatusCode == http.StatusNotFound { + if err != nil || orgRes.StatusCode == http.StatusNotFound || orgRes.StatusCode == http.StatusForbidden { http.Error(w, "Get origin failed", orgRes.StatusCode) log.Printf("Get origin failed. %v\n", err) return diff --git a/main_test.go b/main_test.go index dba3943..addc1fd 100644 --- a/main_test.go +++ b/main_test.go @@ -166,6 +166,27 @@ func TestOriginNotExist(t *testing.T) { } } +func TestOriginForbidden(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(proxy)) + + origin := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "403 Forbidden", http.StatusForbidden) + })) + + orgSrvURL = origin.URL + + url := ts.URL + "/forbidden.jpg" + + res, err := http.Get(url) + if err != nil { + t.Fatal(err) + } + + if res.StatusCode != http.StatusForbidden { + t.Errorf("HTTP status is %d, want %d", res.StatusCode, http.StatusNotFound) + } +} + func TestOriginBadGateWay(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(proxy))