Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Go Httpbin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Nix
Go Httpbin
Commits
493d7aab
Unverified
Commit
493d7aab
authored
4 years ago
by
Will McCutchen
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
httpbin/handlers.go
+32
-0
32 additions, 0 deletions
httpbin/handlers.go
httpbin/handlers_test.go
+18
-0
18 additions, 0 deletions
httpbin/handlers_test.go
with
50 additions
and
0 deletions
httpbin/handlers.go
+
32
−
0
View file @
493d7aab
...
...
@@ -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"`
,
...
...
This diff is collapsed.
Click to expand it.
httpbin/handlers_test.go
+
18
−
0
View file @
493d7aab
...
...
@@ -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!"
},
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment