@azteam/http-client
Advanced tools
Comparing version 1.0.85 to 1.0.86
{ | ||
"name": "@azteam/http-client", | ||
"version": "1.0.85", | ||
"version": "1.0.86", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
import _ from 'lodash'; | ||
import fs from 'fs'; | ||
import qs from 'querystring'; | ||
import {Readable} from 'stream'; | ||
import {parse} from 'node-html-parser'; | ||
import { Readable } from 'stream'; | ||
import { parse } from 'node-html-parser'; | ||
import axios from 'axios'; | ||
import axiosCookieJarSupport from 'axios-cookiejar-support'; | ||
import {CookieJar} from 'tough-cookie'; | ||
import {FileCookieStore} from 'tough-cookie-file-store'; | ||
import { wrapper } from 'axios-cookiejar-support'; | ||
import { CookieJar } from 'tough-cookie'; | ||
import { FileCookieStore } from 'tough-cookie-file-store'; | ||
import http from 'http'; | ||
@@ -17,8 +17,2 @@ import https from 'https'; | ||
axiosCookieJarSupport(axios); | ||
function bufferToStream(buffer) { | ||
@@ -42,4 +36,4 @@ var stream = new Readable(); | ||
resolveJSON: false, | ||
httpAgent: new http.Agent({keepAlive: true}), | ||
httpsAgent: new https.Agent({keepAlive: true}), | ||
httpAgent: new http.Agent({ keepAlive: true }), | ||
httpsAgent: new https.Agent({ keepAlive: true }), | ||
validateStatus: function(status) { | ||
@@ -54,3 +48,3 @@ return status >= 200 && status < 500; // default | ||
_resetOptions() { | ||
this.options = {...this.initOpts}; | ||
this.options = { ...this.initOpts }; | ||
this.options.headers = { | ||
@@ -175,10 +169,10 @@ ...this.initOpts.headers | ||
upload(url, data = {fieldName: '', file: '', fileName: ''}, metaData = {}) { | ||
upload(url, data = { fieldName: '', file: '', fileName: '' }, metaData = {}) { | ||
this._changeOption('timeout', 300000); | ||
if(typeof data.file === 'string'){ | ||
if (typeof data.file === 'string') { | ||
data.file = fs.createReadStream(data.file); | ||
} else { | ||
const isItBuffer = Buffer.isBuffer(data.file); | ||
if(isItBuffer){ | ||
if (isItBuffer) { | ||
data.file = bufferToStream(data.file); | ||
@@ -196,3 +190,3 @@ } | ||
_.map(form.getHeaders(), (value, key) => { | ||
this.addHeader(key,value) | ||
this.addHeader(key, value) | ||
}); | ||
@@ -226,5 +220,8 @@ | ||
return new Promise((resolve, reject) => { | ||
axios(options).then((response) => { | ||
let client = null; | ||
if (options.jar) { | ||
client = wrapper(axios.create(options)); | ||
} | ||
client.then((response) => { | ||
if (options.resolveWithFullResponse) { | ||
@@ -252,2 +249,2 @@ resolve({ | ||
export default HttpClient; | ||
export default HttpClient; |
15675
277