from email.utils import format_datetime, formatdate
from functools import partial
from mimetypes import guess_type
-from random import choices as random_choices
+from secrets import token_hex
from urllib.parse import quote
import anyio
file_size: int,
send_header_only: bool,
) -> None:
- boundary = "".join(random_choices("abcdefghijklmnopqrstuvwxyz0123456789", k=13))
+ # In firefox and chrome, they use boundary with 95-96 bits entropy (that's roughly 13 bytes).
+ boundary = token_hex(13)
content_length, header_generator = self.generate_multipart(
ranges, boundary, file_size, self.headers["content-type"]
)
response = file_response_client.get("/", headers={"Range": "bytes=0-100, 200-300"})
assert response.status_code == 206
assert response.headers["content-range"].startswith("multipart/byteranges; boundary=")
- assert response.headers["content-length"] == "400"
+ assert response.headers["content-length"] == "439"
def test_file_response_range_multi_head(file_response_client: TestClient) -> None:
response = file_response_client.head("/", headers={"Range": "bytes=0-100, 200-300"})
assert response.status_code == 206
- assert response.headers["content-length"] == "400"
+ assert response.headers["content-length"] == "439"
assert response.content == b""
response = file_response_client.head(