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

Question regarding path - Maybe stupid, but I would need some help #134

Open
mchingotto opened this issue Jan 17, 2022 · 4 comments
Open

Comments

@mchingotto
Copy link

mchingotto commented Jan 17, 2022

Hello,

Thank you for all the effort to make this works.
I have the revproxy inside a view at www.mysite.com/proxy/.
The problem I see is that in the responses the /proxy/ part is not added.

Test bed (example):

In this case, the upstream could be: www.google.com

So, for example, if a request goes to www.mysite.com/proxy/, it is translated to www.google.com, but in the response the url of the image that should be loaded (www.google.com/images/this_image.jpg) becomes www.mysite.com/images/this_image.jgp; instead of www.mysite.com/proxy/images/this_image.jgp. So, It does not work at all.

I hope to be clear. I read all questions done before, but I did not understand how to fix this.

A second question. Is there any way to add the IP address to the upstream plus the URL? I mean, in order to avoid DNS or etc/hosts to resolve it.

Thanks, I appreciate any help.
M

@brianmay
Copy link
Collaborator

What you want would require revproxy parse the response from the server and translate links such as /images/this_image.jpg to /proxy/images/this_image.jpg.

I think this might be the rewrite feature. Never used it myself, so not sure what it does exactly. See https://django-revproxy.readthedocs.io/en/latest/proxyview.html#revproxy.views.ProxyView.rewrite

@mchingotto
Copy link
Author

Hello brianmay,

Thank you for your fast answer, I appreciate it.
I tried already, but I found that rewrite only works for me in the upstream direction (maybe my fault), so, I can change the request, but I can not change the response. I feel confused because I thought everyone needs to translate the response too. I thought It was very common, but It seems I am thinking in the wrong way.

@brianmay
Copy link
Collaborator

brianmay commented Jan 18, 2022

Depends on your use case. For me I only ever used it once (in an application that was cancelled during development) to proxy 3rd party APIs and bypass JavaScript CORS restrictions, so I never needed any rewriting abilities in any direction.

Maybe this was never implemented. In which case the documentation should perhaps be clarified as to what "Basic URL rewrite" means.

@fabien-michel
Copy link

If someone fall here, I've managed to handle that case.

  1. Hack the returned HTML so it contain a token like {ROOT} in absolute src, href, etc…
  2. If a request arrive with that hook, proxy to root of the upstream

You can find a Mixin to implement this behavior here: https://gist.github.com/fabien-michel/dfc7105e87d8c89b646da7a0483657d9

from revproxy.views import ProxyView

from xxx import HandleRootUrlMixin

class MyProxyView(HandleRootUrlMixin, ProxyView):
  pass

The same gist contain other useful mixins to handle root url in Location header (redirect) and to clear sessionid cookie so a remote proxified django doesn't logout current user because of cookie forwarding

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

3 participants