Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkHeader() failing #85

Closed
brandonscript opened this issue Apr 9, 2014 · 2 comments
Closed

checkHeader() failing #85

brandonscript opened this issue Apr 9, 2014 · 2 comments

Comments

@brandonscript
Copy link
Contributor

req.checkHeader('Authorization', 'Authorization header cannot be empty).notEmpty();

This will fail with exception:

TypeError: Cannot read property 'Authorization' of undefined
    at ~/node_modules/express-validator/lib/express_validator.js:173:33
    at ~/node_modules/express-validator/lib/express_validator.js:81:21
    at Array.map (native)
    at IncomingMessage.checkHeader (~/node_modules/express-validator/lib/express_validator.js:79:13)
    at app.get.res.statusCode (~/users.js:33:6)
    at callbacks (~/node_modules/express/lib/router/index.js:164:37)
    at param (~/node_modules/express/lib/router/index.js:138:11)
    at param (~/node_modules/express/lib/router/index.js:135:11)
    at pass (~/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (~/node_modules/express/lib/router/index.js:173:5)
@brandonscript
Copy link
Contributor Author

So looks like the original bug still wasn't fixed? Or maybe the npm version is old?

Either way, replacing this with req fixed the problem:

req.checkHeader = checkParam(req, function(header) {
        var toCheck;

        if (header === 'referrer' || header === 'referer') {
          toCheck = req.headers.referer;
        } else {
          toCheck = req.headers[header];
        }
        return toCheck || '';
 });

@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant