datasette icon indicating copy to clipboard operation
datasette copied to clipboard

Database download missing content-length header and is sent chunked

Open amoeba opened this issue 1 year ago • 0 comments

With the latest Datasette (0.64.1 or latest git HEAD), when I serve my database like this,

$ datasette serve -i my.db

and try to download from http://127.0.0.1:8001/my.db,

I expect a content-length header since I think I'm downloading a static file from the filesystem but it's not set and the response is chunked instead:

$ curl -I "http://127.0.0.1:8001/my.db"
HTTP/1.1 200 OK
date: Sat, 06 Apr 2024 06:01:16 GMT
server: uvicorn
Etag: "c80e062a22bfff8042d1774f1c839ca3a7d95c53ae03a764fd4f6f1a5cbfd4de"
content-disposition: attachment; filename="my.db"
content-type: application/octet-stream
Transfer-Encoding: chunked

Is there a reason why the response is chunked here and not just sent normally with content-length? I'm guessing timeouts? I see https://github.com/simonw/datasette/issues/905 which makes it look like content-length should be getting set but when I attach a debugger the code that gets hit is https://github.com/simonw/datasette/blob/main/datasette/views/database.py#L302 which doesn't set it so I assume there's different code involved.

Setting content-length would be useful for my use-case which involves showing a progress bar for the request. MDN indicates mixing chunked and content-length might be a bad idea but I thought I'd suggest it in case it might work here.

amoeba avatar Apr 06 '24 06:04 amoeba