Skip to content

Commit

Permalink
Updating sample & test files to use new helper functions, fixing `res…
Browse files Browse the repository at this point in the history
….send()` for `http1` requests
  • Loading branch information
avoidwork committed Nov 28, 2017
1 parent 56c83a7 commit 91d0122
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Woodland {

res.send = (...args) => this.http2Send(req, res, ...args);
} else {
res.send = (body, status, headers) => {
res.send = (body, status = 200, headers) => {
res.statusCode = status;
res.writeHead(status, headers);
res.end(body);
Expand Down Expand Up @@ -155,7 +155,7 @@ class Woodland {
http2Send (req, res, body, status = 200, headers = null) {
if (res.writable) {
const output = {":status": status},
empty = status === 204 || status === 304;
empty = regex.isHead.test(req.method) || status === 204 || status === 304;

each(Object.keys(res._headers).filter(i => invalidHttp2Headers.test(i) === false), i => {
output[i] = res._headers[i];
Expand Down
6 changes: 3 additions & 3 deletions sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const http = require("http"),
router = require("./index")({defaultHeaders: {"Cache-Control": "no-cache", "Content-Type": "text/plain"}});

router.use("/", (req, res) => res.end("Hello World!"));
router.use("/", (req, res) => res.end("Make a GET request to retrieve the representation"), "options");
router.use("/:user", (req, res) => res.end("Hello " + req.params.user + "!"));
router.use("/", (req, res) => res.send("Hello World!"));
router.use("/", (req, res) => res.send("Make a GET request to retrieve the representation"), "options");
router.use("/:user", (req, res) => res.send("Hello " + req.params.user + "!"));
http.createServer(router.route).listen(8000);
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const http = require("http"),
}
});

router.onconnect = (req, res) => res.setHeader("x-onconnect", "true");
router.use("/", (req, res) => res.end(req.method !== "OPTIONS" ? "Hello World!" : ""));
router.use("/echo/:echo", (req, res) => res.end(req.params.echo));
router.use("/echo/:echo", (req, res) => res.end("The entity will be echoed back to you"), "OPTIONS");
router.onconnect = (req, res) => res.header("x-onconnect", "true");
router.use("/", (req, res) => res.send(req.method !== "OPTIONS" ? "Hello World!" : ""));
router.use("/echo/:echo", (req, res) => res.send(req.params.echo));
router.use("/echo/:echo", (req, res) => res.send("The entity will be echoed back to you"), "OPTIONS");

http.createServer(router.route).listen(8001);

Expand Down

0 comments on commit 91d0122

Please sign in to comment.