Skip to content

Commit

Permalink
Fixing content-length response header value on 206 when specifying …
Browse files Browse the repository at this point in the history
…a negative offset from end
  • Loading branch information
avoidwork committed Oct 24, 2019
1 parent 3d658f3 commit 685f043
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function partial (req, res, buffered, status, headers) {
if ((options.start >= options.end || isNaN(options.start) || isNaN(options.end)) === false) {
req.range = options;
headers["content-range"] = `bytes ${options.start}-${options.end}/${size}`;
headers["content-length"] = `${options.end - options.start + 1}`;
headers["content-length"] = `${options.end - options.start + (options.end === size ? 0 : 1)}`;
status = res.statusCode = 206;
res.removeHeader("etag"); // Removing etag since this rep is incomplete
delete headers.etag;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woodland",
"version": "9.1.0",
"version": "9.1.1",
"description": "Lightweight HTTP/HTTP2 router with automatic `Allow` & `CORS` headers",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe("Valid Requests", function () {
return tinyhttptest({url: "http://localhost:8001/", headers: {range: "bytes=-5"}})
.expectStatus(206)
.expectHeader("content-range", /^bytes 7-12\/12$/)
.expectHeader("content-length", 6)
.expectHeader("content-length", 5)
.expectBody(/^orld!$/)
.end();
});
Expand Down
2 changes: 1 addition & 1 deletion test/test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe("Valid Requests (HTTP2)", function () {
return tinyhttptest({http2: true, url: "https://localhost:8002/", headers: {range: "bytes=-5"}})
.expectStatus(206)
.expectHeader("content-range", /^bytes 7-12\/12$/)
.expectHeader("content-length", 6)
.expectHeader("content-length", 5)
.expectBody(/^orld!$/)
.end();
});
Expand Down

0 comments on commit 685f043

Please sign in to comment.