-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix]
httpbp
middleware doesn't flush chunked responses (#573)
* wrapped middleware supports Flush() and Hijack() * Update httpbp/middlewares.go Co-authored-by: Kyle Lemons <[email protected]> * added unit test * chain wrapper functions together * test tweaks * additional test cases * update to use jump table and support http.Pusher * remove generated code and write all wrappers by hand * PR feedback Co-authored-by: Adam Sax <[email protected]> Co-authored-by: Kyle Lemons <[email protected]>
- Loading branch information
1 parent
87a56c4
commit fae00cb
Showing
3 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package httpbp | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type optionalResponseWriter uint64 | ||
|
||
const ( | ||
flusher optionalResponseWriter = 1 << iota | ||
hijacker | ||
pusher | ||
) | ||
|
||
func wrapResponseWriter(orig, wrapped http.ResponseWriter) http.ResponseWriter { | ||
var w optionalResponseWriter | ||
f, isFlusher := orig.(http.Flusher) | ||
if isFlusher { | ||
w |= flusher | ||
} | ||
h, isHijacker := orig.(http.Hijacker) | ||
if isHijacker { | ||
w |= hijacker | ||
} | ||
p, isPusher := orig.(http.Pusher) | ||
if isPusher { | ||
w |= pusher | ||
} | ||
|
||
switch w { | ||
case 0: | ||
return wrapped | ||
case flusher: | ||
return struct { | ||
http.ResponseWriter | ||
http.Flusher | ||
}{wrapped, f} | ||
case hijacker: | ||
return struct { | ||
http.ResponseWriter | ||
http.Hijacker | ||
}{wrapped, h} | ||
case flusher | hijacker: | ||
return struct { | ||
http.ResponseWriter | ||
http.Flusher | ||
http.Hijacker | ||
}{wrapped, f, h} | ||
case pusher: | ||
return struct { | ||
http.ResponseWriter | ||
http.Pusher | ||
}{wrapped, p} | ||
case flusher | pusher: | ||
return struct { | ||
http.ResponseWriter | ||
http.Flusher | ||
http.Pusher | ||
}{wrapped, f, p} | ||
case hijacker | pusher: | ||
return struct { | ||
http.ResponseWriter | ||
http.Hijacker | ||
http.Pusher | ||
}{wrapped, h, p} | ||
case flusher | hijacker | pusher: | ||
return struct { | ||
http.ResponseWriter | ||
http.Flusher | ||
http.Hijacker | ||
http.Pusher | ||
}{wrapped, f, h, p} | ||
} | ||
|
||
return wrapped | ||
} |