Re: Range:-Header support
Andreas Kotes <[email protected]> Thu, 13 Jun 2002 14:54:04 +0200
| Newsgroups | gmane.comp.djb.publicfile |
|---|---|
| Message-ID | <[email protected]> |
Hi Peter! * Peter Conrad <[email protected]> [20020613 13:48]: > 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. well, I just needed it for a https IPv6 site which keeps dropping connections while transfering large files .. not too nice over a 144kbit link. the owner of that site insists on using publicfile, so I gave him this patch - I just didn't want to keep it all for myself, so I sent it to the list .. > > + 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. as it says: Strange, but true... wget sends HTTP/1.0 requests with Range:-header and can handle this purrrfectly the way this is patched. > > + 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. uh, right. > > + 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? ups, I suppose you're right. forgot that byte 0 counts in all of these cases.. works with my wget nonetheless. > > + if (curbyte + r > lastbyte) r = lastbyte-curbyte; > > out_put(filebuf,r); > > + curbyte += r; > > + if (curbyte == lastbyte) break; > > And here too, probably... ..... well: to be honest - I flinched quite some times while looking at the source of publicfile as well as wget, and decided to go for an ugly hack which satisfies my needs (and nothing more!) .. this one does, I can resume files when downloading. somebody else might find this useful too, now it is in the mailinglist archives - and somebody could enhance this and put it right. what totally killed my enthusiasm were the use of chunked responses ALWAYS when HTTP/1.1 is used, so I limited the Range support to HTTP/1.0, which is the only way wget tries to use it anyway .. so, ultrarudimentary. another 'works for me' hack like so many out there. Count P.S: publicfile doesn't fit my needs as well as boa (select-based and MUCH more performant withmany hits) or fnord (with CGI support), so I most likely won't throw any time on this ... -- Andreas Kotes - ICQ: 3741366 - The views expressed herein are (only) mine. Look to the future, because that is where you'll spend the rest of your life. -- George Burnsh -- OpenPGP Key 0x8F94C228