-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect: Use klauspost/compress/gzip decompression (#3314)
* Fix missing parameter in makefile * connect: Use klauspost/compress/gzip decompression At the same time this make sures that all handlers and clients use the same compressor pool. Otherwise every new handler and client maintains its own pool.
- Loading branch information
1 parent
53f7de2
commit cf55c09
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package connectapi | ||
|
||
import ( | ||
"io" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/klauspost/compress/gzip" | ||
) | ||
|
||
const ( | ||
compressionGzip = "gzip" | ||
) | ||
|
||
var ( | ||
gzipPoolHandler = connect.WithCompression( | ||
compressionGzip, | ||
func() connect.Decompressor { return &gzip.Reader{} }, | ||
func() connect.Compressor { return gzip.NewWriter(io.Discard) }, | ||
) | ||
gzipPoolClient = connect.WithAcceptCompression( | ||
compressionGzip, | ||
func() connect.Decompressor { return &gzip.Reader{} }, | ||
func() connect.Compressor { return gzip.NewWriter(io.Discard) }, | ||
) | ||
) | ||
|
||
func WithGzipHandler() connect.HandlerOption { | ||
return gzipPoolHandler | ||
} | ||
|
||
func WithGzipClient() connect.ClientOption { | ||
return gzipPoolClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters