Skip to content

Commit

Permalink
Updating woodland router, fixing 206 tests, returning 204 response fo…
Browse files Browse the repository at this point in the history
…r `OPTIONS` requests routing through `keymaster()`
  • Loading branch information
avoidwork committed Oct 24, 2019
1 parent ce00d7d commit 78828a3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require("path"),
fs = require("fs"),
{STATUS_CODES} = require("http"),
retsu = require("retsu"),
coerce = require("tiny-coerce"),
mime = require("mimetype"),
Expand Down Expand Up @@ -137,7 +138,9 @@ function payload (req, res, next) {
function keymaster (req, res) {
// No authentication, or it's already happened
if (req.protect === false || req.protectAsync === false || (req.session !== void 0 && req.isAuthenticated())) { // eslint-disable-line no-extra-parens
if (typeof req.last === "function") {
if (req.method === "OPTIONS" && req.allow.includes("GET")) {
res.send(STATUS_CODES[204], 204);
} else if (typeof req.last === "function") {
req.last(req, res);
} else {
res.error(404);
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"tiny-merge": "^1.0.0",
"tiny-uuid4": "^1.0.1",
"tiny-xml": "^2.0.0",
"woodland": "^9.1.0",
"woodland": "^9.1.1",
"yamljs": "^0.3.0",
"yargs": "^14.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion test/valid_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("Valid", function () {
it("GET / (206 / 'Partial response - bytes=-5')", function () {
return tinyhttptest({url: "http://localhost:" + port + "/", headers: {range: "bytes=-5"}})
.expectStatus(206)
.expectHeader("content-range", /^bytes 285-290\/290$/)
.expectHeader("content-range", /^bytes 286-290\/290$/)
.expectHeader("content-length", undefined)
.expectBody(/^:200}$/)
.end();
Expand Down
2 changes: 1 addition & 1 deletion test/valid_test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Valid (HTTP2)", function () {
it("GET / (206 / 'Partial response - bytes=-5')", function () {
return tinyhttptest({http2: true, url: "https://localhost:" + port + "/", headers: {range: "bytes=-5"}})
.expectStatus(206)
.expectHeader("content-range", /^bytes 285-290\/290$/)
.expectHeader("content-range", /^bytes 286-290\/290$/)
.expectHeader("content-length", undefined)
.expectBody(/^:200}$/)
.end();
Expand Down

0 comments on commit 78828a3

Please sign in to comment.