【问题标题】:How to send HTTP error from http-proxy?如何从 http-proxy 发送 HTTP 错误?
【发布时间】:2017-06-07 11:07:39
【问题描述】:

是否可以在 http-proxy 中不将请求转发到服务器,而是立即返回带有一些错误代码的响应,例如 401 Unauthorized?
我需要分析请求正文,并且在某些情况下不将请求转发到服务器。

有可能吗?
还是http-proxy只能修改request和response,而request总是要转发给服务器?

【问题讨论】:

    标签: node.js http proxy node-http-proxy


    【解决方案1】:

    你可以试试这样:

    const server = http.createServer((req, res) => {
        if(/*your auth check*/){
            //return the 401 error
        }
        //auth check is passed, pass the request to the proxy
        proxy.web(req, res, { target: 'http://your.target' });
    });
    

    【讨论】:

      猜你喜欢
      • 2015-09-24
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2014-10-06
      • 2014-09-12
      相关资源
      最近更新 更多