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
c0546840
Commit
c0546840
authored
8 years ago
by
Will McCutchen
Browse files
Options
Downloads
Patches
Plain Diff
Constant json content type
parent
c4135f95
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
httpbin/handlers.go
+2
-2
2 additions, 2 deletions
httpbin/handlers.go
httpbin/handlers_test.go
+14
-14
14 additions, 14 deletions
httpbin/handlers_test.go
httpbin/helpers.go
+1
-1
1 addition, 1 deletion
httpbin/helpers.go
httpbin/httpbin.go
+2
-0
2 additions, 0 deletions
httpbin/httpbin.go
with
19 additions
and
17 deletions
httpbin/handlers.go
+
2
−
2
View file @
c0546840
...
...
@@ -138,7 +138,7 @@ func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request) {
406
:
&
statusCase
{
body
:
notAcceptableBody
,
headers
:
map
[
string
]
string
{
"Content-Type"
:
"application/json; encoding=utf-8"
,
"Content-Type"
:
jsonContentType
,
},
},
407
:
&
statusCase
{
...
...
@@ -179,7 +179,7 @@ func (h *HTTPBin) ResponseHeaders(w http.ResponseWriter, r *http.Request) {
}
body
,
_
:=
json
.
Marshal
(
args
)
if
contentType
:=
w
.
Header
()
.
Get
(
"Content-Type"
);
contentType
==
""
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json; encoding=utf-8"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
jsonContentType
)
}
w
.
Write
(
body
)
}
...
...
This diff is collapsed.
Click to expand it.
httpbin/handlers_test.go
+
14
−
14
View file @
c0546840
...
...
@@ -92,7 +92,7 @@ func TestGet__Basic(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -135,7 +135,7 @@ func TestGet__WithParams(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -246,7 +246,7 @@ func TestIP(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
ipResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -266,7 +266,7 @@ func TestUserAgent(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
userAgentResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -289,7 +289,7 @@ func TestHeaders(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
headersResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -314,7 +314,7 @@ func TestPost__EmptyBody(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -342,7 +342,7 @@ func TestPost__FormEncodedBody(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -378,7 +378,7 @@ func TestPost__FormEncodedBodyNoContentType(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -426,7 +426,7 @@ func TestPost__MultiPartBody(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -488,7 +488,7 @@ func TestPost__JSON(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -536,7 +536,7 @@ func TestPost__BodyTooBig(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusBadRequest
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
}
func
TestPost__QueryParams
(
t
*
testing
.
T
)
{
...
...
@@ -550,7 +550,7 @@ func TestPost__QueryParams(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -587,7 +587,7 @@ func TestPost__QueryParamsAndBody(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
var
resp
*
bodyResponse
err
:=
json
.
Unmarshal
(
w
.
Body
.
Bytes
(),
&
resp
)
...
...
@@ -692,7 +692,7 @@ func TestResponseHeaders__OK(t *testing.T) {
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
http
.
StatusOK
)
assertContentType
(
t
,
w
,
"application/json; encoding=utf-8"
)
assertContentType
(
t
,
w
,
jsonContentType
)
for
k
,
expectedValues
:=
range
headers
{
values
,
ok
:=
w
.
HeaderMap
[
k
]
...
...
This diff is collapsed.
Click to expand it.
httpbin/helpers.go
+
1
−
1
View file @
c0546840
...
...
@@ -47,7 +47,7 @@ func getURL(r *http.Request) *url.URL {
}
func
writeJSON
(
w
http
.
ResponseWriter
,
body
[]
byte
,
status
int
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json; encoding=utf-8"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
jsonContentType
)
w
.
WriteHeader
(
status
)
w
.
Write
(
body
)
}
...
...
This diff is collapsed.
Click to expand it.
httpbin/httpbin.go
+
2
−
0
View file @
c0546840
...
...
@@ -5,6 +5,8 @@ import (
"net/url"
)
const
jsonContentType
=
"application/json; encoding=utf-8"
type
headersResponse
struct
{
Headers
http
.
Header
`json:"headers"`
}
...
...
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