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

issues/48: Fix superfluous response.WriteHeader call #302

Merged
merged 2 commits into from
Jul 2, 2023
Merged

Conversation

komuw
Copy link
Owner

@komuw komuw commented Jul 2, 2023

  • When http.ResponseWriter.WriteHeader() is called more than once, it always produces the error;
    http: superfluous response.WriteHeader call from github.com/komuw/ong/middleware.(*logRW).WriteHeader (log.go:121)
    And the stack trace always points to the ong log middleware. But that does not mean that ong has any issues.
    That error is always produced irrespective of if ong is used. It's how net/http works[2]
  • Also note that; if http.ResponseWriter.WriteHeader is not called explicitly, the first call to Write
    will trigger[3] an implicit WriteHeader(http.StatusOK).
  • So this PR does not fix the issue(since it is an actual feature of net/http), rather it clarifies that understanding.
  1. Fixes: http: superfluous response.WriteHeader call #48
  2. http: superfluous response.WriteHeader call #48 (comment)
  3. https://github.com/golang/go/blob/go1.20.5/src/net/http/server.go#L141-L159

@komuw komuw marked this pull request as ready for review July 2, 2023 10:31
@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05 🎉

Comparison is base (ff0b7f8) 73.37% compared to head (5aae181) 73.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   73.37%   73.43%   +0.05%     
==========================================
  Files          42       42              
  Lines        4782     4792      +10     
==========================================
+ Hits         3509     3519      +10     
  Misses       1021     1021              
  Partials      252      252              
Impacted Files Coverage Δ
middleware/log.go 68.67% <100.00%> (+4.29%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@komuw komuw merged commit 8b1a122 into main Jul 2, 2023
@komuw komuw deleted the issues/48/log branch July 2, 2023 10:53
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.

http: superfluous response.WriteHeader call
2 participants