node.js - an Issue when using a simple express request -


i'm facing stupid issue express , nodejs,

i have simple code give the ability check if headers exist or not in request :

var express = require('express');  var app = express();  app.get('/', function (req, res) {      if (req.headers["x-caller-id"]) {         res.status(200).send('found');     } else {         res.status(400).send('header missing');         } });  app.listen(3000); 

everything works fine, when use request, doesn't show i'm looking for. should show found doesn't

enter image description here

i got strange thing when take off referer or user-agent header works fine, when add both of them request, x-caller-id disappears

you can use req.get('headername') header content.

var express = require('express');  var app = express();  app.get('/', function (req, res) {      if (req.get("x-caller-id")) {         res.status(200).send('found');     } else {         res.status(400).send('header missing');         } });  app.listen(3000); 

source: http://expressjs.com/en/api.html#req.get


Comments