| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + "use strict"; | ||
| 2 | + function setHeaders(res, headers) { | ||
| 3 | + Object.keys(headers).forEach(key => { | ||
| 4 | + let value = headers[key]; | ||
| 5 | + if (value !== null) { | ||
| 6 | + res.setHeader(key, value); | ||
| 7 | + } | ||
| 8 | + }); | ||
| 9 | + } | ||
| 10 | + export default function () { | ||
| 11 | + return function (req, res, next) { | ||
| 12 | + setHeaders(res, { | ||
| 13 | + "X-Content-Type-Options": "nosniff" | ||
| 14 | + }); | ||
| 15 | + next(); | ||
| 16 | + } | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | "use strict"; | |
| 3 | 3 | import assert from "power-assert"; | |
| 4 | 4 | import connect from "connect" | |
| 5 | + import nosniff from "../../src/connect/nosniff"; | ||
| 5 | 6 | import hello from "../../src/connect/hello"; | |
| 6 | 7 | import http from "http"; | |
| 7 | 8 | import fetch from "node-fetch"; | |
@@ -10,6 +11,7 @@ describe("hello", function () { | |||
| 10 | 11 | var server; | |
| 11 | 12 | before(function (done) { | |
| 12 | 13 | var app = connect(); | |
| 14 | + app.use(nosniff()); | ||
| 13 | 15 | app.use(hello(responseText)); | |
| 14 | 16 | server = http.createServer(app).listen(3000, done); | |
| 15 | 17 | }); | |
@@ -23,4 +25,10 @@ describe("hello", function () { | |||
| 23 | 25 | assert.equal(text, responseText); | |
| 24 | 26 | }); | |
| 25 | 27 | }); | |
| 28 | + it("should return response has `X-Content-Type-Options` header", function () { | ||
| 29 | + return fetch("http://localhost:3000") | ||
| 30 | + .then(res => { | ||
| 31 | + assert.equal(res.headers.get("x-content-type-options"), "nosniff"); | ||
| 32 | + }) | ||
| 33 | + }); | ||
| 26 | 34 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments