Movatterモバイル変換


[0]ホーム

URL:


콘텐츠로 이동
Join theFastAPI Cloud waiting list 🚀
Follow@fastapi onX (Twitter) to stay updated
FollowFastAPI onLinkedIn to stay updated
Subscribe to theFastAPI and friends newsletter 🎉
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor

HTTPConnection class

When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes anHTTPConnection instead of aRequest or aWebSocket.

You can import it fromfastapi.requests:

fromfastapi.requestsimportHTTPConnection

fastapi.requests.HTTPConnection

HTTPConnection(scope,receive=None)

Bases:Mapping[str,Any],Generic[StateT]

A base class for incoming HTTP connections, that is used to provideany functionality that is common to bothRequest andWebSocket.

Source code instarlette/requests.py
858687
def__init__(self,scope:Scope,receive:Receive|None=None)->None:assertscope["type"]in("http","websocket")self.scope=scope

scopeinstance-attribute

scope=scope

appproperty

app

urlproperty

url

base_urlproperty

base_url

headersproperty

headers

query_paramsproperty

query_params

path_paramsproperty

path_params

cookiesproperty

cookies

clientproperty

client

sessionproperty

session

authproperty

auth

userproperty

user

stateproperty

state

url_for

url_for(name,/,**path_params)
Source code instarlette/requests.py
192193194195196197
defurl_for(self,name:str,/,**path_params:Any)->URL:url_path_provider:Router|Starlette|None=self.scope.get("router")orself.scope.get("app")ifurl_path_providerisNone:raiseRuntimeError("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)returnurl_path.make_absolute_url(base_url=self.base_url)

[8]ページ先頭

©2009-2026 Movatter.jp