Skip to content

Commit 8d68730

Browse files
committed
Rebase changes
1 parent 065dbcd commit 8d68730

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

starlette/responses.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ def set_stat_headers(self, stat_result: os.stat_result) -> None:
336336

337337
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
338338
send_header_only: bool = scope["method"].upper() == "HEAD"
339+
send_pathsend: bool = "http.response.pathsend" in scope["extensions"]
340+
339341
if self.stat_result is None:
340342
try:
341343
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:
354356
http_if_range = headers.get("if-range")
355357

356358
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)
358360
else:
359361
try:
360362
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:
373375
if self.background is not None:
374376
await self.background()
375377

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:
377379
await send({"type": "http.response.start", "status": self.status_code, "headers": self.raw_headers})
378380
if send_header_only:
379381
await send({"type": "http.response.body", "body": b"", "more_body": False})
380-
elif "http.response.pathsend" in scope["extensions"]:
382+
elif send_pathsend:
381383
await send({"type": "http.response.pathsend", "path": str(self.path)})
382384
else:
383385
async with await anyio.open_file(self.path, mode="rb") as file:

tests/middleware/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections.abc import AsyncGenerator, AsyncIterator, Generator
55
from contextlib import AsyncExitStack
66
from pathlib import Path
7-
from typing import Any, AsyncGenerator, AsyncIterator, Generator
7+
from typing import Any
88

99
import anyio
1010
import pytest
@@ -1182,6 +1182,7 @@ async def passthrough(request: Request, call_next: RequestResponseEndpoint) -> R
11821182
"version": "3",
11831183
"method": "GET",
11841184
"path": "/",
1185+
"headers": [],
11851186
"extensions": {"http.response.pathsend": {}},
11861187
}
11871188

tests/test_responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ async def send(message: Message) -> None:
379379

380380
# Since the TestClient doesn't support `pathsend`, we need to test this directly.
381381
await app(
382-
{"type": "http", "method": "get", "extensions": {"http.response.pathsend": {}}},
382+
{"type": "http", "method": "get", "headers": [], "extensions": {"http.response.pathsend": {}}},
383383
receive,
384384
send,
385385
)

0 commit comments

Comments
 (0)