thomasw / djproxy Goto Github PK
View Code? Open in Web Editor NEWdjproxy is a class-based generic view reverse HTTP proxy for Django.
License: MIT License
djproxy is a class-based generic view reverse HTTP proxy for Django.
License: MIT License
The requests file this ships with installs a version of Django not compatible with Python 2.6. If you need to test things with that version of Python, you'll need to install a version of Django < 1.7.
In case the server returns more than one set-cookie
header, djproxy returns a single set-cookie
header that is incomprehensible to the browser.
This bug is known and reported in the operation of request
. It is appropriate to process this usecase to use the headers returned by urllib3 instead of the one from request.
For now, I have implemented this processing in a ForwardSetCookie
middleware.
I have the impression that it should be part of the core of the library, not to be deported in a middleware. It is the role of the proxy to correctly manage headers, cookies, ... I can redo my PR if it's the case.
class ForwardSetCookie(object):
"""
Handles the transmission of multiple cookies returned by a server as multiple set-cookie headers.
Request merges the set-cookie headers into one. The default behavior is ok
if the server returns only one cookie per http response.
The browser will receive only one cookie.
{
Set-Cookie: hello=world; Expires=Wed, 21 Oct 2015 07:28:00 GMT, world=hello
}
instead
{
Set-Cookie: hello=world; Expires=Wed, 21 Oct 2015 07:28:00 GMT
Set-Cookie: world=hello
}
pass
i want to check user permissions and then give him access to proxy.
but when i want to check request.user and its permissions, it give me Anonymous user
however it is not anonymous!!!
def process_request(self, proxy, request, **kwargs):
if request.method != 'OPTIONS':
_u = User.objects.get(username=request.user)
if not _u.has_perm('dummy.cm'):
return HttpResponse({"status": -1, "msg": "you don't have permission to be here"}, content_type='application/json', status=HTTP_403_FORBIDDEN)
else:
return response
else:
return response
Is there a way to define reverse proxy for dynamic domain?
URL links in proxied documents that begin with '/' always request the document at the url of the website. For example, if my website is www.example.com, and the proxy for an external site www.external.com is hosted at '/prefix/', if the proxied HTML document that is served as a response contains any links (href or src) starting with '/', for example, '/image/puppy.png', the link resolves to 'www.example.com/image/puppy.png' which is incorrect, since it ignores the prefix we have set up for the proxy.
Take look at a call of the base class' constructor here.
class HttpProxy(View):
...
def __init__(self, *args, **kwargs):
return super(View, self).__init__(*args, **kwargs)
It must be return super(HttpProxy, self).__init__(*args, **kwargs)
.
For anyone else looking for how to make this work in Django 3.1+, you'll find that url() is deprecated, so where you see this in the documentation:
url(r'^local_proxy/(?P<url>.*)$', LocalProxy.as_view(), name='proxy')
...change it to this:
path('local_proxy/<path:url>', views.LocalProxy.as_view(), name='proxy'),
(you could also use re_path()
, but there's really no need)
I hope this helps someone out :-)
Hi
I am trying to proxy requests to an internal Nginx server which in turn proxy_passes again. At the end, there is an IPython Notebook.
The problem is, that it complaints about missing CSRF cookie. Is there something special I need to set for that to work? Using the Nginx proxy directly works.
BTW: Is is also possible to proxy the websocket protocol?
Thanks!
Forgive me if it's a noob question. I usually code in other programming language. I tried using this library to proxy request but i was getting garbage value in prod which connects to a https url. After struggling i figured out that the headers is not passed from upstream to the proxy request. so i wrote a middle ware and added it to make it work. Is that intentional or bug ?
The middleware looks like this
class AddHeaders(object):
def process_response(self, proxy, request, upstream_response, response):
return HttpResponse(response.content, headers=upstream_response.headers)
It would be convenient if the "cert" kwarg for a client side certificate was exposed like the "verify" kwarg and passed through the call to self.middleware.process_request.
Line 13 in ce40f54
I was trying to proxy third-party software that sent a header named "x-http-method", and it got changed to "method".
Trying to use ReverseProxy on Django 2.1 but is does not add the location headers.
Later I see that it is only tested on Django 1 version.
Will this project get into a Version 2 release ?
Hi thomas,
great proxy you have developed there, thanks in first place ๐
Just a question if you took a look already at supporting websockets via the django-channels project? I was said to be included in django 1.10 but it wasn't but i wanted to ask if you would consider supporting it anyway??
Thanks!
I want to set up a reverse proxy that will proxy a Django app URL to another part of the same website that is outside of Django.
(for example):
www.mysite.com/MyDjangoApp/foo/* -> www.mysite.com/bar/*
And of course, I need this to work for whatever domain/server the app is installed on.
The example in the docs only shows proxying to a static upstream domain (base_url = 'https://google.com/'). How can I set "base_url" in order to use whatever server the original request was made to, instead of always going to a specific domain?
It this isn't specifically configurable, I suppose I could look at request.META['HTTP_HOST'] to find out what server to use, but is there a method that I can hook into where I will have access to the request, and also be able to set base_url at runtime?
I want to proxy and send ip x.x.x.x requests to y.y.y.y via z.z.z.z proxy!
Can i do this?
Hello Team,
Thank you for your efforts with this library.
I am confused about something. When configuring the middleware to ProxyPassReverse in the view, should I expect all links in the response content to the user (for example images inside the Html page) are going to be changed to the hostname the one is doing the proxy? I could not make this work. Am I doing something wrong?
Thank you, I appreciate it.
M
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.