httpd: fix rane requests
we gave wrong content-length in range requests. r->stop - r->start is wrong because r->stop is the byte offset of the *last* byte, not the *next* byte after the last.
This commit is contained in:
parent
e53ece53ed
commit
029a8087a3
1 changed files with 7 additions and 3 deletions
|
@ -127,7 +127,7 @@ sendfd(HConnect *c, int fd, Dir *dir, HContent *type, HContent *enc)
|
||||||
hprint(hout, "Content-Length: %lld\r\n", length);
|
hprint(hout, "Content-Length: %lld\r\n", length);
|
||||||
else if(r->next == nil){
|
else if(r->next == nil){
|
||||||
hprint(hout, "Content-Range: bytes %ld-%ld/%lld\r\n", r->start, r->stop, length);
|
hprint(hout, "Content-Range: bytes %ld-%ld/%lld\r\n", r->start, r->stop, length);
|
||||||
hprint(hout, "Content-Length: %ld\r\n", r->stop - r->start);
|
hprint(hout, "Content-Length: %ld\r\n", 1 + r->stop - r->start);
|
||||||
}else{
|
}else{
|
||||||
multir = 1;
|
multir = 1;
|
||||||
boundary = hmkmimeboundary(c);
|
boundary = hmkmimeboundary(c);
|
||||||
|
@ -196,7 +196,7 @@ sendfd(HConnect *c, int fd, Dir *dir, HContent *type, HContent *enc)
|
||||||
hprint(hout, "\r\n--%s\r\n", boundary);
|
hprint(hout, "\r\n--%s\r\n", boundary);
|
||||||
printtype(hout, type, enc);
|
printtype(hout, type, enc);
|
||||||
hprint(hout, "Content-Range: bytes %ld-%ld/%lld\r\n", r->start, r->stop, length);
|
hprint(hout, "Content-Range: bytes %ld-%ld/%lld\r\n", r->start, r->stop, length);
|
||||||
hprint(hout, "Content-Length: %ld\r\n", r->stop - r->start);
|
hprint(hout, "Content-Length: %ld\r\n", 1 + r->stop - r->start);
|
||||||
hprint(hout, "\r\n");
|
hprint(hout, "\r\n");
|
||||||
}
|
}
|
||||||
hflush(hout);
|
hflush(hout);
|
||||||
|
@ -205,7 +205,7 @@ sendfd(HConnect *c, int fd, Dir *dir, HContent *type, HContent *enc)
|
||||||
ok = -1;
|
ok = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for(tr = r->stop - r->start + 1; tr; tr -= n){
|
for(tr = 1 + r->stop - r->start; tr; tr -= n){
|
||||||
n = tr;
|
n = tr;
|
||||||
if(n > HBufSize)
|
if(n > HBufSize)
|
||||||
n = HBufSize;
|
n = HBufSize;
|
||||||
|
@ -418,6 +418,10 @@ fixrange(HRange *h, long length)
|
||||||
rr = nil;
|
rr = nil;
|
||||||
for(r = h; r != nil; r = r->next){
|
for(r = h; r != nil; r = r->next){
|
||||||
if(r->suffix){
|
if(r->suffix){
|
||||||
|
/*
|
||||||
|
* for suffix, r->stop is a byte *length*
|
||||||
|
* not the byte *offset* of last byte!
|
||||||
|
*/
|
||||||
r->start = length - r->stop;
|
r->start = length - r->stop;
|
||||||
if(r->start >= length)
|
if(r->start >= length)
|
||||||
r->start = 0;
|
r->start = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue