-
Couldn't load subscription status.
- Fork 9
-
Hi,
I'm trying to build a FastAPI app with a reverse proxy. It sends the requests to a remote server, then modifies the response. It mostly works. However when it sits behind Cloudfront and makes a request to another Cloudfront endpoint (CF1 -> FastAPI -> CF2), I get 403 errors. It seems that it is linked to having a "via" header.
I'm trying to remove that header before sending the request, but when I do that, I get an Exception in ASGI application.
Here is the relevant part of the code:
proxy = ReverseHttpProxy(AsyncClient(), base_url=f"http://{fqdn}/")
@app.api_route("/{path:path}", methods=["GET", "HEAD", "OPTIONS"])
async def _(request: Request, path: str = ""):
# Remove the "via" header.
if "Via" in request.headers:
request.headers = MutableHeaders(dict(request.headers.items()))
del request.headers["Via"]
proxy_response = await proxy.proxy(request=request, path=path)
query_params = dict(request.query_params)
return proxy_response
If I comment the if statement, no issue (other than the 403 obviously).
Any idea what I'm doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Hi @wabiloo
I get an Exception in ASGI application
Can you send me the complete exception traceback?
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, not sure how to get that. I couldn't figure it out.
I'll try and give you a piece of code that you can run and that reproduces it
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, not sure how to get that. I couldn't figure it out.
just send me the terminal output, it might look something like this:
PS E:\GitHub\fastapi-proxy> python Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined
I'll try and give you a piece of code that you can run and that reproduces it
it's best to be a minimal reproducible example
Beta Was this translation helpful? Give feedback.