Blazingly fast 🚀 HTTP range requests
I was digging around in the zerobrew sources – a brew alternative that adapts uv’s architecture to speed up brew. Don’t ask me how it works – I haven’t fully figured it out.
But I learned that HTTP supports partial requests through the Accept-Ranges header, allowing large files to
be downloaded in chunks via range requests.
It works like this: first, we send a HEAD request to the server to check whether it supports range requests:
curl -I https://i.imgur.com/z4d4kWk.jpg
We get something like:
HTTP/2 200
content-type: image/jpeg
last-modified: Thu, 02 Feb 2017 11:15:53 GMT
…
accept-ranges: bytes
content-length: 146515
And then we can pull the chunk we need (and, obviously, this can be parallelized or the download can be resumed if it gets interrupted) with something like:
curl -H "Range: bytes=0-999" https://i.imgur.com/z4d4kWk.jpg
It’s a small thing, but nice. As you can see, you can read an entire book about Network Performance and still learn something new every day.