HTTPConnection
类¶
当你想要定义与 HTTP 和 WebSockets 都兼容的依赖项时,你可以定义一个参数,该参数接受 HTTPConnection
而不是 Request
或 WebSocket
。
你可以从 fastapi.requests
导入它:
from fastapi.requests import HTTPConnection
fastapi.requests.HTTPConnection
¶
HTTPConnection(scope, receive=None)
Bases: Mapping[str, Any]
A base class for incoming HTTP connections, that is used to provide
any functionality that is common to both Request
and WebSocket
.
PARAMETER | DESCRIPTION |
---|---|
scope |
TYPE:
|
receive |
TYPE:
|
Source code in starlette/requests.py
71 72 73 |
|
url_for
¶
url_for(name, /, **path_params)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
**path_params |
TYPE:
|
Source code in starlette/requests.py
177 178 179 180 |
|