コンテンツにスキップ

HTTPConnection クラス

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

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

from fastapi.requests import HTTPConnection

fastapi.requests.HTTPConnection

HTTPConnection(scope, receive=None)

基底クラス: Mapping[str, Any]

着信 HTTP 接続の基底クラス。RequestWebSocket の両方に共通の機能を提供するために使用されます。

パラメータ 説明
スコープ

型: Scope

受信

型: Receive | None デフォルト: None

ソースコードは starlette/requests.py にあります
71
72
73
def __init__(self, scope: Scope, receive: Receive | None = None) -> None:
    assert scope["type"] in ("http", "websocket")
    self.scope = scope

スコープ インスタンス属性

scope = scope

アプリ プロパティ

app

URL プロパティ

url

ベース URL プロパティ

base_url

ヘッダー プロパティ

headers

クエリパラメータ プロパティ

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)
パラメータ 説明
名前

型: str

**path_params**

型: Any デフォルト: {}

ソースコードは starlette/requests.py にあります
177
178
179
180
def url_for(self, name: str, /, **path_params: typing.Any) -> URL:
    router: Router = self.scope["router"]
    url_path = router.url_path_for(name, **path_params)
    return url_path.make_absolute_url(base_url=self.base_url)