Is it possible to set request headers for img src attributes, using node-http-proxy? I'm getting a 401 error because my server is expecting a header property: value for every request, incuding img src attributes. I'm setting the headers for all requests in the index.js file but headers are not being set for img requests. I'm trying to check if the request is for an image and then set the header before sending the request using node-http-proxy.
// index.js -- works for non img src requests
if ($rootScope.foobar_header !== undefined) {
headersGetter()['X-Special-Proxy-Header'] = $rootScope.foobar_header;
}
if (data) {
return angular.toJson(data);
}
function proxyMiddleware(req, res, next) {
if (req.url.indexOf(proxyApiPrefix) !== -1) {
if (req.url.indexOf(proxyImgPrefix) !== -1) {
console.log('img request');
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('X-Special-Proxy-Header', 'foobar_header');
});
}
proxy.web(req, res);
} else {
next();
}
}