This commit is contained in:
buddy
2022-07-19 09:45:45 +00:00
parent 3d8cca58dd
commit 52fae1a695
8 changed files with 99 additions and 92 deletions

View File

@@ -17,7 +17,8 @@ exports.FetchStream = FetchStream;
exports.CookieJar = CookieJar;
exports.fetchUrl = fetchUrl;
function FetchStream(url, options) {
function FetchStream(url, options)
{
Stream.call(this);
options = options || {};
@@ -172,7 +173,7 @@ FetchStream.prototype.parseUrl = function (url) {
path: urlparts.pathname + (urlparts.search || '') || '/',
method: this.options.method,
rejectUnauthorized: this.options.rejectUnauthorized
};
};
switch (urlparts.protocol) {
case 'https:':
@@ -185,17 +186,17 @@ FetchStream.prototype.parseUrl = function (url) {
}
if (transport === https) {
if('agentHttps' in this.options){
if ('agentHttps' in this.options) {
urloptions.agent = this.options.agentHttps;
}
if('agent' in this.options){
if ('agent' in this.options) {
urloptions.agent = this.options.agent;
}
} else {
if('agentHttp' in this.options){
if ('agentHttp' in this.options) {
urloptions.agent = this.options.agentHttp;
}
if('agent' in this.options){
if ('agent' in this.options) {
urloptions.agent = this.options.agent;
}
}
@@ -382,7 +383,8 @@ FetchStream.prototype._runStream = function (url_data, url) {
}
};
function fetchUrl(url, options, callback) {
function fetchUrl(url, options, callback)
{
if (!callback && typeof options === 'function') {
callback = options;
options = undefined;
@@ -453,7 +455,8 @@ function fetchUrl(url, options, callback) {
});
}
function _parseContentType(str) {
function _parseContentType(str)
{
if (!str) {
return {};
}
@@ -476,7 +479,8 @@ function _parseContentType(str) {
};
}
function _findHTMLCharset(htmlbuffer) {
function _findHTMLCharset(htmlbuffer)
{
var body = htmlbuffer.toString('ascii'),
input, meta, charset;