@@ -464,6 +464,11 @@ func NewWrapper(opts ...option) (func(http.Handler) http.HandlerFunc, error) {
464
464
return func (h http.Handler ) http.HandlerFunc {
465
465
return func (w http.ResponseWriter , r * http.Request ) {
466
466
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
+
467
472
if acceptsGzip (r ) {
468
473
gw := grwPool .Get ().(* GzipResponseWriter )
469
474
* gw = GzipResponseWriter {
@@ -536,17 +541,18 @@ func (pct parsedContentType) equals(mediaType string, params map[string]string)
536
541
537
542
// Used for functional configuration.
538
543
type 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
550
556
}
551
557
552
558
func (c * config ) validate () error {
@@ -579,6 +585,15 @@ func MinSize(size int) option {
579
585
}
580
586
}
581
587
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
+
582
597
// CompressionLevel sets the compression level
583
598
func CompressionLevel (level int ) option {
584
599
return func (c * config ) {
@@ -752,6 +767,12 @@ func RandomJitter(n, buffer int, paranoid bool) option {
752
767
}
753
768
}
754
769
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
+
755
776
// acceptsGzip returns true if the given HTTP request indicates that it will
756
777
// accept a gzipped response.
757
778
func acceptsGzip (r * http.Request ) bool {
0 commit comments