Skip to content

Commit

Permalink
Revert "feat: http upload/download progress handlers (#54)"
Browse files Browse the repository at this point in the history
This reverts commit d30be96.
  • Loading branch information
achingbrain authored Aug 14, 2020
1 parent 35f8f70 commit be4528e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 325 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"dist"
],
"browser": {
"./src/http/fetch.js": "./src/http/fetch.browser.js",
"./src/text-encoder.js": "./src/text-encoder.browser.js",
"./src/text-decoder.js": "./src/text-decoder.browser.js",
"./src/temp-dir.js": "./src/temp-dir.browser.js",
Expand Down Expand Up @@ -45,15 +44,15 @@
"merge-options": "^2.0.0",
"nanoid": "^3.1.3",
"node-fetch": "^2.6.0",
"stream-to-it": "^0.2.0",
"it-to-stream": "^0.1.2"
"stream-to-it": "^0.2.0"
},
"devDependencies": {
"aegir": "^25.0.0",
"delay": "^4.3.0",
"it-all": "^1.0.2",
"it-drain": "^1.0.1",
"it-last": "^1.0.2"
"it-last": "^1.0.2",
"it-to-stream": "^0.1.2"
},
"contributors": [
"Hugo Dias <[email protected]>",
Expand Down
23 changes: 19 additions & 4 deletions src/http.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
/* eslint-disable no-undef */
'use strict'

const { fetch, Request, Headers } = require('./http/fetch')
const { TimeoutError, HTTPError } = require('./http/error')
const fetch = require('node-fetch')
const merge = require('merge-options').bind({ ignoreUndefined: true })
const { URL, URLSearchParams } = require('iso-url')
const TextDecoder = require('./text-decoder')
const AbortController = require('abort-controller')
const anySignal = require('any-signal')

const Request = fetch.Request
const Headers = fetch.Headers

class TimeoutError extends Error {
constructor () {
super('Request timed out')
this.name = 'TimeoutError'
}
}

class HTTPError extends Error {
constructor (response) {
super(response.statusText)
this.name = 'HTTPError'
this.response = response
}
}

const timeout = (promise, ms, abortController) => {
if (ms === undefined) {
return promise
Expand Down Expand Up @@ -70,8 +87,6 @@ const defaults = {
* @prop {function(URLSearchParams): URLSearchParams } [transformSearchParams]
* @prop {function(any): any} [transform] - When iterating the response body, transform each chunk with this function.
* @prop {function(Response): Promise<void>} [handleError] - Handle errors
* @prop {function({total:number, loaded:number, lengthComputable:boolean}):void} [onUploadProgress] - Can be passed to track upload progress
* @prop {function({total:number, loaded:number, lengthComputable:boolean}):void} [onDownloadProgress] - Can be passed to track download progress
*/

class HTTP {
Expand Down
26 changes: 0 additions & 26 deletions src/http/error.js

This file was deleted.

124 changes: 0 additions & 124 deletions src/http/fetch.browser.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/http/fetch.js

This file was deleted.

133 changes: 0 additions & 133 deletions src/http/fetch.node.js

This file was deleted.

25 changes: 0 additions & 25 deletions test/http.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,4 @@ describe('http', function () {

await expect(drain(HTTP.ndjson(res.body))).to.eventually.be.rejectedWith(/aborted/)
})

it('progress events', async () => {
let upload = 0
let download = 0
const body = new Uint8Array(1000000 / 2)
const request = await HTTP.post(`${process.env.ECHO_SERVER}/echo`, {
body,
onUploadProgress: (progress) => {
expect(progress).to.have.property('lengthComputable').to.be.a('boolean')
expect(progress).to.have.property('total', body.byteLength)
expect(progress).to.have.property('loaded').to.be.a('number')
upload += 1
},
onDownloadProgress: (progress) => {
expect(progress).to.have.property('lengthComputable').to.be.a('boolean')
expect(progress).to.have.property('total').to.be.a('number')
expect(progress).to.have.property('loaded').to.be.a('number')
download += 1
}
})
await all(request.iterator())

expect(upload).to.be.greaterThan(0)
expect(download).to.be.greaterThan(0)
})
})

0 comments on commit be4528e

Please sign in to comment.