electron-fetch
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,2 +7,7 @@ | ||
## V1.1.0 | ||
- Added option to pass proxy credentials on Electron. Thanks @CharlieHess! | ||
- Fixed a bug where `session` was not passed correctly. Thanks @tex0l! | ||
## v1.0.0 | ||
@@ -9,0 +14,0 @@ |
import { format, parse, resolve } from 'url'; | ||
import { STATUS_CODES } from 'http'; | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
import { Z_SYNC_FLUSH, createGunzip, createInflate, createInflateRaw } from 'zlib'; | ||
import * as zlib from 'zlib'; | ||
import Stream, { PassThrough } from 'stream'; | ||
@@ -42,9 +42,9 @@ import { convert } from 'encoding'; | ||
} else if (ArrayBuffer.isView(element)) { | ||
buffer = new Buffer(new Uint8Array(element.buffer, element.byteOffset, element.byteLength)); | ||
buffer = Buffer.from(new Uint8Array(element.buffer, element.byteOffset, element.byteLength)); | ||
} else if (element instanceof ArrayBuffer) { | ||
buffer = new Buffer(new Uint8Array(element)); | ||
buffer = Buffer.from(new Uint8Array(element)); | ||
} else if (element instanceof Blob) { | ||
buffer = element[BUFFER]; | ||
} else { | ||
buffer = new Buffer(typeof element === 'string' ? element : String(element)); | ||
buffer = Buffer.from(typeof element === 'string' ? element : String(element)); | ||
} | ||
@@ -136,3 +136,4 @@ buffers.push(buffer); | ||
'ERR_NAME_NOT_RESOLVED': 'ENOTFOUND', | ||
'ERR_CONTENT_DECODING_FAILED': 'Z_DATA_ERROR' | ||
'ERR_CONTENT_DECODING_FAILED': 'Z_DATA_ERROR', | ||
'ERR_CONTENT_DECODING_INIT_FAILED': 'Z_DATA_ERROR' | ||
}; | ||
@@ -319,3 +320,3 @@ | ||
if (this.body === null) { | ||
return Promise.resolve(new Buffer(0)); | ||
return Promise.resolve(Buffer.alloc(0)); | ||
} | ||
@@ -325,3 +326,3 @@ | ||
if (typeof this.body === 'string') { | ||
return Promise.resolve(new Buffer(this.body)); | ||
return Promise.resolve(Buffer.from(this.body)); | ||
} | ||
@@ -341,3 +342,3 @@ | ||
if (!(this.body instanceof Stream)) { | ||
return Promise.resolve(new Buffer(0)); | ||
return Promise.resolve(Buffer.alloc(0)); | ||
} | ||
@@ -1261,3 +1262,3 @@ | ||
delete options.headers; | ||
options.session = options.session || electron.session.fromPartition('electron-fetch'); | ||
options.session = opts.session || electron.session.fromPartition('electron-fetch'); | ||
} | ||
@@ -1283,2 +1284,14 @@ const req = send(options); | ||
if (request.useElectronNet) { | ||
// handle authenticating proxies | ||
req.on('login', function (authInfo, callback) { | ||
if (opts.user && opts.password) { | ||
callback(opts.user, opts.password); | ||
} else { | ||
req.abort(); | ||
reject(new FetchError(`login event received from ${authInfo.host} but no credentials provided`, 'proxy', { code: 'PROXY_AUTH_FAILED' })); | ||
} | ||
}); | ||
} | ||
req.on('error', function (err) { | ||
@@ -1351,6 +1364,5 @@ clearTimeout(reqTimeout); | ||
useElectronNet: request.useElectronNet | ||
}; | ||
// HTTP-network fetch step 16.1.2 | ||
const codings = headers.get('Content-Encoding'); | ||
// HTTP-network fetch step 16.1.2 | ||
};const codings = headers.get('Content-Encoding'); | ||
@@ -1415,2 +1427,3 @@ // HTTP-network fetch step 16.1.3: handle content codings | ||
export { Headers, Request, Response, FetchError };export default fetch; | ||
export { Headers, Request, Response, FetchError }; | ||
export default fetch; |
@@ -48,9 +48,9 @@ 'use strict'; | ||
} else if (ArrayBuffer.isView(element)) { | ||
buffer = new Buffer(new Uint8Array(element.buffer, element.byteOffset, element.byteLength)); | ||
buffer = Buffer.from(new Uint8Array(element.buffer, element.byteOffset, element.byteLength)); | ||
} else if (element instanceof ArrayBuffer) { | ||
buffer = new Buffer(new Uint8Array(element)); | ||
buffer = Buffer.from(new Uint8Array(element)); | ||
} else if (element instanceof Blob) { | ||
buffer = element[BUFFER]; | ||
} else { | ||
buffer = new Buffer(typeof element === 'string' ? element : String(element)); | ||
buffer = Buffer.from(typeof element === 'string' ? element : String(element)); | ||
} | ||
@@ -142,3 +142,4 @@ buffers.push(buffer); | ||
'ERR_NAME_NOT_RESOLVED': 'ENOTFOUND', | ||
'ERR_CONTENT_DECODING_FAILED': 'Z_DATA_ERROR' | ||
'ERR_CONTENT_DECODING_FAILED': 'Z_DATA_ERROR', | ||
'ERR_CONTENT_DECODING_INIT_FAILED': 'Z_DATA_ERROR' | ||
}; | ||
@@ -325,3 +326,3 @@ | ||
if (this.body === null) { | ||
return Promise.resolve(new Buffer(0)); | ||
return Promise.resolve(Buffer.alloc(0)); | ||
} | ||
@@ -331,3 +332,3 @@ | ||
if (typeof this.body === 'string') { | ||
return Promise.resolve(new Buffer(this.body)); | ||
return Promise.resolve(Buffer.from(this.body)); | ||
} | ||
@@ -347,3 +348,3 @@ | ||
if (!(this.body instanceof Stream__default)) { | ||
return Promise.resolve(new Buffer(0)); | ||
return Promise.resolve(Buffer.alloc(0)); | ||
} | ||
@@ -1267,3 +1268,3 @@ | ||
delete options.headers; | ||
options.session = options.session || electron.session.fromPartition('electron-fetch'); | ||
options.session = opts.session || electron.session.fromPartition('electron-fetch'); | ||
} | ||
@@ -1289,2 +1290,14 @@ const req = send(options); | ||
if (request.useElectronNet) { | ||
// handle authenticating proxies | ||
req.on('login', function (authInfo, callback) { | ||
if (opts.user && opts.password) { | ||
callback(opts.user, opts.password); | ||
} else { | ||
req.abort(); | ||
reject(new FetchError(`login event received from ${authInfo.host} but no credentials provided`, 'proxy', { code: 'PROXY_AUTH_FAILED' })); | ||
} | ||
}); | ||
} | ||
req.on('error', function (err) { | ||
@@ -1357,6 +1370,5 @@ clearTimeout(reqTimeout); | ||
useElectronNet: request.useElectronNet | ||
}; | ||
// HTTP-network fetch step 16.1.2 | ||
const codings = headers.get('Content-Encoding'); | ||
// HTTP-network fetch step 16.1.2 | ||
};const codings = headers.get('Content-Encoding'); | ||
@@ -1363,0 +1375,0 @@ // HTTP-network fetch step 16.1.3: handle content codings |
{ | ||
"name": "electron-fetch", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A light-weight module that brings window.fetch to electron's background process", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"coverage": "xvfb-maybe cross-env BABEL_ENV=coverage electron-mocha --compilers js:babel-register test/test.js -R test/coverage-reporter.js", | ||
"report": "npm run coverage && codecov -f coverage/coverage-final.json" | ||
"report": "standard && npm run coverage && codecov -f coverage/coverage-final.json" | ||
}, | ||
@@ -41,6 +41,7 @@ "repository": { | ||
"devDependencies": { | ||
"babel-eslint": "^7.1.1", | ||
"babel-plugin-istanbul": "^4.0.0", | ||
"babel-preset-env": "^1.1.10", | ||
"babel-register": "^6.23.0", | ||
"babel-eslint": "^8.0.0", | ||
"babel-plugin-istanbul": "^4.1.4", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-register": "^6.26.0", | ||
"basic-auth-parser": "0.0.2", | ||
"chai": "^3.5.0", | ||
@@ -50,25 +51,26 @@ "chai-as-promised": "^6.0.0", | ||
"chai-string": "^1.3.0", | ||
"codecov": "^1.0.1", | ||
"cross-env": "^3.2.3", | ||
"codecov": "^2.3.0", | ||
"cross-env": "^5.0.5", | ||
"dirty-chai": "^1.2.2", | ||
"electron": "^1.6.2", | ||
"electron-mocha": "^3.3.0", | ||
"form-data": ">=1.0.0", | ||
"electron": "^1.6.13", | ||
"electron-mocha": "^4.0.2", | ||
"form-data": ">=2.3.1", | ||
"is-builtin-module": "^1.0.0", | ||
"istanbul-api": "^1.1.1", | ||
"istanbul-lib-coverage": "^1.0.1", | ||
"mocha": "^3.1.2", | ||
"nyc": "^10.1.2", | ||
"istanbul-api": "^1.1.14", | ||
"istanbul-lib-coverage": "^1.1.1", | ||
"mocha": "^3.5.3", | ||
"nyc": "^11.2.1", | ||
"parted": "^0.1.1", | ||
"promise": "^7.1.1", | ||
"promise": "^8.0.1", | ||
"proxy": "^0.2.4", | ||
"resumer": "0.0.0", | ||
"rollup": "^0.41.4", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"standard": "^9.0.1", | ||
"whatwg-url": "^4.0.0", | ||
"xvfb-maybe": "^0.1.3" | ||
"rollup": "^0.49.3", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"standard": "^10.0.3", | ||
"whatwg-url": "^6.2.1", | ||
"xvfb-maybe": "^0.2.1" | ||
}, | ||
"dependencies": { | ||
"encoding": "^0.1.11" | ||
"encoding": "^0.1.12" | ||
} | ||
} |
99595
2486
29
13
Updatedencoding@^0.1.12