You can declare a parameter in a path operation function or dependency to be of type Request and then you can access the raw request object directly, without any validation, etc.
You can import it directly from fastapi:
fromfastapiimportRequest
Tip
When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an HTTPConnection instead of a Request or a WebSocket.
defurl_for(self,name:str,/,**path_params:typing.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)
asyncdefstream(self)->typing.AsyncGenerator[bytes,None]:ifhasattr(self,"_body"):yieldself._bodyyieldb""returnifself._stream_consumed:raiseRuntimeError("Stream consumed")whilenotself._stream_consumed:message=awaitself._receive()ifmessage["type"]=="http.request":body=message.get("body",b"")ifnotmessage.get("more_body",False):self._stream_consumed=Trueifbody:yieldbodyelifmessage["type"]=="http.disconnect":# pragma: no branchself._is_disconnected=TrueraiseClientDisconnect()yieldb""