@@ -336,6 +336,8 @@ def set_stat_headers(self, stat_result: os.stat_result) -> None:
336
336
337
337
async def __call__ (self , scope : Scope , receive : Receive , send : Send ) -> None :
338
338
send_header_only : bool = scope ["method" ].upper () == "HEAD"
339
+ send_pathsend : bool = "http.response.pathsend" in scope ["extensions" ]
340
+
339
341
if self .stat_result is None :
340
342
try :
341
343
stat_result = await anyio .to_thread .run_sync (os .stat , self .path )
@@ -354,7 +356,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
354
356
http_if_range = headers .get ("if-range" )
355
357
356
358
if http_range is None or (http_if_range is not None and not self ._should_use_range (http_if_range )):
357
- await self ._handle_simple (send , send_header_only )
359
+ await self ._handle_simple (send , send_header_only , send_pathsend )
358
360
else :
359
361
try :
360
362
ranges = self ._parse_range_header (http_range , stat_result .st_size )
@@ -373,11 +375,11 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
373
375
if self .background is not None :
374
376
await self .background ()
375
377
376
- async def _handle_simple (self , send : Send , send_header_only : bool ) -> None :
378
+ async def _handle_simple (self , send : Send , send_header_only : bool , send_pathsend : bool ) -> None :
377
379
await send ({"type" : "http.response.start" , "status" : self .status_code , "headers" : self .raw_headers })
378
380
if send_header_only :
379
381
await send ({"type" : "http.response.body" , "body" : b"" , "more_body" : False })
380
- elif "http.response.pathsend" in scope [ "extensions" ] :
382
+ elif send_pathsend :
381
383
await send ({"type" : "http.response.pathsend" , "path" : str (self .path )})
382
384
else :
383
385
async with await anyio .open_file (self .path , mode = "rb" ) as file :
0 commit comments