responder icon indicating copy to clipboard operation
responder copied to clipboard

Using responder as a proxy (X-Forwarded)

Open Serkan-devel opened this issue 6 years ago • 5 comments

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?

Serkan-devel avatar Nov 25 '18 12:11 Serkan-devel

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>

mmanhertz avatar Nov 26 '18 08:11 mmanhertz

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.

spyoungtech avatar Nov 27 '18 06:11 spyoungtech

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

Serkan-devel avatar Nov 29 '18 17:11 Serkan-devel

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.

agilezebra avatar Dec 03 '18 14:12 agilezebra

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

Serkan-devel avatar Dec 03 '18 14:12 Serkan-devel