Working Skelleton
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
*.log
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4.2"
|
||||
- "5"
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Evan Hahn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
DNS prefetch control header for Express
|
||||
=======================================
|
||||
[](https://travis-ci.org/helmetjs/dns-prefetch-control)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
[_Looking for a changelog?_](https://github.com/helmetjs/helmet/blob/master/HISTORY.md)
|
||||
|
||||
This middleware lets you set the `X-DNS-Prefetch-Control` to control browsers' DNS prefetching. Read more about it [on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Controlling_DNS_prefetching) and [on Chromium's docs](https://dev.chromium.org/developers/design-documents/dns-prefetching).
|
||||
|
||||
Usage:
|
||||
|
||||
```js
|
||||
var dnsPrefetchControl = require('dns-prefetch-control')
|
||||
|
||||
// Set X-DNS-Prefetch-Control: off
|
||||
app.use(dnsPrefetchControl())
|
||||
|
||||
// Set X-DNS-Prefetch-Control: off
|
||||
app.use(dnsPrefetchControl({ allow: false }))
|
||||
|
||||
// Set X-DNS-Prefetch-Control: on
|
||||
app.use(dnsPrefetchControl({ allow: true }))
|
||||
```
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
module.exports = function dnsPrefetchControl (options) {
|
||||
if (options && options.allow) {
|
||||
return function dnsPrefetchControl (req, res, next) {
|
||||
res.setHeader('X-DNS-Prefetch-Control', 'on')
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
return function dnsPrefetchControl (req, res, next) {
|
||||
res.setHeader('X-DNS-Prefetch-Control', 'off')
|
||||
next()
|
||||
}
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "dns-prefetch-control@0.1.0",
|
||||
"scope": null,
|
||||
"escapedName": "dns-prefetch-control",
|
||||
"name": "dns-prefetch-control",
|
||||
"rawSpec": "0.1.0",
|
||||
"spec": "0.1.0",
|
||||
"type": "version"
|
||||
},
|
||||
"/Users/gerrit/Documents/dev/nodejs/rentfor.camp/html/RentForCamp/node_modules/helmet"
|
||||
]
|
||||
],
|
||||
"_from": "dns-prefetch-control@0.1.0",
|
||||
"_id": "dns-prefetch-control@0.1.0",
|
||||
"_inCache": true,
|
||||
"_location": "/dns-prefetch-control",
|
||||
"_nodeVersion": "5.3.0",
|
||||
"_npmUser": {
|
||||
"name": "evanhahn",
|
||||
"email": "me@evanhahn.com"
|
||||
},
|
||||
"_npmVersion": "3.5.3",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "dns-prefetch-control@0.1.0",
|
||||
"scope": null,
|
||||
"escapedName": "dns-prefetch-control",
|
||||
"name": "dns-prefetch-control",
|
||||
"rawSpec": "0.1.0",
|
||||
"spec": "0.1.0",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/helmet"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/dns-prefetch-control/-/dns-prefetch-control-0.1.0.tgz",
|
||||
"_shasum": "60ddb457774e178f1f9415f0cabb0e85b0b300b2",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "dns-prefetch-control@0.1.0",
|
||||
"_where": "/Users/gerrit/Documents/dev/nodejs/rentfor.camp/html/RentForCamp/node_modules/helmet",
|
||||
"author": {
|
||||
"name": "Evan Hahn",
|
||||
"email": "me@evanhahn.com",
|
||||
"url": "http://evanhahn.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/helmetjs/dns-prefetch-control/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Middleware to set X-DNS-Prefetch-Control header.",
|
||||
"devDependencies": {
|
||||
"connect": "^3.4.0",
|
||||
"mocha": "^2.3.4",
|
||||
"standard": "^5.4.1",
|
||||
"supertest": "^1.1.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "60ddb457774e178f1f9415f0cabb0e85b0b300b2",
|
||||
"tarball": "https://registry.npmjs.org/dns-prefetch-control/-/dns-prefetch-control-0.1.0.tgz"
|
||||
},
|
||||
"gitHead": "c7684311d1766387dbbc517abb2e9cfbb55e7717",
|
||||
"homepage": "https://github.com/helmetjs/dns-prefetch-control#readme",
|
||||
"keywords": [
|
||||
"helmet",
|
||||
"security",
|
||||
"express",
|
||||
"connect",
|
||||
"x-dns-prefetch-control",
|
||||
"dns",
|
||||
"prefetch"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "evanhahn",
|
||||
"email": "me@evanhahn.com"
|
||||
}
|
||||
],
|
||||
"name": "dns-prefetch-control",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/helmetjs/dns-prefetch-control.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && mocha"
|
||||
},
|
||||
"standard": {
|
||||
"global": [
|
||||
"beforeEach",
|
||||
"describe",
|
||||
"it"
|
||||
]
|
||||
},
|
||||
"version": "0.1.0"
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
var dnsPrefetchControl = require('..')
|
||||
|
||||
var assert = require('assert')
|
||||
var connect = require('connect')
|
||||
var request = require('supertest')
|
||||
|
||||
describe('dnsPrefetchControl', function () {
|
||||
function use () {
|
||||
var result = connect()
|
||||
result.use(dnsPrefetchControl.apply(null, arguments))
|
||||
result.use(function (req, res) {
|
||||
res.end('Hello world!')
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
it('continues onto the following middleware', function (done) {
|
||||
var app = use()
|
||||
|
||||
request(app).get('/')
|
||||
.expect('Hello world!')
|
||||
.end(done)
|
||||
})
|
||||
|
||||
it('sets the header to "off" by default', function (done) {
|
||||
var app = use()
|
||||
|
||||
request(app).get('/')
|
||||
.expect('X-DNS-Prefetch-Control', 'off')
|
||||
.end(done)
|
||||
})
|
||||
|
||||
it('can set header to "off" with configuration', function (done) {
|
||||
var app = use({ allow: false })
|
||||
|
||||
request(app).get('/')
|
||||
.expect('X-DNS-Prefetch-Control', 'off')
|
||||
.end(done)
|
||||
})
|
||||
|
||||
it('can set header to "on" with configuration', function (done) {
|
||||
var app = use({ allow: true })
|
||||
|
||||
request(app).get('/')
|
||||
.expect('X-DNS-Prefetch-Control', 'on')
|
||||
.end(done)
|
||||
})
|
||||
|
||||
it('names its function and middleware', function () {
|
||||
assert.equal(dnsPrefetchControl.name, 'dnsPrefetchControl')
|
||||
assert.equal(dnsPrefetchControl().name, 'dnsPrefetchControl')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user