-
Notifications
You must be signed in to change notification settings - Fork 270
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
Using handler.CompressHandler with mux.NotFoundHandler #83
Comments
Looks like the call to |
Interesting. Go 1.7? |
Yup, 1.7 |
Yeah, this is very strange. I've just found if I leave the browser error open for a while I get asked if I want to allow the site to download multiple files... but nothing actually downloads. Here's what curl gets: ~
🍡 curl -X GET http://localhost:3000/foo -v
* Trying ::1...
* Connected to localhost (::1) port 3000 (#0)
> GET /foo HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: application/x-gzip
< Date: Mon, 05 Sep 2016 07:30:15 GMT
< Vary: Accept-Encoding
< Content-Length: 15
<
* Connection #0 to host localhost left intact
404 - Not Found |
Looks like compress.go#L25 is the problem, commenting it out fixes this issue. Out of interest, why would the compress handler need to set a response code? |
@wayneashleyberry The gzip middleware writes the header as it's own If you comment that out, are you seeing the correct status codes written in all cases (e.g. non-200's)? This should not have changed under Go 1.7, either. |
Ah no, if I comment out |
I'm actually running into the same issue using https://github.com/phyber/negroni-gzip instead. |
I suspect that https://github.com/NYTimes/gziphandler won't cause the issue
On Mon, Sep 5, 2016 at 10:33 AM Wayne Ashley Berry notifications@github.com
|
Looks like I'm getting the exact same issue with the NYTimes/gziphandler, this is bleak :/ |
Might be related to nytimes/gziphandler#5 |
And with SSA disabled? On Mon, Sep 5, 2016 at 11:21 AM Wayne Ashley Berry notifications@github.com
|
Not quite sure where I run that command @elithrar, I tried running it in |
While checking out the source for https://golang.org/src/net/http/server.go?s=51433:51485#L1725 package main
import (
"fmt"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
r.HandleFunc("/", HomeHandler)
gzip := handlers.CompressHandler(r)
http.ListenAndServe(":"+os.Getenv("PORT"), gzip)
}
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
// A Content-Type header has to be set before calling w.WriteHeader,
// otherwise WriteHeader is called twice (from this handler and
// the compression handler) and the response breaks.
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "404 - not found")
}
func HomeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
} |
Setting the content-type header prevents the same thing from happening when using |
Without a Content-Type the browser doesn't know what to do. We should either:
Would you be able to PR this? |
@elithrar I think i can add some context here. For debugging Typically if
What is important is to make sure that Unfortunately the docs for
So. a) skip compression So if you put these things together, given the example from @wayneashleyberry you get
|
Correct. We need to effectively replicate wroteHeader in the default ResponseWriter On Sun, Sep 18, 2016 at 5:48 PM Jehiah Czebotar notifications@github.com
|
Hey,
I seem to be getting errors when using a
CompressHandler
in conjunction with aNotFoundHandler
. In the following example my 404's don't work at all and the browser's just dumping a "This site can’t be reached" error to the screen. No error messages or stack traces coming from Go either :/If I comment out
r.NotFoundHandler
orh2 := handlers.CompressHandler(h1)
then it works.The text was updated successfully, but these errors were encountered: