-
-
Notifications
You must be signed in to change notification settings - Fork 230
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 StringWriter
interface to ResponseWriter
#921
add StringWriter
interface to ResponseWriter
#921
Conversation
StringWriter
interface to ResponseWriter
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #921 +/- ##
=======================================
Coverage 81.81% 81.82%
=======================================
Files 160 160
Lines 9064 9066 +2
=======================================
+ Hits 7416 7418 +2
Misses 1399 1399
Partials 249 249
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
var _ http.ResponseWriter = (*rwInterceptor)(nil) | ||
type stringResponseWriter interface { | ||
http.ResponseWriter | ||
io.StringWriter |
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.
Do you mind pointing at an example of another similar code that implements io.StringWriter
? This doesn't seem so bad, but I'm wondering when a caller wouldn't just call Write([]byte(s))
themselves without inspecting the interfaces.
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.
This used to a thing but now I only find old references.
Like these :
- https://go.googlesource.com/benchmarks/+/master/garbage/nethttp.go#1690
- proposal: net/http: add ResponseWriterAs function golang/go#39558 (comment)
I suspect that WriteString
on ResponseWriter
is no longer common and that Write([]bytes(s))
is the idiomatic way.
We still have a bunch of tests to make sure that all middleware we add implements the needed interfaces. But it has been a while (±6 years) since I revisited those tests.
e.g. CloseNotifier
is also unimplemented here but that is documented as deprecated in http
.
So, yeah, this is ok to close for me :)
It can always be revisited if there is an actual need for this and not because of some legacy requirement.
Thank you for the super speedy review 🙇
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.
Thanks a lot for the investigation @romainmenke! Yeah let's go ahead and close for now then, if we find a strong use case for it we can reintroduce it.
Co-authored-by: Anuraag Agrawal <[email protected]>
Make sure that you've checked the boxes below before you submit PR:
This change adds the
io.StringWriter
interface to thehttp.ResponseWriter
implementation ininterceptor.go
.This is a fairly small addition because string values can be trivially converted to bytes.
It does not rely on the underlying
http.ResponseWriter
to also be aio.StringWriter
.Implementing
WriteString
is fairly common for http response writers.