-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
167 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
'use strict'; | ||
const validate = require('./lib/validate'); | ||
|
||
module.exports = function networkErrorLogging(options){ | ||
module.exports = function networkErrorLogging(options) { | ||
validate(options); | ||
|
||
const headerValue = JSON.stringify(options); | ||
|
||
return function networkErrorLogging(req, res, next){ | ||
return function networkErrorLogging(req, res, next) { | ||
res.setHeader('NEL', headerValue); | ||
return next(); | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
'use strict'; | ||
|
||
function isObject(value){ | ||
function isObject(value) { | ||
return Object.prototype.toString.call(value) === '[object Object]'; | ||
} | ||
|
||
module.exports = function validate(options){ | ||
if(!isObject(options)){ | ||
module.exports = function validate(options) { | ||
if(!isObject(options)) { | ||
throw new Error('NEL must be called with an object argument.'); | ||
} | ||
if((options.report_to) !== undefined && typeof(options.report_to) !== 'string'){ | ||
if((options.report_to) !== undefined && typeof(options.report_to) !== 'string') { | ||
throw new TypeError('The `report_to` parameter must be a string if set.'); | ||
} | ||
if(options.include_subdomains && typeof(options.include_subdomains) !== 'boolean'){ | ||
if(options.include_subdomains && typeof(options.include_subdomains) !== 'boolean') { | ||
throw new Error('The `include_subdomains` parameter must be a boolean if set.'); | ||
} | ||
if(!options.max_age){ | ||
if(!options.max_age) { | ||
throw new Error('The `max_age` parameter is required.'); | ||
} | ||
if(typeof(options.max_age) !== 'number' || options.max_age <= 0){ | ||
if(typeof(options.max_age) !== 'number' || options.max_age <= 0) { | ||
throw new Error('The `max_age` parameter must be a positive integer.'); | ||
} | ||
if(options.success_fraction && (typeof(options.success_fraction) !== 'number' || options.success_fraction < 0 || options.success_fraction > 1)){ | ||
if(options.success_fraction && (typeof(options.success_fraction) !== 'number' || options.success_fraction < 0 || options.success_fraction > 1)) { | ||
throw new Error('The `success_fraction` parameter must be a positive integer between 0.0 and 1.0.'); | ||
} | ||
if(options.failure_fraction && (typeof(options.failure_fraction) !== 'number' || options.failure_fraction < 0 || options.failure_fraction > 1)){ | ||
if(options.failure_fraction && (typeof(options.failure_fraction) !== 'number' || options.failure_fraction < 0 || options.failure_fraction > 1)) { | ||
throw new Error('The `failure_fraction` parameter must be a positive integer between 0.0 and 1.0.'); | ||
} | ||
if(options.request_headers && !Array.isArray(options.request_headers)){ | ||
if(options.request_headers && !Array.isArray(options.request_headers)) { | ||
throw new Error('The `request_headers` parameter must be an array of strings'); | ||
} | ||
if(options.request_headers && Array.isArray(options.request_headers)){ | ||
for(const header of options.request_headers){ | ||
if(typeof(header) !== 'string'){ | ||
if(options.request_headers && Array.isArray(options.request_headers)) { | ||
for(const header of options.request_headers) { | ||
if(typeof(header) !== 'string') { | ||
throw new TypeError('The `request_headers` parameter must only contain strings.'); | ||
} | ||
} | ||
} | ||
if(options.response_headers && !Array.isArray(options.response_headers)){ | ||
if(options.response_headers && !Array.isArray(options.response_headers)) { | ||
throw new Error('The `response_headers` parameter must be an array of strings'); | ||
} | ||
if(options.response_headers && Array.isArray(options.response_headers)){ | ||
for(const header of options.response_headers){ | ||
if(typeof(header) !== 'string'){ | ||
if(options.response_headers && Array.isArray(options.response_headers)) { | ||
for(const header of options.response_headers) { | ||
if(typeof(header) !== 'string') { | ||
throw new TypeError('The `response_headers` parameter must only contain strings.'); | ||
} | ||
} | ||
} | ||
}; | ||
}; |
Oops, something went wrong.