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

Assign new ResponseWriter after calling http.HandlerFunc #1341

Merged
merged 1 commit into from
Aug 7, 2019

Conversation

jszwedko
Copy link
Contributor

Otherwise, the http.ResponseWriter passed to next() within the
middleware is unused. This precludes middlewares from wrapping the
http.ResponseWriter to do things like record the status code.

Fixes #1257

There was a workaround mentioned in the linked issue to set the echo.Response.Writer in the middleware, but I think this is still an improvement as:

  • the current behavior is, in my opinion, pretty suprising. I expected the rw I passed to next() to get passed to the next middleware. In practice, I can just pass nil here and have the same effect as echo doesn't capture and use the rw
  • the mentioned workaround only works if you wrote the middleware. It precludes using 3rd-party HTTP middlewares

Otherwise, the `http.ResponseWriter` passed to `next()` within the
middleware is unused. This precludes middlewares from wrapping the
http.ResponseWriter to do things like record the status code.
@codecov
Copy link

codecov bot commented May 27, 2019

Codecov Report

Merging #1341 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1341      +/-   ##
==========================================
+ Coverage   84.39%   84.42%   +0.02%     
==========================================
  Files          27       27              
  Lines        2019     2022       +3     
==========================================
+ Hits         1704     1707       +3     
  Misses        205      205              
  Partials      110      110
Impacted Files Coverage Δ
context.go 90.79% <100%> (+0.07%) ⬆️
echo.go 85.66% <100%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbb7286...c68d845. Read the comment docs.

@stale
Copy link

stale bot commented Jul 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 26, 2019
@jszwedko
Copy link
Contributor Author

I believe this PR to still be relevant. cc/ @vishr

@stale stale bot removed the wontfix label Jul 26, 2019
@vishr
Copy link
Member

vishr commented Jul 26, 2019

@jszwedko Ignore the bot. I will look into it soon.

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.

Custom ResponseWriter not used by echo.WrapMiddleware
2 participants