replace-response icon indicating copy to clipboard operation
replace-response copied to clipboard

Support compression encoding

Open geraldwuhoo opened this issue 4 years ago • 3 comments

Unless I am misinterpreting the code and set up my Caddy incorrectly, this module does not support replacing gzip/zstd/etc. compression encoded files. Since most people use Caddyserver as a reverse proxy for services, and many popular services serve gzip-encoded files, this module does not work in the majority of configurations.

Would love if this could be implemented (or even better, if I am misinterpreting the code and this is already supported).

geraldwuhoo avatar Jun 07 '21 05:06 geraldwuhoo

It works on the raw bytes of the response, regardless of encoding. To manipulate the decoded body, the handler would need a way to be configured to decode the body, perform the replacement, then re-encode.

Open to pull requests.

mholt avatar Jun 07 '21 17:06 mholt

@francislavoie came up with a clever solution if the encoded content comes from reverse_proxy, using a subdirective:

header_up  Accept-Encoding identity

(Of course, this doesn't help for precompressed static files so much. I guess you could set up an internal file server to serve the static files to which you proxy, and that could work.)

mholt avatar Aug 26 '21 05:08 mholt

@francislavoie came up with a clever solution if the encoded content comes from reverse_proxy, using a subdirective:

header_up  Accept-Encoding identity

(Of course, this doesn't help for static files so much. I guess you could set up an internal file server to serve the static files to which you proxy, and that could work.)

I was reverse-proxying to a server I had not control over and wanted to inject javascript into the response by replacing a <script> tag and this header was required to get it to work. Thanks!

yroc92 avatar Sep 28 '21 05:09 yroc92