Appending Content to Output

Hi Everybody!

I’m working on porting some functionality from my company’s older web stack over to Caddy, but I’ve run into something that I’m having trouble accomplishing with standard plugin/middleware implementations.

I need to write a script tag out after the file content is served. I’m able to do this with other webserver implementations by either tacking it on after the request has been processed or by parsing the HTML file and injecting the script tag right before I write out the file contents. I can easily write this content out from a plugin, but I haven’t been able to figure out how to write it after, just before, the content is written. This makes it not play nice with the gzip plugin, since running my plugin before gzip results in a chunk of non-compressed javascript at the top and running after leads to an invalid request in the browser since I’ve appended bytes onto an already-compressed output.

So, is it possible to do this with caddy plugins? Am I missing something simple? Do I need to look into using a custom server type for this? Any help is appreciated! Thanks!

Have you tried the filter plugin as far as I understand this is designed for this requirement.

https://caddyserver.com/docs/filter

I need to do this conditionally based on a querystring parameter, but I think this code should help me figure it out Thanks for the suggestion!

I think the request_url part should allow this.