hypercorn
hypercorn copied to clipboard
AccessLog should use raw_path
Some asgi frameworks, for example, starlette, modifies scope["path"] during execution, which confuses the log output because hypercorn uses that to record the path.
Step to reproduce
- The code
from fastapi import FastAPI
app = FastAPI(title="CGI Server")
app.mount("/cgi-bin", Someapp) # type: ignore
if __name__ == "__main__":
import asyncio
from hypercorn.asyncio import serve
from hypercorn.config import Config
conf = Config.from_mapping(accesslog="-", bind="0.0.0.0:8000", loglevel="DEBUG")
asyncio.run(serve(app, conf)) # type: ignore
- Then
curl http://127.0.0.1:8000/cgi-bin/env.cgi
expected
[2022-09-03 23:10:16 +0800] [28820] [INFO] 127.0.0.1:59981 - - [03/Sep/2022:23:10:16 +0800] "GET /cgi-bin/env.cgi 1.1" 200 - "-" "Apache-HttpClient/4.5.13 (Java/17.0.3)"
got
[2022-09-03 23:12:08 +0800] [28820] [INFO] 127.0.0.1:60235 - - [03/Sep/2022:23:12:08 +0800] "GET /env.cgi 1.1" 200 - "-" "Apache-HttpClient/4.5.13 (Java/17.0.3)"
Issue was with Starlette