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 {
* @return {[type]} [description]
*/
onRequest(event, opts) {
logger.debug('onRequest::opts', opts);
logger.debug('onRequest::url', opts['url']);
logger.debug('onRequest::data', opts['data']);
superagent
.post(opts['url'])
.set('User-Agent', USER_AGENT)
.proxy(APROXY_CONF['uri'])
.type('form')
// 超时
.timeout(REQ_TIMEOUT)
// 忽略HTTPS
.ignoreHTTPS(opts['ignoreHTTPS'])
.send(opts['data'])
.parse((res, callback) => {
this.parse(opts['tag_s'], opts['tag_e'], (chunk) => {
......@@ -145,6 +147,8 @@ class Request {
.type('form')
// 设置超时会导致文件过大时写入出错
// .timeout(timeout)
// 忽略HTTPS
.ignoreHTTPS(opts['ignoreHTTPS'])
.send(opts['data'])
.pipe(through(
(chunk) => {
......
......@@ -589,6 +589,17 @@ Request.prototype.ca = function(cert){
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.
*
......@@ -615,6 +626,10 @@ Request.prototype.request = function(){
options.host = url.hostname;
options.ca = this._ca;
options.agent = this._agent;
// 卧槽,设置了这么多选项都没用,不过还好解决了,先留着吧。。
// options.requestCert = this._ignoreHttps;
// options.strictSSL = false;
// options.rejectUnhauthorized = false;
// initiate request
var mod = exports.protocols[url.protocol];
......
......@@ -215,7 +215,8 @@ class Base {
data: opt['data'],
tag_s: opt['tag_s'],
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