From 7bdc48deb24a239872fff840f17343b0664cc439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Gime=CC=81nez?= Date: Mon, 3 Apr 2023 13:11:51 +0200 Subject: [PATCH 1/3] add httprequest unwrapping --- gzhttp/compress.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gzhttp/compress.go b/gzhttp/compress.go index 6ca11b1c10..a7418f0e6a 100644 --- a/gzhttp/compress.go +++ b/gzhttp/compress.go @@ -169,6 +169,10 @@ func (w *GzipResponseWriter) Write(b []byte) (int, error) { return len(b), nil } +func (w *GzipResponseWriter) Unwrap() http.ResponseWriter { + return w.ResponseWriter +} + var castagnoliTable = crc32.MakeTable(crc32.Castagnoli) // startGzip initializes a GZIP writer and writes the buffer. From df4f8bf7c19c02098753128b7743061c108ec1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Gime=CC=81nez?= Date: Mon, 3 Apr 2023 14:16:24 +0200 Subject: [PATCH 2/3] also for NoGzipResponseWriter --- gzhttp/compress.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gzhttp/compress.go b/gzhttp/compress.go index a7418f0e6a..8b73497574 100644 --- a/gzhttp/compress.go +++ b/gzhttp/compress.go @@ -986,3 +986,7 @@ func (n *NoGzipResponseWriter) WriteHeader(statusCode int) { } n.ResponseWriter.WriteHeader(statusCode) } + +func (n *NoGzipResponseWriter) Unwrap() http.ResponseWriter { + return n.ResponseWriter +} From b46a81d6ae5b8c30e1eeb6cd647b7fb4db5a9d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Gime=CC=81nez?= Date: Mon, 3 Apr 2023 14:39:13 +0200 Subject: [PATCH 3/3] add unwrap in newNoGzipResponseWriter with hijacker --- gzhttp/compress.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gzhttp/compress.go b/gzhttp/compress.go index 8b73497574..a7950b39ad 100644 --- a/gzhttp/compress.go +++ b/gzhttp/compress.go @@ -923,6 +923,10 @@ func atoi(s string) (int, bool) { return int(i64), err == nil } +type unwrapper interface { + Unwrap() http.ResponseWriter +} + // newNoGzipResponseWriter will return a response writer that // cleans up compression artifacts. // Depending on whether http.Hijacker is supported the returned will as well. @@ -933,10 +937,12 @@ func newNoGzipResponseWriter(w http.ResponseWriter) http.ResponseWriter { http.ResponseWriter http.Hijacker http.Flusher + unwrapper }{ ResponseWriter: n, Hijacker: hj, Flusher: n, + unwrapper: n, } return x }