Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Aug 8, 2019
1 parent 7077ae0 commit f48b0f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const http = require("http"),
regex = require(path.join(__dirname, "regex.js")),
request = require(path.join(__dirname, "request.js")),
{URL} = require("url"),
all = "*";
all = "*",
delimiter = ":";

function clone (arg) {
return JSON.parse(JSON.stringify(arg));
Expand Down Expand Up @@ -209,6 +210,7 @@ function writeHead (res, status, headers) {
module.exports = {
all,
clone,
delimiter,
each,
http2Normalize,
http2Send,
Expand Down
11 changes: 5 additions & 6 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ const path = require("path"),
fifo = require("tiny-fifo"),
http = require("http"),
precise = require("precise"),
methods = http.METHODS,
{METHODS} = http,
Base = require(path.join(__dirname, "base.js")),
dtrace = require(path.join(__dirname, "dtrace.js")),
{all, clone, each, http2Normalize, http2Send, next, ms, params, parse, partial, pipeable, last, reduce, wrapped, writeHead} = require(path.join(__dirname, "utility.js")),
delimiter = ":";
{all, clone, delimiter, each, http2Normalize, http2Send, next, ms, params, parse, partial, pipeable, last, reduce, wrapped, writeHead} = require(path.join(__dirname, "utility.js"));

class Woodland extends Base {
constructor (defaultHeaders, cacheSize, http2, cacheTTL, dtp, origins) {
Expand Down Expand Up @@ -209,7 +208,7 @@ class Woodland extends Base {
req.parsed = parsed;
req.allow = this.allows(req.parsed.pathname);
req.body = "";
req.cors = req.headers.origin !== void 0 && (this.origins.includes("*") || this.origins.includes(req.headers.origin));
req.cors = req.headers.origin !== void 0 && (this.origins.includes(all) || this.origins.includes(req.headers.origin));
req.host = req.parsed.hostname;
req.ip = remotes[remotes.length - 1];
req.params = {};
Expand Down Expand Up @@ -400,12 +399,12 @@ class Woodland extends Base {
use (rpath, ...fn) {
if (typeof rpath === "function") {
fn = [rpath, ...fn];
rpath = "/.*";
rpath = `/.${all}`;
}

const method = typeof fn[fn.length - 1] === "string" ? fn.pop().toUpperCase() : "GET";

if (method !== all && methods.includes(method) === false) {
if (method !== all && METHODS.includes(method) === false) {
throw new TypeError("Invalid HTTP method");
}

Expand Down

0 comments on commit f48b0f7

Please sign in to comment.