使用http-proxy-middleware报错

启动是没有问题的:

[HPM] GET /v2/goods/goods_summary?access_token=b1c9aeb1dce5eb26672a2d72041276b3&t=1500448519850 -> https://api.dinghuo123.com

一旦向后台请求数据,就报错:

_http_outgoing.js:366
    throw new TypeError(
    ^

TypeError: Header name must be a valid HTTP Token ["cache -control"]
    at ServerResponse.setHeader (_http_outgoing.js:366:11)
    at setHeader (/Users/spider/Work/ydh/ircloud-ydh-agent/node_modules/http-proxy/lib/http-proxy/passes/web-outgoing.js:94:15)
    at /Users/spider/Work/ydh/ircloud-ydh-agent/node_modules/http-proxy/lib/http-proxy/passes/web-outgoing.js:116:7
    at Array.forEach (native)
    at Array.writeHeaders (/Users/spider/Work/ydh/ircloud-ydh-agent/node_modules/http-proxy/lib/http-proxy/passes/web-outgoing.js:111:35)
    at ClientRequest.<anonymous> (/Users/spider/Work/ydh/ircloud-ydh-agent/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:166:20)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:191:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:522:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
    at TLSSocket.socketOnData (_http_client.js:411:20)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at TLSSocket.Readable.push (_stream_readable.js:134:10)
    at TLSWrap.onread (net.js:563:20)
阅读 4.2k
1 个回答

后台返回response Header不规范,cache -control中间带一个空格。node.js的错误处理兼容得不够好,将头部的空格认定为非法的字符,直接throw error。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏