有一种快速检查的方法,如果请求处于状态重定向(302),我使用(req,res)我使用以下?
var http = require('http'),
httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({});
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('X-Special-Proxy-Header', 'foobar');
});
proxy.on('proxyRes', function (proxyRes, req, res) {
console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
});
https://github.com/nodejitsu/node-http-proxy
最佳答案
也许我不明白这个问题,但你可以很容易地做到以下几点:
proxy.on('proxyRes', function(proxyRes, req, res) {
if (proxyRes.statusCode === 301 || proxyRes.statusCode === 302) {
proxyRes.headers['location'] = fixUrl(proxyRes.headers['location']);
}
});
其中
fixUrl()
在location
响应头上执行任何必要的转换。关于node.js - 检查请求是否处于重定向状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32127512/