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

[bug] Compression middleware should step out of the way on upgrade requests #182

Closed
ghost opened this issue Apr 18, 2020 · 1 comment · Fixed by #187
Closed

[bug] Compression middleware should step out of the way on upgrade requests #182

ghost opened this issue Apr 18, 2020 · 1 comment · Fixed by #187
Labels

Comments

@ghost
Copy link

ghost commented Apr 18, 2020

See gorilla/websocket#589 for a complete description of the problem.

The summary is that compression middleware writes to hijacked connections on this line and the HTTP server panics as a result.

One fix for the issue is to detect hijack and avoid writing to the connection after hijack.

The larger problem is that the compression middleware should not do anything on a protocol upgrade request. The middleware assumes HTTP, but the connection will be used for a different protocol.

The middleware should call the handler directly when the connection upgrade token is present. Add the following to the beginning of the handler:

if httpguts.HeaderValuesContainsToken(r.Header["Connection"], "Upgrade") {
    h.ServeHTTP(w, r)
    return
}

If you don't want to add a dependency on httpguts, then do something like this:

var upgrade bool
for _, v := range strings.Split(r.Header.Get("Connection"), ",") {
    if strings.ToLower(strings.TrimSpace(v)) == "upgrade" {
        upgrade = true
        break
    }
}
if upgrade {
    h.ServeHTTP(w, r)
    return
}
@vtolstov
Copy link

any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant