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
d9c2d013
Commit
d9c2d013
authored
4 years ago
by
Will McCutchen
Browse files
Options
Downloads
Patches
Plain Diff
Fix handling of HEAD requests for streaming responses
parent
c429c2d3
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_test.go
+23
-0
23 additions, 0 deletions
httpbin/handlers_test.go
httpbin/middleware.go
+2
-2
2 additions, 2 deletions
httpbin/middleware.go
with
25 additions
and
2 deletions
httpbin/handlers_test.go
+
23
−
0
View file @
d9c2d013
...
@@ -1604,6 +1604,29 @@ func TestDrip(t *testing.T) {
...
@@ -1604,6 +1604,29 @@ func TestDrip(t *testing.T) {
assertStatusCode
(
t
,
w
,
test
.
code
)
assertStatusCode
(
t
,
w
,
test
.
code
)
})
})
}
}
t
.
Run
(
"ensure HEAD request works with streaming responses"
,
func
(
t
*
testing
.
T
)
{
srv
:=
httptest
.
NewServer
(
handler
)
defer
srv
.
Close
()
resp
,
err
:=
http
.
Head
(
srv
.
URL
+
"/drip?duration=900ms&delay=100ms"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %s"
,
err
)
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
t
.
Fatalf
(
"error reading response body: %s"
,
err
)
}
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatalf
(
"expected HTTP 200 OK rsponse, got %d"
,
resp
.
StatusCode
)
}
if
bodySize
:=
len
(
body
);
bodySize
>
0
{
t
.
Fatalf
(
"expected empty body from HEAD request, bot: %s"
,
string
(
body
))
}
})
}
}
func
TestRange
(
t
*
testing
.
T
)
{
func
TestRange
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
httpbin/middleware.go
+
2
−
2
View file @
d9c2d013
...
@@ -61,7 +61,7 @@ func limitRequestSize(maxSize int64, h http.Handler) http.Handler {
...
@@ -61,7 +61,7 @@ func limitRequestSize(maxSize int64, h http.Handler) http.Handler {
// headResponseWriter implements http.ResponseWriter in order to discard the
// headResponseWriter implements http.ResponseWriter in order to discard the
// body of the response
// body of the response
type
headResponseWriter
struct
{
type
headResponseWriter
struct
{
http
.
ResponseWriter
*
meta
ResponseWriter
}
}
func
(
hw
*
headResponseWriter
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
func
(
hw
*
headResponseWriter
)
Write
(
b
[]
byte
)
(
int
,
error
)
{
...
@@ -72,7 +72,7 @@ func (hw *headResponseWriter) Write(b []byte) (int, error) {
...
@@ -72,7 +72,7 @@ func (hw *headResponseWriter) Write(b []byte) (int, error) {
func
autohead
(
h
http
.
Handler
)
http
.
Handler
{
func
autohead
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
==
"HEAD"
{
if
r
.
Method
==
"HEAD"
{
w
=
&
headResponseWriter
{
w
}
w
=
&
headResponseWriter
{
&
metaResponseWriter
{
w
:
w
}
}
}
}
h
.
ServeHTTP
(
w
,
r
)
h
.
ServeHTTP
(
w
,
r
)
})
})
...
...
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