NodeJS server "swallows" header field

I am creating a proxy server with nodejs. It works fine unless a CSRF token is required.

When making a request with the request plugin (https://github.com/request/request), the response object's header won#t continue x-csrf-token, even tho the req.header object made a "Fetch".

Any ideas?

app.use("/", function (req, res, next) {
    options = {
    'url': sDestination + req.url,
        'ca': cas,
        'jar': true,//jar,
        'strictSSL': true,
        'headers': {
    accept: '*/*'
        }
    };
    request(options, function (err, response, body) {
    if (err) { 
     console.error(err);
     }
    else {
     if (typeof req.headers['x-csrf-token'] === "string") {
    console.log("#1 " + (typeof req.headers['x-csrf-token'])); // string
     console.log("#2 " + (req.headers['x-csrf-token'])); // "Fetch"
     console.log("#3 " + (typeof response.headers['x-csrf-token'])); // undefined
     }
     }
    }).pipe(res);
}

Try to also add this request header:

"X-Requested-With": "XMLHttpRequest"

It could do the trick in some (probably not all) cases


这样做的工作:

req.pipe(request(options, function (err, response, body) {
    if (err) {
        return console.error('upload failed:', err);
    }
}), {end: (req.method === "GET" ? true : false)}).pipe(res);
链接地址: http://www.djcxy.com/p/89108.html

上一篇: 从nodejs到Django的http请求

下一篇: NodeJS服务器“吞服”标题字段