Client scope not implemented
sralloza opened this issue · comments
Right now, the ASGI app can't access the client's ip and port, because a2wsgi.asgi.build_scope
returns client=None
.
Adding "client": (environ["REMOTE_ADDR"], environ["REMOTE_PORT"]),
to the return of build_scope
would fix it.
It seems that these two values are not mentioned in PEP3333. Can you tell me their source?
I haven't read it from any official PEP document. I just noticed that uvicorn (an ASGI server) implements them in the scope passed to the ASGI application. You can check the scope generated by uvicorn if by installing uvicorn and then executing this commands.
test.py
def app(scope):
async def asgi(receive, send):
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/plain"]],
}
)
await send({"type": "http.response.body", "body": str(scope).encode()})
return asgi
And then
uvicorn test:app --port 80
Or any other port.
Note: the simple asgi application was taken from here
I mean environ["REMOTE_ADDR"], environ["REMOTE_PORT"]
what is the source of these two values? It seems that these two values are not mentioned in the WSGI standard.
REMOTE_PORT
isn't mentioned in any official document , but REMOTE_ADDR
is mentioned here:
Several keys are optional in WSGI, but required in CGI, in particular SCRIPT_NAME, PATH_INFO and QUERY_STRING. Also REMOTE_ADDR and SERVER_SOFTWARE are supposed to exist, even if empty. All these keys could become required in WSGI.
I also saw relevant instructions in the ASGI standard.
If you are free, can you submit a PR? Or wait some time, I will modify it when I have time.
Thank you for your help, now you can get scope["client"]
with version 1.3.0 or higher.