caddyserver / replace-response

Caddy module that performs replacements in response bodies
Apache License 2.0
98 stars 27 forks source link

Support compression encoding #4

Open geraldwuhoo opened 3 years ago

geraldwuhoo commented 3 years ago

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).

mholt commented 3 years ago

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 commented 3 years ago

@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.)

yroc92 commented 3 years ago

@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!