Skip to content
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

Add WriteHeader call to Flush #634

Merged
merged 1 commit into from Aug 20, 2019
Merged

Add WriteHeader call to Flush #634

merged 1 commit into from Aug 20, 2019

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Aug 19, 2019

Flush is another of the methods that will call WriteHeader if it
hasn't happened yet. Since we want to call observeWriteHeader (if
set), we need to do the WriteHeader call already here, similar to what
we have done in Write and ReadFrom.

This commit also adds comments explaining the above to not tempt
developers to remove the WriteHeader call.

Signed-off-by: beorn7 beorn@grafana.com

Flush is another of the methods that will call WriteHeader if it
hasn't happened yet. Since we want to call observeWriteHeader (if
set), we need to do the WriteHeader call already here, similar to what
we have done in Write and ReadFrom.

This commit also adds comments explaining the above to not tempt
developers to remove the WriteHeader call.

Signed-off-by: beorn7 <beorn@grafana.com>
Copy link

@matthiasr matthiasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the ResponseWriter know that we already called WriteHeader? Could we rely on the same mechanism instead of implementing our own (wroteHeader)?

@beorn7
Copy link
Member Author

beorn7 commented Aug 20, 2019

It really depends on the implementation. The implementation I looked at in the standard library (https://golang.org/src/net/http/server.go) do the same thing, i.e. they have an unexported tracking variable wroteHeader. Since it is unexported, the delegator we are implementing here cannot access it and we have to do our own tracking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants