Comments (9)
Yep you're right. Added some code in PR #59, don't know how attribution works on github but perhaps the repo owner can add you as well?
from gziphandler.
Can you provide an example? I'd very much like to fix this.
from gziphandler.
Sure thing! I am a bit lazy (and I have no idea what is causing the problem), so I think I will just send you the entire file.
Main.go.txt
from gziphandler.
I'm not very sure if this is an actual bug or me just misusing the library, I am kinda new to Golang still :P
Also, the code I sent you is a very early work in progress, and is nowhere near done.
from gziphandler.
It looks like http.ServeFile
sends its own status header, which overwrites yours. Does this work as expected when you remove the gzip middlware? The stdlib response logs an error (http: multiple response.WriteHeader calls) when this is the case, but our implementation silently overwrites the previous status, which is rather unhelpful. Sorry about that. I expect you'll see that error in your log.
from gziphandler.
Yup, this works as expected when I remove the gzip middleware. When I add gzip back, it goes back to silently removing the 404 status code. I do still see the 404 in my log, of course. But, the browser doesn't see it, and that can be a problem.
from gziphandler.
This is a bug in gziphandler, although you could almost say this is undefined behaviour of Golang's net/http.
The net/http WriteHeader functions all ignore multiple calls to WriteHeader and only use the status code from the first call. Unfortunately this behaviour is not explicitly documented anywhere.
func (w *response) WriteHeader(code int) {
...
if w.wroteHeader {
w.conn.server.logf("http: multiple response.WriteHeader calls")
return
}
w.wroteHeader = true
w.status = code
...
func (rws *http2responseWriterState) writeHeader(code int) {
if !rws.wroteHeader {
rws.wroteHeader = true
rws.status = code
...
I've fixed this with tmthrgd/gziphandler@c3e45bd in my fork. A similar fix could be introduced into this repository, care has to be taken to ensure that buffering of the response (for min size) doesn't cause future calls to WriteHeader to succeed.
from gziphandler.
I think #49 has fixed this too. Can you confirm, @kittyhacker101 / @tmthrgd ?
from gziphandler.
@EmielM I don't know how I missed your comment for all this time, sorry. I don't seem to have gotten a notification for it 😕
I just ran this repo against the test case I introduced in tmthrgd/gziphandler@c3e45bd and it still fails with:
--- FAIL: TestStatusCodes (0.00s)
gzip_test.go:287: StatusCode should have been 404 but was 500
The failing test code is (snippet):
handler = GzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
w.WriteHeader(http.StatusInternalServerError)
}))
w = httptest.NewRecorder()
handler.ServeHTTP(w, r)
result = w.Result()
if result.StatusCode != 404 {
t.Errorf("StatusCode should have been 404 but was %d", result.StatusCode)
}
#49 wasn't enough to fix this unfortunately.
from gziphandler.
Related Issues (20)
- Static files from ServeFile HOT 2
- Incorrect check for short write
- $maccon
- State of the package? HOT 1
- If not handleContenttype it buffers entire content
- make acceptsGzip public HOT 4
- Whitelist by mime type HOT 7
- Handling HEAD requests
- Do not set Content-Length on OPTIONS requests
- The NYTimes GitHub org will be renamed to nytimes HOT 4
- go mod depends on 1.12 HOT 11
- Range-Requests aren't properly handled
- Should Content-Length be set on gzipped responses? HOT 1
- Align Go package casing with VCS URL casing HOT 1
- Accept func(w http.ResponseWriter, r *http.Request) literals
- How to force flushing from the wrapped handler? HOT 4
- Show the error of gw.Close()
- Vary: Accept-encoding header is duplicated if inner handler sets it HOT 2
- Swappable gzip implementation? HOT 7
- "identity" Content-Encoding should also be compressed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gziphandler.