Ranged PUTs, Content-Range, and Content-Length
Date: Sun, 28 Apr 2019 10:27:27 -0700
I’m trying to PUT a sub-interval of a file. In simple terms, for the
sake of example, let’s say I have a 4-byte file and I want to PUT the
middle two bytes.
Here’s what I expect the headers to look like:
I’m having trouble telling libcurl to do that. Here’s what I tried:
If I set CURLOPT_RANGE to 1-2 and CURLOPT_INFILESIZE to 4, then I get
Content-Range 1-2/4, but Content-Length is set to 4 instead of the
If I set CURLOPT_RANGE to 1-2 and CURLOPT_INFILESIZE to 2, then I get
Content-Length 2, but Content-Range is set to 1-2/2 instead of 1-2/4.
If I set CURLOPT_RESUME_FROM to 1 and CURLOPT_INFILESIZE to 4, then I
get Content-Range 1-3/4 and Content-Length 3, which are sane relative
to each other but go all the way to EOF rather than stopping where I
If I set CURLOPT_RESUME_FROM to 1 and CURLOPT_INFILESIZE to 3, then I
get Content-Range: 1-2/3 and Content-Length 2, which is the right range
and length but the wrong total file size (Content-Range should be
If I set both CURLOPT_RESUME_FROM and CURLOPT_RANGE, the latter seems
to be completely ignored.
Right now I’m thinking of just setting CURLOPT_INFILESIZE to 2 and
CURLOPT_HTTPHEADER to Content-Range:1-2/4, but I would like to know if
I’m missing something and maybe there is a way to make libcurl do this
“properly” rather than manually constructing the header?
-- Christopher Head
- application/pgp-signature attachment: OpenPGP digital signature