-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#215 - Response: add support for flushing #218
Conversation
c25fc94
to
8c0796b
Compare
Pull Request Test Coverage Report for Build 9910117267Details
💛 - Coveralls |
- Response implement http.Flusher - Call PreWrite only once on the first Write - Add CommonWriter to reduce chained writers boilerplate - Use CommonWriter for log and compress middleware
8c0796b
to
f68b0c6
Compare
Awesome, This is exactly what I need right now! |
// be called with an empty byte slice. | ||
func (r *Response) Flush() { | ||
if !r.wroteHeader { | ||
r.PreWrite([]byte{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised by this line, because it will call prewrite, that will indeed send the header, but I feel strange to PreWrite during flush
Shouldn't you simply call WriteHeader ?
r.PreWrite([]byte{}) | |
r.WriteHeader(r.status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A flush will trigger a write so we want to trigger PreWrite
as well. It's only relevant if you call Flush
without having written anything (no prior call to Write
).
if !r.wroteHeader { | ||
if r.status == 0 { | ||
r.status = http.StatusOK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !r.wroteHeader { | |
if r.status == 0 { | |
r.status = http.StatusOK | |
if !r.IsHeaderWritten { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the check if 0, then OK into r.WriteHeader
if status == 0 {
status = http.StatusOK
}
References
Issue(s): closes #215
Description
Response
implementhttp.Flusher
PreWrite
only once on the firstWrite
CommonWriter
to reduce chained writers boilerplateCommonWriter
for log and compress middleware