Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403を返した場合もクライアントには403を返すようにします #11

Merged
merged 2 commits into from
Dec 1, 2023

Conversation

ryuichi1208
Copy link

No description provided.

@@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

403 forbidden をエラーにしない。

Comment on lines +169 to +189
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)
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

403 forbidden のレスポンスが正しく処理されることのテスト。

Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestOriginForbidden$ github.com/pepabo/oyaki

=== RUN   TestOriginForbidden
2023/12/01 13:09:43 Get origin failed. <nil>
--- PASS: TestOriginForbidden (0.00s)
PASS
ok      github.com/pepabo/oyaki (cached)

Copy link

@harukin721 harukin721 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よさそうだと思いました!

@ryuichi1208 ryuichi1208 merged commit a45b7ac into master Dec 1, 2023
2 checks passed
@ryuichi1208 ryuichi1208 deleted the fix_status branch December 1, 2023 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants