-
-
Notifications
You must be signed in to change notification settings - Fork 610
Make it possible to have a dynamic reverse proxy #1132
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
Comments
@piraz Thank you for bringing this to my attention. Indeed, we need to make reverse proxy more powerful to make it useful in real-world scenarios. We started adding reverse proxy support when folks came asking for it. It was added as a starter template and was never well thought-out. I see two solutions, similar to what you proposed:
IMHO, option 2 is less work for me and importantly more flexible. |
Thanks @abhinavsingh. I think for the time being, using the skeleton app would be an option to replace the core ReverseProxy. Let me try to hack that and I get it you posted if it works. |
What's the ETA on this functionality? I have a strong use case for it and it's a bummer that it's not implemented. =( For command line options, it would be awesome if were something like this:
I know it doesn't cover POST request rewrites, but simple URI rewrites from the command line would be amazing. Nginx and apache offer something similar, but they are too heavy weight for my use case. Mitmproxy does not offer this capability, and that's unfortunate because the command line options are kind of simple. |
Script I'm working on right now (assuming initially proposed changes) is as follows:
This is simple and self contained, and would be significantly less of a headache than nginx or apache since they use so many config files. |
@rpgmaster280 Thanks for the proposal. This looks pretty close. I am also thinking that for a given regex, user might be interested in load-balancing between multiple endpoint. FWIW, I don't even want to anticipate or restrict developers from what they can do once a pattern is matched. Here is how I am imagining routes type definition might look like:
@piraz asked for match groups and IMHO we must also make way for it. I'll give more thought into it over the weekend. Once we have a clear idea of what to deliver, delivery should happen quick. Feel free to chime in with ideas/suggestions. Best |
I have some code that's pretty close. Haven't full vetted it yet but it's something like this (in reverse.py): Line 68 was throwing exceptions for me, so I had to change it to get the proxy to work for me. Lines 71 to 74 are where the actual changes are. I haven't testing this in the case where no regex groups are defined. |
Tested the code change above and it seems to work fine. Can't seem to get the tool to work with certificates and ssl though. I believe that to be a separate issue from this one. This solution does not include any sort of user error reporting. Did you want me to do a pull request with the changes?:
So I think I figured out the issue I was having with the connection to the forwarded server. Is it possible to specify the certificates the server uses for the forwarded connection? Been looking at the command line arguments and I don't see anything. |
@rpgmaster280 If you want please go ahead and send a PR. I can then either merge your PR and work on top of it, or simply work on top of your PR itself. I will try to take a look at it over the weekend. |
Note that wild card replacements are slow. It's better to be explicit when using regex pattern matching. This should be capture in the documentation. Please see below: |
Thank you for the PR. I'll get into it over weekend. Likely we can move discussion to PR then onwards for more specifics about regex and callback types |
tested this code, it seems the upstream server with port 8443,7443,6443 are not working for https reverse proxy, but 443 seems fine, and http reverse proxy can use any port. i'm not sure if this is a bug or i miss something. |
@sunnyjocker I'll double check shortly and update back on what's going on and what to expect. Thanks for bringing this to my attention. |
thanks for the help, looking forward to it. for security concern, i want to deploy the reverse proxy at public net, and the real service at lan of my lab. i tried "https to http"(https request and route to http url) configuration, but it doesn't work, i guess the reverse proxy works just as bypassing. |
Let me explain what I understand from the reverse proxy plugin and the reverse proxy implementation.
From the plugin: https://github.com/abhinavsingh/proxy.py/blob/develop/proxy/plugin/reverse_proxy.py#L16-L26. The code above is directing /get to httpbin.org/get either on http or https.
If I would decide to change the reverse proxy location so everything going through the proxy is matched like this:
Now everything(i.e. /get, /post/, /abcddfd/fd/dfd/33/3423432, etc...) will be matched by the proxy but will be dispatched to a fixed string in the
REVERSE_PROXY_PASS
array.This is clear in when the reverse proxy is handling the request: https://github.com/abhinavsingh/proxy.py/blob/develop/proxy/http/server/reverse.py#L65-L71.
My case is to create a reverse proxy that matches a regular expression and upstreams to a dynamic url, where matches from the solved pattern could be added to url.
If I would like to have a way to inject what was resolved from the pattern
r'/(.*)$'
, or any other pattern, to the self.reverse[route] in order to have something like:I cannot see a solution for that right now.
The approach of adding patterns will add complexity to the code but it will remove complexity from the developer's plugin.
Another solution would be adding a call from the
ReverseProxyBasePlugin
to resolve theself.choice = Url.from_bytes...
and give us the solved location with the pattern andself.reverse[route]
, we just override this method and things and return the magic.Currently we have no way to get into the handle request inside the
ReverseProxy
, added by the --enable-reverse-proxy option. If we have an option to provide what ReverseProxy to be used, that could be another solution to this problem.Please let me know if this issue can be solved by the current code and if I'm missing something.
Could you help me with this issue?
The text was updated successfully, but these errors were encountered: