当目标端点位于 PAC 代理之后时,superagent 使用的 http-proxy-agent 无法上传文件

问题描述

当端点被 PAC 代理访问时,上传多部分/FormData 的 POST 端点失败。 'superagent' 使用 proxy-agent,后者又根据所使用的代理类型使用 http 代理。

端点服务报告多部分数据不完整。我通过设置 DEBUG=* 启用了调试日志,还在 http 代理服务器上捕获了日志,当我通过标准 http 代理引用代理详细信息而不是我提供 PAC 代理 URL 时,它报告了不同数量的写入字节。

我在 http-proxy-module 中确定了两行导致此问题。如果我在此源文件中的 callback() 函数中注释以下行,则我的所有 http 流量(包括 multipart/formdata)在 STANDARD HTTP PROXY、PAC PROXY 以及 NO PROXY 下都可以正常工作。 https://github.com/TooTallNate/node-http-proxy-agent/blob/master/src/agent.ts

req._header = null;
req._implicitHeader();

这些行在 callback() 中的位置在 'if' 条件内,该条件已经检查了 'req._header' 是否未定义。他们为什么需要隐式生成标题?我的测试表明它不会影响上述所有三种情况。

对这些行进行注释是否安全?

以下是我的示例代码

var request = require('superagent');
require('superagent-proxy')(request);
 
// HTTP,HTTPS,or SOCKS proxy to use
var proxy =  'pac+http://localhost:6080/examples/proxy.pac';


request.post('http://10.32.50.141/example/10058/upload')
  .accept('json')
  .set('Authorization','Bearer accesstoken')
  .attach('file','d:\\sample\sample.zip')   
  .field('id','10058')
.set('Content-disposition','form-data; name=file')
.set('enctype','multipart/form-data')
.proxy(proxy)
  .then(onresponse);
 
function onresponse (err,res) {
  if (err) {
    console.log(err);
  } else {
    console.log(res.status,res.headers);
    console.log(res.body);
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)