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

Re-wrote the middleware compress library. #401

Merged
merged 1 commit into from Feb 27, 2019

Conversation

@awbraunstein
Copy link
Contributor

awbraunstein commented Feb 26, 2019

This re-write introduces the concept of a Compressor which stores all the settings for how compression/encoding should happen. The old API was changed to use the new Compressor struct which should prevent this change from breaking current consumers.

Additionally, this uses a sync.Pool for encoders that have a Reset(io.Writer) method to reduce memory overhead.

The new API is as follows:

r := chi.NewRouter()
compressor := NewCompressor(5, "text/html", "text/css")
// Add in a no-op encoder.
compressor.SetEncoder("nop", func(w io.Writer, _ int) io.Writer {
	return w
})
r.Use(compressor.Handler())

This fixes #397.

This re-write introduces the concept of a Compressor which stores all the settings for how compression/encoding should happen. The old API was changed to use the new Compressor struct which should prevent this change from breaking current consumers.

Additionally, this uses a sync.Pool for encoders that have a Reset(io.Writer) method to reduce memory overhead.
@pkieltyka

This comment has been minimized.

Copy link
Member

pkieltyka commented Feb 27, 2019

wow @awbraunstein well done. the code looks very sharp and complete. I will review it in detail this evening. thanks for the quick turnaround

@pkieltyka

This comment has been minimized.

Copy link
Member

pkieltyka commented Feb 27, 2019

did a review, tested various edge cases manually, and works great. thanks again @awbraunstein

@pkieltyka pkieltyka merged commit 52e06e6 into go-chi:master Feb 27, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Copy link
Contributor

VojtechVitek left a comment

Sweet contribution! Thanks ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.