Skip to content
Snippets Groups Projects
Unverified Commit 493d7aab authored by Will McCutchen's avatar Will McCutchen Committed by GitHub
Browse files

Merge pull request #49 from mccutchen/better-redirects

Better HTTP 300 & 308 handling
parents 3fb53d7c 8f5ca462
No related branches found
No related tags found
No related merge requests found
......@@ -172,12 +172,44 @@ func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request) {
"accept": acceptedMediaTypes,
})
http300body := []byte(`<!doctype html>
<head>
<title>Multiple Choices</title>
</head>
<body>
<ul>
<li><a href="/image/jpeg">/image/jpeg</a></li>
<li><a href="/image/png">/image/png</a></li>
<li><a href="/image/svg">/image/svg</a></li>
</body>
</html>`)
http308body := []byte(`<!doctype html>
<head>
<title>Permanent Redirect</title>
</head>
<body>Permanently redirected to <a href="/image/jpeg">/image/jpeg</a>
</body>
</html>`)
specialCases := map[int]*statusCase{
300: {
body: http300body,
headers: map[string]string{
"Location": "/image/jpeg",
},
},
301: redirectHeaders,
302: redirectHeaders,
303: redirectHeaders,
305: redirectHeaders,
307: redirectHeaders,
308: {
body: http308body,
headers: map[string]string{
"Location": "/image/jpeg",
},
},
401: {
headers: map[string]string{
"WWW-Authenticate": `Basic realm="Fake Realm"`,
......
......@@ -708,8 +708,26 @@ func TestStatus(t *testing.T) {
body string
}{
{200, nil, ""},
{300, map[string]string{"Location": "/image/jpeg"}, `<!doctype html>
<head>
<title>Multiple Choices</title>
</head>
<body>
<ul>
<li><a href="/image/jpeg">/image/jpeg</a></li>
<li><a href="/image/png">/image/png</a></li>
<li><a href="/image/svg">/image/svg</a></li>
</body>
</html>`},
{301, redirectHeaders, ""},
{302, redirectHeaders, ""},
{308, map[string]string{"Location": "/image/jpeg"}, `<!doctype html>
<head>
<title>Permanent Redirect</title>
</head>
<body>Permanently redirected to <a href="/image/jpeg">/image/jpeg</a>
</body>
</html>`},
{401, unauthorizedHeaders, ""},
{418, nil, "I'm a teapot!"},
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment