Re: Range:-Header support
Peter Conrad <[email protected]> Thu, 13 Jun 2002 09:31:27 +0200
| Newsgroups | gmane.comp.djb.publicfile |
|---|---|
| Message-ID | <[email protected]> |
Hi,
On Wed, Jun 12, 2002 at 04:04:41PM +0200, Andreas Kotes wrote:
>
> there's no Range:-Header support for publicfile yet, I've hacked
> together a rudimentary version which runs with recent wgets.
Rudimentary indeed. You're breaking lots of things here.
> + lastbyte = length;
> +
> + if (range.len && (protocolnum != 1))
> + barf ("500 ", "Range:-Header supported with HTTP/1.0 only. Strange, but true.");
Huh? HTTP/1.0 doesn't specify a range header. I guess you mean 1.1 and
protocolnum != 2? Hm, maybe you should leave that check out, because a
client that sends a Range: header in its request can be assumed to handle
a Partial-Content response.
> + if (byte_chr (range.s, range.len, ",") < range.len)
> + barf ("500 ", "Only single ranges supported.");
> +
> + rangedelim = byte_chr (range.s, range.len, "-");
> + if (range.len && (range.s[0] == '-'))
> + barf ("500 ", "Ranges to the end of file not supported.");
Instead of barf()ing on unsupported stuff you should return the entire
document, i. e. ignore the Range: header.
> + if (lastbyte > length)
This should be >=.
> + barf ("500 ", "Range extends beyond file length");
As long as firstbyte < length the range is satisfiable and you should return
the satisfiable part (i. e. set lastbyte = length - 1).
> + if (firstbyte > lastbyte)
> + barf ("500 ", "Range starts after its own end");
In that case you should return 416 "Requested range not satisfiable".
> + out_put (strnum, fmt_ulong (strnum, lastbyte - firstbyte)); /* XXX: could change */
Shouldn't this be lastbyte - firstbyte + 1?
> + if (curbyte + r > lastbyte) r = lastbyte-curbyte;
> out_put(filebuf,r);
> + curbyte += r;
> + if (curbyte == lastbyte) break;
And here too, probably...
Bye,
Peter
--
Peter Conrad Tel: +49 6102 / 80 99 072
[ t]ivano Software GmbH Fax: +49 6102 / 80 99 071
Bahnhofstr. 18
63263 Neu-Isenburg