-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Wrap http.ResponseWriter to greatly increase middleware/logging accesibilty #16
Conversation
Nice! good job. We already experimented wrapping the http.ResponseWriter, but we experimented a couple of bugs. For example: when you call Definitely it's on the roadmap. I will review your pull request tomorrow. |
Ah! Good catch. I'll see if I can get all the Write-esque methods patched up and resubmit |
Wrapping it in some way would be very handy. At the moment, i'm experimenting with a GZIP-middleware but thats kind of hard to accomplish without a wrapped ResponseWriter. I could wrap it myself inside the middleware but that feels wrong, and will definitely cause a performance hit. |
Wrapping the ResponseWriter could be also used to implement a redis cache middleware for example! We have to do it right, once the new allocator is ready, we will have much more flexibility to add features without degrading the performance. #24 |
Sorry for the delay everyone :( Let me know what you think and we can get it worked out much more quickly. I haven't come up with an intuitive way to get past the allocation.
The benches were done fairly offhandedly on an i7 MacbookPro |
@zmarcantel thanks to the new cache system, the context/responsewriter allocation is not going to be a problem any more. We could allocate 1MB and the performance would be still the same!! The contexts and responseWriters are going to be allocated once and reused many times! The fix for this issue is already working in develop branch, but since it's a very important one, I am not going to close it yet. |
Will a For example: If you wanted to change the names of the functions (only changes made) please accept this pull request and then immediately issue another commit changing them.... or ask the requester to do it so they get credit. I realize it's too late now, but this is a little frustrating and deters further development. |
@zmarcantel this was implemented a long time ago, but thanks for your work. I am sorry for the inconveniences I am going to add your username to the AUTHORS file. |
The returning status is hidden in http.ResponseWriter, but it's easy to wrap.
This follows Martini and other packages practice and allows giving access to many variables.
I have only included .Status() as an example, but Martini has body length and a few others.
There is also an example of an extended logger working as a middleware using the .Status() function to color output based on status code.
This examples could easily extend to other middleware that "fork" handling based on a specific status such as: