Skip to content

skip compression on upgrade connection#187

Merged
elithrar merged 2 commits intogorilla:masterfrom
benitogf:skip-compression-on-upgrade
Aug 19, 2020
Merged

skip compression on upgrade connection#187
elithrar merged 2 commits intogorilla:masterfrom
benitogf:skip-compression-on-upgrade

Conversation

@benitogf
Copy link
Contributor

@benitogf benitogf commented Jun 2, 2020

Fixes #182

Summary of Changes

  1. Followed what was mentioned on the issue

@stale
Copy link

stale bot commented Aug 1, 2020

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

@stale stale bot added the stale label Aug 1, 2020
@benitogf
Copy link
Contributor Author

benitogf commented Aug 1, 2020

bump

@stale stale bot removed the stale label Aug 1, 2020
compress.go Outdated
Comment on lines +105 to +115
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
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be sufficient:

Suggested change
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
}
if r.Header.Get("Upgrade") != "" {
h.ServeHTTP(w, r)
return
}

return
}

if r.Header.Get("Upgrade") != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the review comment.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#187 (comment) - maybe I misunderstood here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! The proposal I made was already pushed, these 4 lines checking the Upgrade header should work fine (I've been using a wrapper implementing exactly this in production on framer.com for many months and haven't run into any issues with WebSockets.)

@elithrar elithrar self-assigned this Aug 19, 2020
Copy link
Contributor

@elithrar elithrar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @blixt!

@elithrar elithrar merged commit 2188616 into gorilla:master Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants