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

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
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

Sweet contribution! Thanks ❤️

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.

rewrite Compress middleware
3 participants