kennethreitz / responder

A familiar HTTP Service Framework for Python.
http://responder.kennethreitz.org/
Other
3.59k stars 218 forks source link

Using responder as a proxy (X-Forwarded) #252

Closed Serkan-devel closed 6 months ago

Serkan-devel commented 5 years ago

I'm trying to run a small webapp, which sometimes proxies connections to another webservice. Basically, I want to turn this nginx configuration but run it as a python app locally because I'm unable to use nginx.

Is there a way to set X-Forwarded-headers in a response?

mmanhertz commented 5 years ago

According to the docs you can set any header you want. Is there any reason the following wouldn't work?

resp.headers['X-Forwarded'] = <whatever you want>
spyoungtech commented 5 years ago

I think what you're looking for is something like a Proxy Middleware.

However, I'm not familiar with using middlewares with ASGI apps or how compatible (if at all) WSGI middlewares are with ASGI.

Serkan-devel commented 5 years ago

But does anyone know what ´$host´ or ´$proxy_add_x_forwarded_for´ from the nginx config actually mean?

agilezebra commented 5 years ago

We're also wanting to replace nginx with responder but similarly our nginx is currently proxying some requests downstream. The reason for wanting to move to responder over nginx is that we’re essentially using nginx as a static file webserver (serving out a handful of files that form a react application) with a couple of exceptional routes that are proxied to a firewalled wordpress server. Both the static files and the proxied service need some fairly complex JWT inspection/handling and the scripting capabilities of nginx (Lua in openresty) are very limiting. Instead we want to use a webserver/light-weight proxy with more sophisticated scripting and Python is our first choice for such. responder seems to fit the bill for serving the static files conditionally based on JWT but we’re unsure how to (again, conditionally) proxy on some requests downstream.

Serkan-devel commented 5 years ago

@agilezebra considering hst you might know more of nginx than me, how can I convert the variables for the python app?