mliezun / caddy-snake

Caddy plugin to serve Python apps
MIT License
87 stars 3 forks source link

ASGI | Fastapi headers all return null #17

Closed cplmayo closed 4 months ago

cplmayo commented 4 months ago

Doing some basic testing with fastapi today and was unable to get request headers using the documented way in fastapi.

@app.get("/", response_class=HTMLResponse)
@htmx("index", "index")
async def root_page(request: Request, user_agent: str = Header(None)):
    print(user_agent)
    if request.method == "GET":
        return {"user_agent": user_agent}

When run using uvicorn I get the expected string however if executed through caddy-snake results in nulls. I tried multiple methods to extract the headers but always returned null.

mliezun commented 4 months ago

Hi @cplmayo! Thanks for reporting the issue 🙏

I was able to reproduce and fix the problem in PR #18

Can you confirm that it solves the problem on your side also?

You can build from a branch doing:

CGO_ENABLED=1 xcaddy build --with github.com/mliezun/caddy-snake@asgi-lowercase-headers
cplmayo commented 4 months ago

It is working for me; thank you for pushing this so quickly.

mliezun commented 4 months ago

Awesome! Thanks for testing it.

I'll merge and close the issue 👌