Skip to content

Add support for Brotli compression#326

Merged
pkieltyka merged 2 commits into
go-chi:masterfrom
polyfloyd:compress-brotli
Sep 11, 2018
Merged

Add support for Brotli compression#326
pkieltyka merged 2 commits into
go-chi:masterfrom
polyfloyd:compress-brotli

Conversation

@polyfloyd

Copy link
Copy Markdown
Contributor

This patch adds support for Google's Brotli compression format currently supported by Chrome, Firefox and IE edge.

@VojtechVitek VojtechVitek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this effort, but the problem is that gopkg.in/kothar/brotli-go.v0/enc comes with dependencies that use Cgo.

We're not likely to merge such dependencies into the github.com/go-chi/chi codebase.

However, if you provided a runtime initialization for additional encoders where you could "inject" the library on-demand, then I'd be down.

ie.

// middleware/compress.go
func AddEncoder(string, func(http.ResponseWriter) http.ResponseWriter)

// example:

init() {
    middleware.AddEncoder("br", func(w http.ResponseWriter) http.ResponseWriter {
        params := brotli_enc.NewBrotliParams()
        params.SetQuality(someLevel)
        return brotli_enc.NewBrotliWriter(params, w)
    })
}

Thoughts?

@polyfloyd

Copy link
Copy Markdown
Contributor Author

Ah yes, Runtime initialization seems like a good middle way to implement support Brotli until we have a native Go encoder.

@polyfloyd

Copy link
Copy Markdown
Contributor Author

Alright, I've added a new patch to support dynamic addition of encoders. Let me know what you think :)

@pkieltyka

Copy link
Copy Markdown
Member

nice work @polyfloyd — could use a review / small iteration but a nice addition. Do you have a separate subpkg somewhere (in another repo) with the Brotli encoder that uses this interface too? if not, we should make one once this interface is settled / merged

@polyfloyd

Copy link
Copy Markdown
Contributor Author

@pkieltyka I've added an example in one of the comments on how to set up Brotli compression.

@nicksrandall

Copy link
Copy Markdown

Is this PR waiting on anything before it can be merged?

@VojtechVitek

Copy link
Copy Markdown
Contributor

Hi, I'm back from vacation. I'll try to check out & test this PR in the upcoming week or two.

@berkant

berkant commented Aug 13, 2018

Copy link
Copy Markdown

When this is going to be merged?

@nicksrandall

Copy link
Copy Markdown

Is this PR waiting on anything before it can be merged? I would like to use this feature. Thank you!

@polyfloyd

Copy link
Copy Markdown
Contributor Author

I do not believe it is waiting for me! @VojtechVitek?

@pkieltyka

Copy link
Copy Markdown
Member

LGTM

@pkieltyka pkieltyka merged commit 235fa5d into go-chi:master Sep 11, 2018
@VojtechVitek

Copy link
Copy Markdown
Contributor

Sorry for delaying this. This is very good work! Thanks @polyfloyd

🎉 LGTM too

@VojtechVitek

Copy link
Copy Markdown
Contributor

I will test in production next week and report back.

@SirMetathyst SirMetathyst mentioned this pull request May 28, 2022
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.

5 participants