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

feat: use uri-reference for errors redirect to allow relative urls #516

Merged
merged 5 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,14 @@
"properties": {
"to": {
"title": "Redirect to",
"description": "Set the redirect target. Must be a http/https URL.",
"description": "Set the redirect target. Can either be a http/https URL, or a relative URL.",
"type": "string",
"format": "uri"
"format": "uri-reference",
"examples": [
"https://my-app.com/dashboard",
"https://my-app.com/dashboard",
xlanor marked this conversation as resolved.
Show resolved Hide resolved
"/dashboard"
]
},
"code": {
"title": "HTTP Redirect Status Code",
Expand Down
26 changes: 22 additions & 4 deletions pipeline/errors/error_redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestErrorRedirect(t *testing.T) {
assert func(t *testing.T, recorder *httptest.ResponseRecorder)
}{
{
d: "should redirect with 302",
d: "should redirect with 302 - absolute",
givenError: &herodot.ErrNotFound,
config: `{"to":"http://test/test"}`,
assert: func(t *testing.T, rw *httptest.ResponseRecorder) {
Expand All @@ -42,12 +42,30 @@ func TestErrorRedirect(t *testing.T) {
},
},
{
d: "should redirect with 301",
d: "should redirect with 302 - relative",
givenError: &herodot.ErrNotFound,
config: `{"to":"http://test/test","code":301}`,
xlanor marked this conversation as resolved.
Show resolved Hide resolved
config: `{"to":"/test"}`,
assert: func(t *testing.T, rw *httptest.ResponseRecorder) {
assert.Equal(t, 302, rw.Code)
assert.Equal(t, "/test", rw.Header().Get("Location"))
},
},
{
d: "should redirect with 301 - absolute",
givenError: &herodot.ErrNotFound,
config: `{"to":"/test","code":301}`,
assert: func(t *testing.T, rw *httptest.ResponseRecorder) {
assert.Equal(t, 301, rw.Code)
assert.Equal(t, "http://test/test", rw.Header().Get("Location"))
assert.Equal(t, "/test", rw.Header().Get("Location"))
},
},
{
d: "should redirect with 301 - relative",
givenError: &herodot.ErrNotFound,
config: `{"to":"/test"}`,
assert: func(t *testing.T, rw *httptest.ResponseRecorder) {
assert.Equal(t, 302, rw.Code)
assert.Equal(t, "/test", rw.Header().Get("Location"))
},
},
} {
Expand Down