简体   繁体   English

尝试使用node.js 0.12代理HTTPS请求时出现EPROTO错误

[英]EPROTO error when trying to make a proxied HTTPS request with node.js 0.12

At a high level, I am trying to use Quota Guard Static to talk to an IP limited API from a Heroku app from a node.js application. 在较高的级别上,我尝试使用Quota Guard Static与来自node.js应用程序的Heroku应用程序与IP受限的API进行通信。 The API has its own node.js client implementation, but underneath the covers it's just an HTTP[S] api. 该API具有自己的node.js客户端实现,但在幕后仅是HTTP [S] api。 The library uses superagent and superagent-proxy underneath the covers to do the actual HTTP[S] requests. 该库在幕后使用了superagentsuperagent-proxy来执行实际的HTTP [S]请求。

In node 0.10, all worked fine. 在节点0.10中,一切正常。 In node 0.12, I see errors like: 在节点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)

In io.js 2.02 I see: 在io.js 2.02中,我看到了:

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

I tried globally using SSLv3 as shown in this answer , but it seemed to have no effect. 如该答案所示,我在全球范围内尝试使用SSLv3,但这似乎没有任何效果。

The proxy url is specified as an http URL with port 9293. This answer suggested using port 443, but since the proxy provider is external to me, I cannot change it. 代理URL被指定为带有端口9293的http URL。建议使用端口443 回答问题 ,但是由于代理提供程序对我来说是外部的,因此我无法更改它。

How might I get the proxied request to work in node 0.12? 如何获得代理请求以在节点0.12中工作?

Tim here from QuotaGuard. Tim来自QuotaGuard。 This seems to be an issue manifesting itself in the https-proxy-agent used by superagent-proxy for HTTPS requests causing the request to be made to the secure endpoint on the wrong port. 这似乎是一个问题,这在superagent-proxy用于HTTPS请求的https-proxy-agent中表现出来,导致对错误端口上的安全端点的请求。

This is a simple example that should connect to Google on port 443. 这是一个简单的示例,应该通过端口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);
});

The actual request is being made on port 80 so Google is rejecting it. 实际的请求是在端口80上发出的,因此Google拒绝了该请求。 Here are the HTTP headers: 这是HTTP标头:

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

The same example on a patched version correctly connects to port 443 and works: 修补版本上的相同示例正确连接到端口443,并且可以正常工作:

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

I suspect something has changed upstream which is causing the wrong port to be passed to https-proxy-agent but this type of problem is more appropriately discussed on Github issues . 我怀疑上游发生了一些变化,这导致将错误的端口传递给https-proxy-agent,但是在Github问题上更适当地讨论了这种类型的问题。

A quick fix would be switching to use the request library instead: 一个快速解决方案是切换为使用请求库:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM