-
Notifications
You must be signed in to change notification settings - Fork 9
A way to modify headers like host as in nginx #29
-
Is there a way to modify headers like host?
Let's say I have a Web server running at 3000 and I want to use this reverse proxy to pass requests received at localhost:8005. But I need the host header to be localhost:3000 as it is required by the web server. How can I achieve this.
There does not seem to be a function to modify any thing. Am I missing something here? Or is it not yet supported ?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 3 replies
-
Hi @ankit-sapkota555 .
Is there a way to modify headers like host?
Have you read https://wsh032.github.io/fastapi-proxy-lib/Usage/Advanced/#modify-request ? Does it meet your needs?
newest link: https://www.python-httpx.org/advanced/authentication/#custom-authentication-schemes
I'm not sure if I understand your meaning correctly. Do you mean that there is a server running on port 8005, and you want to forward all requests received on port 8005 to port 3000?
And you want the requests received on port 3000 to have a request header with host: "localhost:3000" ?
Actually, this library will automatically modify the corresponding host for you, which follows common HTTP standards.
Have you encountered any specific errors while using it? Let me know, and perhaps I can help resolve it.
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes this follows common HTTP standards, but what I need is to forward all requests in port 8005 to 3000, but the web server expects the host header to be localhost:3000 (For my specific use case), So, to test that the proxy gateway will work as expected upon deployment, I need to modify the host header. Just curious if this is achievable through this package.
I will look into the docs refs and let you konw if they cover my use case. Thanks for the reply.
Beta Was this translation helpful? Give feedback.
All reactions
-
Just curious if this is achievable through this package.
Of course. Refer to the following code:
import httpx from fastapi_proxy_lib.fastapi.app import reverse_http_app class MyCustomAuth(httpx.Auth): def auth_flow(self, request: httpx.Request): # whatever you want to do with the headers of the request request.headers["host"] = "localhost:3000" yield request app = reverse_http_app( client=httpx.AsyncClient(auth=MyCustomAuth()), base_url="http://localhost:3000/", )
Please let me know if it works for you.
Beta Was this translation helpful? Give feedback.
All reactions
-
In fact, regardless of the request headers received on port 8005, the requests forwarded to port 3000 will always have "host": "localhost:3000". This functionality is available out of the box, so it's quite likely that you don't need to do anything.
Beta Was this translation helpful? Give feedback.