pallets / werkzeug

The comprehensive WSGI web application library.
https://werkzeug.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
6.65k stars 1.73k forks source link

Inaccurate Content-Range header in for partial content responses. #2871

Closed jeffpeng3 closed 7 months ago

jeffpeng3 commented 7 months ago

When my request header is Range: bytes=792-1955, the response header is bytes 792-1954/*, which is not correct.

@app.get("/ota/<filename>")
async def staticFile(filename: str):
    response = await send_from_directory("./ota/", filename)
    if request.range:
        temp = request.range.ranges[0]
        print(temp)
        await response.make_conditional(request, accept_ranges=True)
        print(response.headers["Content-Range"])
    return response

When the request is Range: bytes=792-1955, the response should be Content-Range: bytes 792-1955/*.

I think there was a problem with this code, and after deleting the - 1 from {end - 1} everything worked fine.

Environment:

==edited== I also noticed that it adds 1 to the end when it receives a request, but it looks like the end after this addition is not passed to the response, so I fixed the problem superficially after I removed the -1. So I think maybe this is a problem caused by quart.

(792, 1956)
bytes 792-1954/2354929051
[2024-04-01 18:43:30 +0000] [12382] [INFO] 10.1.4.128:47372 GET /ota/husky-ota-ap1a.240305.019.a1-f1130be5.zip 1.1 - - 1947
jeffpeng3 commented 7 months ago

I've confirmed that it's not werkzeug that's causing the problem, it's quart.