visionmedia/express — Issue #963: Can't access some headers from middleware
Author: RexMorgan
Created: 2012-01-14 09:22:09+00:00
State: open

I created a function to echo back a specific HTTP from request to response. Code looks like this:

```javascript
exports.correlate = function (req, res, next) {
var correlationId = res.header('X-Correlation-Id');
console.log('correlationId: ' + correlationId);
if (correlationId) {
console.log('setting correlationId on response header');
res.setHeader('X-Correlation-Id', correlationId);
}
next();
};
```

I'm setting up the middleware like this:
```javascript
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(mid.correlate);
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
```

However the header is not in the request at the time my middleware runs, even though firebug/chrome say that the data is being sent up. When I put the code to get the header in the route, then it works. I was just hoping this could be called for all of my routes. It's important to note that some headers are listed.