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
499044e1
Unverified
Commit
499044e1
authored
1 year ago
by
Will McCutchen
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: include Transfer-Encoding when echoing request headers (#130)
Fixes #128
parent
69e0f18f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
httpbin/handlers_test.go
+40
-0
40 additions, 0 deletions
httpbin/handlers_test.go
httpbin/helpers.go
+6
-2
6 additions, 2 deletions
httpbin/helpers.go
httpbin/helpers_test.go
+9
-1
9 additions, 1 deletion
httpbin/helpers_test.go
with
55 additions
and
3 deletions
httpbin/handlers_test.go
+
40
−
0
View file @
499044e1
...
@@ -553,6 +553,7 @@ func testRequestWithBody(t *testing.T, verb, path string) {
...
@@ -553,6 +553,7 @@ func testRequestWithBody(t *testing.T, verb, path string) {
testRequestWithBodyQueryParams
,
testRequestWithBodyQueryParams
,
testRequestWithBodyQueryParamsAndBody
,
testRequestWithBodyQueryParamsAndBody
,
testRequestWithBodyBinaryBody
,
testRequestWithBodyBinaryBody
,
testRequestWithBodyTransferEncoding
,
}
}
for
_
,
testFunc
:=
range
testFuncs
{
for
_
,
testFunc
:=
range
testFuncs
{
testFunc
:=
testFunc
testFunc
:=
testFunc
...
@@ -1030,6 +1031,45 @@ func testRequestWithBodyQueryParamsAndBody(t *testing.T, verb, path string) {
...
@@ -1030,6 +1031,45 @@ func testRequestWithBodyQueryParamsAndBody(t *testing.T, verb, path string) {
}
}
}
}
func
testRequestWithBodyTransferEncoding
(
t
*
testing
.
T
,
verb
string
,
path
string
)
{
testCases
:=
[]
struct
{
given
string
want
string
}{
{
""
,
""
},
{
"identity"
,
""
},
{
"chunked"
,
"chunked"
},
}
for
_
,
tc
:=
range
testCases
{
tc
:=
tc
t
.
Run
(
"transfer-encoding/"
+
tc
.
given
,
func
(
t
*
testing
.
T
)
{
t
.
Parallel
()
srv
:=
httptest
.
NewServer
(
app
)
defer
srv
.
Close
()
r
,
_
:=
http
.
NewRequest
(
verb
,
srv
.
URL
+
path
,
bytes
.
NewReader
([]
byte
(
"{}"
)))
if
tc
.
given
!=
""
{
r
.
TransferEncoding
=
[]
string
{
tc
.
given
}
}
httpResp
,
err
:=
srv
.
Client
()
.
Do
(
r
)
assertNilError
(
t
,
err
)
assertIntEqual
(
t
,
httpResp
.
StatusCode
,
http
.
StatusOK
)
var
resp
*
bodyResponse
if
err
:=
json
.
NewDecoder
(
httpResp
.
Body
)
.
Decode
(
&
resp
);
err
!=
nil
{
t
.
Fatalf
(
"failed to unmarshal body from JSON: %s"
,
err
)
}
got
:=
resp
.
Headers
.
Get
(
"Transfer-Encoding"
)
if
got
!=
tc
.
want
{
t
.
Errorf
(
"expected Transfer-Encoding %#v, got %#v"
,
tc
.
want
,
got
)
}
})
}
}
// TODO: implement and test more complex /status endpoint
// TODO: implement and test more complex /status endpoint
func
TestStatus
(
t
*
testing
.
T
)
{
func
TestStatus
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
...
...
This diff is collapsed.
Click to expand it.
httpbin/helpers.go
+
6
−
2
View file @
499044e1
...
@@ -25,11 +25,15 @@ const Base64MaxLen = 2000
...
@@ -25,11 +25,15 @@ const Base64MaxLen = 2000
// requestHeaders takes in incoming request and returns an http.Header map
// requestHeaders takes in incoming request and returns an http.Header map
// suitable for inclusion in our response data structures.
// suitable for inclusion in our response data structures.
//
//
// This is necessary to ensure that the incoming Host header is included,
// This is necessary to ensure that the incoming Host and Transfer-Encoding
// because golang only exposes that header on the http.Request struct itself.
// headers are included, because golang only exposes those values on the
// http.Request struct itself.
func
getRequestHeaders
(
r
*
http
.
Request
)
http
.
Header
{
func
getRequestHeaders
(
r
*
http
.
Request
)
http
.
Header
{
h
:=
r
.
Header
h
:=
r
.
Header
h
.
Set
(
"Host"
,
r
.
Host
)
h
.
Set
(
"Host"
,
r
.
Host
)
if
len
(
r
.
TransferEncoding
)
>
0
{
h
.
Set
(
"Transfer-Encoding"
,
strings
.
Join
(
r
.
TransferEncoding
,
","
))
}
return
h
return
h
}
}
...
...
This diff is collapsed.
Click to expand it.
httpbin/helpers_test.go
+
9
−
1
View file @
499044e1
...
@@ -14,8 +14,16 @@ import (
...
@@ -14,8 +14,16 @@ import (
)
)
func
assertNil
(
t
*
testing
.
T
,
v
interface
{})
{
func
assertNil
(
t
*
testing
.
T
,
v
interface
{})
{
t
.
Helper
()
if
v
!=
nil
{
if
v
!=
nil
{
t
.
Errorf
(
"expected nil, got %#v"
,
v
)
t
.
Fatalf
(
"expected nil, got %#v"
,
v
)
}
}
func
assertNilError
(
t
*
testing
.
T
,
err
error
)
{
t
.
Helper
()
if
err
!=
nil
{
t
.
Fatalf
(
"expected nil error, got %s (%T)"
,
err
,
err
)
}
}
}
}
...
...
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