Skip to content

Commit 1bbe957

Browse files
authored
fix: revert "feat: http upload/download progress handlers" (#58)
This reverts commit d30be96.
1 parent 35f8f70 commit 1bbe957

File tree

7 files changed

+22
-325
lines changed

7 files changed

+22
-325
lines changed

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dist"
1313
],
1414
"browser": {
15-
"./src/http/fetch.js": "./src/http/fetch.browser.js",
1615
"./src/text-encoder.js": "./src/text-encoder.browser.js",
1716
"./src/text-decoder.js": "./src/text-decoder.browser.js",
1817
"./src/temp-dir.js": "./src/temp-dir.browser.js",
@@ -45,15 +44,15 @@
4544
"merge-options": "^2.0.0",
4645
"nanoid": "^3.1.3",
4746
"node-fetch": "^2.6.0",
48-
"stream-to-it": "^0.2.0",
49-
"it-to-stream": "^0.1.2"
47+
"stream-to-it": "^0.2.0"
5048
},
5149
"devDependencies": {
5250
"aegir": "^25.0.0",
5351
"delay": "^4.3.0",
5452
"it-all": "^1.0.2",
5553
"it-drain": "^1.0.1",
56-
"it-last": "^1.0.2"
54+
"it-last": "^1.0.2",
55+
"it-to-stream": "^0.1.2"
5756
},
5857
"contributors": [
5958
"Hugo Dias <[email protected]>",

src/http.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
/* eslint-disable no-undef */
22
'use strict'
33

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

11+
const Request = fetch.Request
12+
const Headers = fetch.Headers
13+
14+
class TimeoutError extends Error {
15+
constructor () {
16+
super('Request timed out')
17+
this.name = 'TimeoutError'
18+
}
19+
}
20+
21+
class HTTPError extends Error {
22+
constructor (response) {
23+
super(response.statusText)
24+
this.name = 'HTTPError'
25+
this.response = response
26+
}
27+
}
28+
1229
const timeout = (promise, ms, abortController) => {
1330
if (ms === undefined) {
1431
return promise
@@ -70,8 +87,6 @@ const defaults = {
7087
* @prop {function(URLSearchParams): URLSearchParams } [transformSearchParams]
7188
* @prop {function(any): any} [transform] - When iterating the response body, transform each chunk with this function.
7289
* @prop {function(Response): Promise<void>} [handleError] - Handle errors
73-
* @prop {function({total:number, loaded:number, lengthComputable:boolean}):void} [onUploadProgress] - Can be passed to track upload progress
74-
* @prop {function({total:number, loaded:number, lengthComputable:boolean}):void} [onDownloadProgress] - Can be passed to track download progress
7590
*/
7691

7792
class HTTP {

src/http/error.js

-26
This file was deleted.

src/http/fetch.browser.js

-124
This file was deleted.

src/http/fetch.js

-9
This file was deleted.

src/http/fetch.node.js

-133
This file was deleted.

test/http.spec.js

-25
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,4 @@ describe('http', function () {
150150

151151
await expect(drain(HTTP.ndjson(res.body))).to.eventually.be.rejectedWith(/aborted/)
152152
})
153-
154-
it('progress events', async () => {
155-
let upload = 0
156-
let download = 0
157-
const body = new Uint8Array(1000000 / 2)
158-
const request = await HTTP.post(`${process.env.ECHO_SERVER}/echo`, {
159-
body,
160-
onUploadProgress: (progress) => {
161-
expect(progress).to.have.property('lengthComputable').to.be.a('boolean')
162-
expect(progress).to.have.property('total', body.byteLength)
163-
expect(progress).to.have.property('loaded').to.be.a('number')
164-
upload += 1
165-
},
166-
onDownloadProgress: (progress) => {
167-
expect(progress).to.have.property('lengthComputable').to.be.a('boolean')
168-
expect(progress).to.have.property('total').to.be.a('number')
169-
expect(progress).to.have.property('loaded').to.be.a('number')
170-
download += 1
171-
}
172-
})
173-
await all(request.iterator())
174-
175-
expect(upload).to.be.greaterThan(0)
176-
expect(download).to.be.greaterThan(0)
177-
})
178153
})

0 commit comments

Comments
 (0)