コンテンツへスキップ

HTTPConnectionクラス

HTTPとWebSocketの両方と互換性があるべき依存関係を定義したい場合、RequestWebSocketの代わりにHTTPConnectionを受け取るパラメータを定義できます。

fastapi.requestsからインポートできます。

from fastapi.requests import HTTPConnection

fastapi.requests.HTTPConnection

HTTPConnection(scope, receive=None)

Bases: Mapping[str, Any]

受信HTTP接続のベースクラスで、RequestWebSocketの両方に共通する機能を提供するために使用されます。

starlette/requests.py内のソースコード
76
77
78
def __init__(self, scope: Scope, receive: Receive | None = None) -> None:
    assert scope["type"] in ("http", "websocket")
    self.scope = scope

scope instance-attribute

scope = scope

app property

app

url property

url

base_url property

base_url

headers property

headers

query_params property

query_params

path_params property

path_params

cookies property

cookies

client property

client

session property

session

auth property

auth

user property

user

state property

state

url_for

url_for(name, /, **path_params)
starlette/requests.py内のソースコード
182
183
184
185
186
187
def url_for(self, name: str, /, **path_params: typing.Any) -> URL:
    url_path_provider: Router | Starlette | None = self.scope.get("router") or self.scope.get("app")
    if url_path_provider is None:
        raise RuntimeError("The `url_for` method can only be used inside a Starlette application or with a router.")
    url_path = url_path_provider.url_path_for(name, **path_params)
    return url_path.make_absolute_url(base_url=self.base_url)