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

Fix compression of *os.Files. #197

Merged
merged 1 commit into from
Aug 31, 2020
Merged

Conversation

muirdm
Copy link

@muirdm muirdm commented Aug 31, 2020

After using httpsnoop to preserve interfaces, the compress response
writer now implemented ReaderFrom. ReaderFrom is used by net/http to
use sendfile when serving *os.Files. This breaks compression because
it serves directly to the underlying response writer, skipping the
compressor. Fix by implementing ReadFrom on our resposne writer to
copy to our compressor.

Fixes #194.

After using httpsnoop to preserve interfaces, the compress response
writer now implemented ReaderFrom. ReaderFrom is used by net/http to
use sendfile when serving *os.Files. This breaks compression because
it serves directly to the underlying response writer, skipping the
compressor. Fix by implementing ReadFrom on our resposne writer to
copy to our compressor.

Fixes gorilla#194.
@muirdm muirdm force-pushed the fix-compress-file branch from 41705aa to 0cf2138 Compare August 31, 2020 17:00
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 a lot for this - LGTM.

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 a lot for this - LGTM.

// Make sure we can compress and serve an *os.File properly. We need
// to use a real http server to trigger the net/http sendfile special
// case.
func TestCompressFile(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👏🏻👏🏻👏🏻

@elithrar elithrar self-assigned this Aug 31, 2020
@elithrar elithrar merged commit d453eff into gorilla:master Aug 31, 2020
@andig
Copy link

andig commented Aug 31, 2020

After using httpsnoop to preserve interfaces, the compress response writer now implemented ReaderFrom.

Seems, after reading through the httpsnoop README, that using it is not as straightforward as advertised ;) Thank you for the quick turn-around time!

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.

[bug] COmpressHandler is broken
3 participants