-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
templates: Access to proxy response (closes #4420) #4871
Conversation
Also sorted the func map just for kicks.
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
@byoungdale Is there still interest in this? Would be a shame to have to close it if we can't confirm this meets the requirements of the original feature request. |
I would still be interested, but unfortunately, I have no time at the moment to try it out. |
@byoungdale When will you try this? |
Closing due to inactivity :( We can merge this if someone who needs it tests it to confirm it works for them (rather than me just assuming it works for a real use case). |
I'm facing similar needs and can try. I know it's been awhile but If you want to reopen I'll test it. |
@frink Go for it 👍 |
Closing due to merge conflicts and inactivity. If anyone wants to take this up and fix the conflict, and test that it works for their use case, we can reopen. |
Would it be easy to modify this to allow passing the response body into another reverse_proxy? My usecase is to intercept all HTML responses from a service and add a script to their head section. From what I can tell the easiest way to do that would be to use some modified version of this feature to pass the response body to a service that returns a new HTML body with the script added. |
This WIP branch allows accessing the reverse proxy response in
templates
:This, of course, reads and drains the response body. I'm not really sure what I'm doing here, so I'm deferring to @francislavoie for a review on this. Maybe there's a better way to handle this. The argument 1024 here is the maximum size to read (since the body has to be buffered).
Accessing the body is admittedly a little awkward currently, since you have to use
call
. I tried withoutcall
and it saidBody has arguments but cannot be invoked as function
, so 🤷♂️ I guess you can't invoke functions as functions when they're struct fields: https://go.dev/src/text/template/exec.go?s=5814:5878@byoungdale could you please give this a try?