Skip to content
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

Modifying reverse proxy response? #20

Open
torarnv opened this issue Dec 4, 2024 · 5 comments
Open

Modifying reverse proxy response? #20

torarnv opened this issue Dec 4, 2024 · 5 comments

Comments

@torarnv
Copy link

torarnv commented Dec 4, 2024

Can a CGI be fed the response from a reverse proxy, modify it , and spit out the modified response?

I tried this without success:

        reverse_proxy {host}:443 {
                header_up Host {upstream_hostport}
                handle_response {
                    handle /some/path/i/want/to/override {
                        cgi * /scripts/hello.py {
                            pass_all_env
                        }
                    }
                    handle {
                        copy_response
                    }
                }
            }
@aksdb
Copy link
Owner

aksdb commented Dec 4, 2024

That's an interesting problem. I'll try to reproduce that setup in the next days and see how far I can get. No promises yet 🙂

@torarnv
Copy link
Author

torarnv commented Dec 4, 2024

Thanks! :)

@aksdb
Copy link
Owner

aksdb commented Dec 7, 2024

I looked into it a bit and also searched through documentation and the caddy forum, but from what I can tell, there is no way to access the body of the reverse_proxy response. If you are only interested in the headers, you could basically do, what forward_auth does, but as soon as you need the body, there doesn't seem to be any way. If I missed anything, please point me in the right direction, otherwise I think this cannot be accomplished (here; it would have to be a change request towards caddy).

@torarnv
Copy link
Author

torarnv commented Dec 7, 2024

Thanks for looking into it! I guess as a workaround I can pass the required cookies as ENV and do the reverse proxying step in the CGI

@aksdb
Copy link
Owner

aksdb commented Dec 7, 2024

I think that would also be cleaner in general. You end up with a "proper" stream: client -> caddy -> cgi -> upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants