File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change 11
11
from email .utils import format_datetime , formatdate
12
12
from functools import partial
13
13
from mimetypes import guess_type
14
- from random import choices as random_choices
14
+ from secrets import token_hex
15
15
from urllib .parse import quote
16
16
17
17
import anyio
@@ -401,7 +401,8 @@ async def _handle_multiple_ranges(
401
401
file_size : int ,
402
402
send_header_only : bool ,
403
403
) -> None :
404
- boundary = "" .join (random_choices ("abcdefghijklmnopqrstuvwxyz0123456789" , k = 13 ))
404
+ # In firefox and
8000
chrome, they use boundary with 95-96 bits entropy (that's roughly 13 bytes).
405
+ boundary = token_hex (13 )
405
406
content_length , header_generator = self .generate_multipart (
406
407
ranges , boundary , file_size , self .headers ["content-type" ]
407
408
)
Original file line number Diff line number Diff line change @@ -598,13 +598,13 @@ def test_file_response_range_multi(file_response_client: TestClient) -> None:
598
598
response = file_response_client .get ("/" , headers = {"Range" : "bytes=0-100, 200-300" })
599
599
assert response .status_code == 206
600
600
assert response .headers ["content-range" ].startswith ("multipart/byteranges; boundary=" )
601
- assert response .headers ["content-length" ] == "400 "
601
+ assert response .headers ["content-length" ] == "439 "
602
602
603
603
604
604
def test_file_response_range_multi_head (file_response_client : TestClient ) -> None :
605
605
response = file_response_client .head ("/" , headers = {"Range" : "bytes=0-100, 200-300" })
606
606
assert response .status_code == 206
607
- assert response .headers ["content-length" ] == "400 "
607
+ assert response .headers ["content-length" ] == "439 "
<
4714
td data-grid-cell-id="diff-f3bc3ab9bfe202a2ded4890229180e22f76181ae47ab29df2b8b4ccec7e5d293-608-608-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">608
608
assert response .content == b""
609
609
610
610
response = file_response_client .head (
You can’t perform that action at this time.
0 commit comments