![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
require-header
Advanced tools
Express/connect middleware to handle errors where an expected header is missing
Express middleware to handle errors where an expected header is missing.
This library requires the following to run:
Install with npm:
npm install allow-methods
Load the library into your code with a require
call:
const requireHeader = require('require-header');
requireHeader
will return a middleware function that will error if the request does not set the given header. The error will have message
and status
properties which you can use.
It accepts two arguments. Firstly, the name of a header which is required:
requireHeader('User-Agent');
Secondly (optionally) a message which will be used in the error if the request message does not match:
requireHeader('User-Agent', 'User-Agent header is required');
const express = require('express');
const app = express();
// Only requests with a User-Agent header will continue
app.get(requireHeader('User-Agent'), () => { ... });
If you want to do something useful with the error, for example output a sensible JSON response, you will need to define an error handler for your application (after the route definition):
app.use((error, request, response, next) => {
response.status(error.status || 500).send({
message: error.message
});
});
const express = require('express');
const app = express();
// Require a User-Agent header across the entire application
app.use(requireHeader('User-Agent'));
The contributing guide is available here. All contributors must follow this library's code of conduct.
Licensed under the MIT license.
Copyright © 2015, Rowan Manning
FAQs
Express/connect middleware to handle errors where an expected header is missing
We found that require-header demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.