Commit 9c156004 authored by Antoor's avatar Antoor Committed by GitHub

Merge pull request #60 from antoor/v2.0-beta-ignore-https

v2.0-beta::Ignore HTTPS Certificate
parents 4b765483 c80a5526
...@@ -91,15 +91,17 @@ class Request { ...@@ -91,15 +91,17 @@ class Request {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
onRequest(event, opts) { onRequest(event, opts) {
logger.debug('onRequest::opts', opts);
logger.debug('onRequest::url', opts['url']);
logger.debug('onRequest::data', opts['data']);
superagent superagent
.post(opts['url']) .post(opts['url'])
.set('User-Agent', USER_AGENT) .set('User-Agent', USER_AGENT)
.proxy(APROXY_CONF['uri']) .proxy(APROXY_CONF['uri'])
.type('form') .type('form')
// 超时
.timeout(REQ_TIMEOUT) .timeout(REQ_TIMEOUT)
// 忽略HTTPS
.ignoreHTTPS(opts['ignoreHTTPS'])
.send(opts['data']) .send(opts['data'])
.parse((res, callback) => { .parse((res, callback) => {
this.parse(opts['tag_s'], opts['tag_e'], (chunk) => { this.parse(opts['tag_s'], opts['tag_e'], (chunk) => {
...@@ -145,6 +147,8 @@ class Request { ...@@ -145,6 +147,8 @@ class Request {
.type('form') .type('form')
// 设置超时会导致文件过大时写入出错 // 设置超时会导致文件过大时写入出错
// .timeout(timeout) // .timeout(timeout)
// 忽略HTTPS
.ignoreHTTPS(opts['ignoreHTTPS'])
.send(opts['data']) .send(opts['data'])
.pipe(through( .pipe(through(
(chunk) => { (chunk) => {
......
...@@ -589,6 +589,17 @@ Request.prototype.ca = function(cert){ ...@@ -589,6 +589,17 @@ Request.prototype.ca = function(cert){
return this; return this;
}; };
/**
* 忽略HTTPS证书
* @param {[type]} ignore [description]
* @return {[type]} [description]
*/
Request.prototype.ignoreHTTPS = function(ignore) {
this._ignoreHttps = !ignore;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = ignore ? '0' : undefined;
return this;
};
/** /**
* Return an http[s] request. * Return an http[s] request.
* *
...@@ -615,6 +626,10 @@ Request.prototype.request = function(){ ...@@ -615,6 +626,10 @@ Request.prototype.request = function(){
options.host = url.hostname; options.host = url.hostname;
options.ca = this._ca; options.ca = this._ca;
options.agent = this._agent; options.agent = this._agent;
// 卧槽,设置了这么多选项都没用,不过还好解决了,先留着吧。。
// options.requestCert = this._ignoreHttps;
// options.strictSSL = false;
// options.rejectUnhauthorized = false;
// initiate request // initiate request
var mod = exports.protocols[url.protocol]; var mod = exports.protocols[url.protocol];
......
...@@ -215,7 +215,8 @@ class Base { ...@@ -215,7 +215,8 @@ class Base {
data: opt['data'], data: opt['data'],
tag_s: opt['tag_s'], tag_s: opt['tag_s'],
tag_e: opt['tag_e'], tag_e: opt['tag_e'],
encode: this.__opts__['encode'] encode: this.__opts__['encode'],
ignoreHTTPS: (this.__opts__['otherConf'] || {})['ignore-https'] === 1
}); });
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment