【问题标题】:EPROTO error when trying to make a proxied HTTPS request with node.js 0.12尝试使用 node.js 0.12 发出代理 HTTPS 请求时出现 EPROTO 错误
【发布时间】:2015-08-02 08:55:07
【问题描述】:

在高层次上,我正在尝试使用Quota Guard Static 与来自 node.js 应用程序的 Heroku 应用程序的 IP 受限 API 对话。 API 有自己的 node.js 客户端实现,但在底层它只是一个 HTTP[S] api。该库在后台使用superagentsuperagent-proxy 来执行实际的HTTP[S] 请求。

在节点 0.10 中,一切正常。在节点 0.12 中,我看到如下错误:

Error: write EPROTO 140735203734288:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:782:
    at exports._errnoException (util.js:746:11)
    at WriteWrap.afterWrite (net.js:775:14)

在 io.js 2.02 中我看到:

Error: write EPROTO    at Object.exports._errnoException (util.js:844:11)

我尝试全局使用 SSLv3,如 answer 所示,但似乎没有效果。

代理 url 被指定为端口 9293 的 http URL。answer 建议使用端口 443,但由于代理提供程序对我来说是外部的,我无法更改它。

如何让代理请求在节点 0.12 中工作?

【问题讨论】:

  • 在端口 9293 上运行的服务不是 SSL。客户端问候响应一些其他数据,而不是服务器问候。因此,您会看到错误。
  • 代理是 HTTP 和 HTTPS 代理。它在端口 9293 上运行,并且由外部服务运行,所以我无法更改它。相同的代码在节点 0.10 上运行良好,但在节点 0.12 或 io 2.02 上不起作用

标签: node.js heroku https proxy openssl


【解决方案1】:

来自 QuotaGuard 的 Tim。这似乎是一个问题,体现在 superagent-proxy 用于 HTTPS 请求的 https-proxy-agent 中,导致向错误端口上的安全端点发出请求。

这是一个简单的示例,应该在端口 443 上连接到 Google。

var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');

// HTTP/HTTPS proxy to connect to
var proxy = process.env.QUOTAGUARDSTATIC_URL;
console.log('using proxy server %j', proxy);

// HTTPS endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'https://www.google.com/';
console.log('attempting to GET %j', endpoint);
var opts = url.parse(endpoint);

// create an instance of the `HttpsProxyAgent` class with the proxy server information
var agent = new HttpsProxyAgent(proxy);
opts.agent = agent;
https.get(opts, function (res) {
  console.log('"response" event!', res.headers);
  res.pipe(process.stdout);
});

实际请求是在端口 80 上发出的,因此 Google 拒绝了它。以下是 HTTP 标头:

["Proxy-Authorization: Basic Xgat28sa78saBZZ \r\n", "Host: www.google.com:80\r\n", "Connection: close\r\n"]

修补版本上的相同示例正确连接到端口 443 并且可以正常工作:

https://github.com/TooTallNate/node-https-proxy-agent/compare/master...timrwilliams:master

我怀疑上游发生了一些变化,导致错误的端口被传递到 https-proxy-agent,但这种类型的问题在Github issues 上讨论得更恰当。

快速解决方法是改用请求库:

var request = require('request');

var options = {
    proxy: process.env.QUOTAGUARDSTATIC_URL,
    url: 'https://www.google.com/',
    headers: {
        'User-Agent': 'node.js'
    }
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);

【讨论】:

    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 2018-04-02
    • 2020-07-21
    • 2019-09-05
    • 1970-01-01
    • 2018-09-23
    相关资源
    最近更新 更多