@@ -464,6 +464,11 @@ func NewWrapper(opts ...option) (func(http.Handler) http.HandlerFunc, error) {
464464 return func (h http.Handler ) http.HandlerFunc {
465465 return func (w http.ResponseWriter , r * http.Request ) {
466466 w .Header ().Add (vary , acceptEncoding )
467+ if c .allowCompressedRequests && contentGzip (r ) {
468+ r .Header .Del (contentEncoding )
469+ r .Body = & gzipReader {body : r .Body }
470+ }
471+
467472 if acceptsGzip (r ) {
468473 gw := grwPool .Get ().(* GzipResponseWriter )
469474 * gw = GzipResponseWriter {
@@ -536,17 +541,18 @@ func (pct parsedContentType) equals(mediaType string, params map[string]string)
536541
537542// Used for functional configuration.
538543type config struct {
539- minSize int
540- level int
541- writer writer.GzipWriterFactory
542- contentTypes func (ct string ) bool
543- keepAcceptRanges bool
544- setContentType bool
545- suffixETag string
546- dropETag bool
547- jitterBuffer int
548- randomJitter string
549- sha256Jitter bool
544+ minSize int
545+ level int
546+ writer writer.GzipWriterFactory
547+ contentTypes func (ct string ) bool
548+ keepAcceptRanges bool
549+ setContentType bool
550+ suffixETag string
551+ dropETag bool
552+ jitterBuffer int
553+ randomJitter string
554+ sha256Jitter bool
555+ allowCompressedRequests bool
550556}
551557
552558func (c * config ) validate () error {
@@ -579,6 +585,15 @@ func MinSize(size int) option {
579585 }
580586}
581587
588+ // AllowCompressedRequests will enable or disable RFC 7694 compressed requests.
589+ // By default this is Disabled.
590+ // See https://datatracker.ietf.org/doc/html/rfc7694
591+ func AllowCompressedRequests (b bool ) option {
592+ return func (c * config ) {
593+ c .allowCompressedRequests = b
594+ }
595+ }
596+
582597// CompressionLevel sets the compression level
583598func CompressionLevel (level int ) option {
584599 return func (c * config ) {
@@ -752,6 +767,12 @@ func RandomJitter(n, buffer int, paranoid bool) option {
752767 }
753768}
754769
770+ // contentGzip returns true if the given HTTP request indicates that it gzipped.
771+ func contentGzip (r * http.Request ) bool {
772+ // See more detail in `acceptsGzip`
773+ return r .Method != http .MethodHead && r .Body != nil && parseEncodingGzip (r .Header .Get (contentEncoding )) > 0
774+ }
775+
755776// acceptsGzip returns true if the given HTTP request indicates that it will
756777// accept a gzipped response.
757778func acceptsGzip (r * http.Request ) bool {
0 commit comments