bugfix: preserve optional interfaces on http.ResponseWriter #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
#80
Description of changes:
This change to preserves optional interfaces on http.ResponseWriter, while also preserving the behavior wherein checking for the presence of an optional interface correctly returns true or false.
Since we currently wrap the http.ResponseWriter to capture the status code and content length, we do not expose the common optional interfaces included in this PR.
Ultimately, I went with a solution based on what
httpsnoop
did: https://github.com/felixge/httpsnoop/blob/master/wrap_generated_gteq_1.8.go#L66I looked at a few other options.
Unfortunately, reflection currently doesn't allow you to add methods to structs for embedded types, so this doesn't work for our situation.
Flush
,Hijack
) from optional interfaces directly, and forward to the underlying ResponseWriter's implementation if they exist. I saw that a few other libraries went this route. It ends up being less code overall, however it breaks the ability for customer handlers to check for the presence of one of these methods before using it. Instead, this implementation panics or returns an error, which is different than what you'd expect if the ResponseWriter was not being wrapped.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.