Compare commits

...

31 Commits

Author SHA1 Message Date
John Hiesey f2341d0598 All browsers again 2018-05-09 18:56:07 -07:00
John Hiesey c348b1494b All except firefox 2018-05-09 18:33:39 -07:00
John Hiesey f03225fa0c Only safari and firefox 2018-05-09 18:26:04 -07:00
John Hiesey a78b00ff6e All except safari and firefox 2018-05-09 18:12:51 -07:00
John Hiesey ebed5847c8 All except chrome 2018-05-09 17:59:27 -07:00
John Hiesey 2515f6420d Second half of browser list 2018-05-09 17:51:39 -07:00
John Hiesey 204b5abba7 Edge only 2018-05-09 17:48:53 -07:00
John Hiesey a72bc9b825 All except edge 2018-05-09 17:28:42 -07:00
John Hiesey a1a075d6ab Only android 2018-05-09 17:24:28 -07:00
John Hiesey 6c795acf4e Enable airtap debug 2018-05-09 16:45:24 -07:00
John Hiesey 12a0b3fd2a npm update 2018-05-09 16:37:22 -07:00
John Hiesey 520cc451e8 Clear fetch timeout after request finishes
Instead of right when response is created, which misses timeouts
that occur later
2018-05-08 21:52:39 -07:00
John Hiesey 5c3b919dab Fix edge tests 2018-05-08 21:52:05 -07:00
John Hiesey 5bc3a7205e Add (disabled) test for timeout after success
Unfortunately, reasonable timeout lengths tend to cause
spurious failures, so this test shouldn't be enabled
normally.
2018-05-08 20:37:36 -07:00
John Hiesey 80cbe3c5fe Improve fetch error handling 2018-05-08 17:36:01 -07:00
John Hiesey c3ab1f7bf0 Update package-lock.json 2018-05-08 16:18:22 -07:00
John Hiesey 98095e85eb Bump airtap version 2018-05-08 16:18:11 -07:00
John Hiesey 6547015c3d Also clear fetch timeout on error 2018-05-08 16:13:41 -07:00
John Hiesey 4b8abf52f3 Fetch clearTimeout fixup 2018-05-08 16:07:46 -07:00
John Hiesey 472ed03ea7 Merge pull request #87 from luozhang002/fetchmode
fix:add clearTimeout issue#85
2018-05-08 16:04:48 -07:00
罗章 16ec2ee996 fix:add clearTimeout 2018-05-03 13:24:32 +08:00
John Hiesey 8cf284cd4b 2.8.1 2018-03-14 13:27:52 -07:00
John Hiesey 709d1acc3d Stop trying to run tests on iOS 8
It seems that this is no longer supported by Sauce Labs
2018-03-14 13:14:14 -07:00
John Hiesey f800fad249 Fix incorrect definition of http.IncomingMessage
Also add test for top-level http properties, plus a stub http.globalAgent
Fixes #81
2018-03-14 13:08:47 -07:00
John Hiesey 920dd3cd48 Bump airtap version 2018-02-26 22:50:33 -08:00
John Hiesey 433d1d5e46 Stop testing safari 7 since sauce labs gives errors 2018-02-26 22:50:01 -08:00
John Hiesey 86bfe01159 Re-enable webworker test with workaround 2018-02-26 17:43:26 -08:00
John Hiesey 8188419852 Merge pull request #84 from jhiesey/airtap
Switch from zuul to airtap for running browser tests
2018-02-22 00:56:32 -08:00
John Hiesey aa4882c7c6 Fix running browser tests locally with airtap 2018-02-22 00:40:33 -08:00
John Hiesey d62864934a Disable android 7 tests due to airtap issue
Upstream issue: https://github.com/airtap/browsers/issues/3
2018-02-22 00:29:58 -08:00
John Hiesey e875fc72b0 Switch from zuul to airtap for tests 2018-02-21 22:22:04 -08:00
11 changed files with 2257 additions and 1703 deletions
+8 -5
View File
@@ -1,20 +1,23 @@
ui: tape
sauce_connect: true
browsers:
- name: chrome
version: 39..latest
- name: firefox
version: 34..latest
- name: safari
version: 7..latest
- name: microsoftedge
version: 8..latest
- name: MicrosoftEdge
version: 13..latest
- name: ie
version: 9..latest
- name: iphone
version: '8.1..latest'
version: '9.3..latest'
- name: android
version: '4.4..latest'
version: '4.4..6.0' # TODO: change this back to latest once https://github.com/airtap/browsers/issues/3 is fixed
server: ./test/server/index.js
scripts:
- "/ie8-polyfill.js"
- "/test-polyfill.js"
browserify:
- options:
dedupe: false
+1 -1
View File
@@ -2,4 +2,4 @@
bundle.js
node_modules
npm-debug.log
.zuulrc
.airtaprc
+5 -1
View File
@@ -1,3 +1,7 @@
language: node_js
node_js:
- "6.4"
- "node"
addons:
sauce_connect: true
hosts:
- airtap.local
+4 -2
View File
@@ -1,5 +1,5 @@
var ClientRequest = require('./lib/request')
var IncomingMessage = require('./lib/response')
var response = require('./lib/response')
var extend = require('xtend')
var statusCodes = require('builtin-status-codes')
var url = require('url')
@@ -46,11 +46,13 @@ http.get = function get (opts, cb) {
}
http.ClientRequest = ClientRequest
http.IncomingMessage = IncomingMessage
http.IncomingMessage = response.IncomingMessage
http.Agent = function () {}
http.Agent.defaultMaxSockets = 4
http.globalAgent = new http.Agent()
http.STATUS_CODES = statusCodes
http.METHODS = [
+8 -3
View File
@@ -56,6 +56,7 @@ var ClientRequest = module.exports = function (opts) {
throw new Error('Invalid value for opts.mode')
}
self._mode = decideMode(preferBinary, useFetch)
self._fetchTimer = null
self.on('finish', function () {
self._onFinish()
@@ -131,13 +132,14 @@ ClientRequest.prototype._onFinish = function () {
if (self._mode === 'fetch') {
var signal = null
var fetchTimer = null
if (capability.abortController) {
var controller = new AbortController()
signal = controller.signal
self._fetchAbortController = controller
if ('requestTimeout' in opts && opts.requestTimeout !== 0) {
global.setTimeout(function () {
self._fetchTimer = global.setTimeout(function () {
self.emit('requestTimeout')
if (self._fetchAbortController)
self._fetchAbortController.abort()
@@ -156,7 +158,9 @@ ClientRequest.prototype._onFinish = function () {
self._fetchResponse = response
self._connect()
}, function (reason) {
self.emit('error', reason)
global.clearTimeout(self._fetchTimer)
if (!self._destroyed)
self.emit('error', reason)
})
} else {
var xhr = self._xhr = new global.XMLHttpRequest()
@@ -256,7 +260,7 @@ ClientRequest.prototype._connect = function () {
if (self._destroyed)
return
self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode)
self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._fetchTimer)
self._response.on('error', function(err) {
self.emit('error', err)
})
@@ -274,6 +278,7 @@ ClientRequest.prototype._write = function (chunk, encoding, cb) {
ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () {
var self = this
self._destroyed = true
global.clearTimeout(self._fetchTimer)
if (self._response)
self._response._destroyed = true
if (self._xhr)
+11 -4
View File
@@ -10,7 +10,7 @@ var rStates = exports.readyStates = {
DONE: 4
}
var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, fetchTimer) {
var self = this
stream.Readable.call(self)
@@ -45,7 +45,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
write: function (chunk) {
return new Promise(function (resolve, reject) {
if (self._destroyed) {
return
reject()
} else if(self.push(new Buffer(chunk))) {
resolve()
} else {
@@ -54,6 +54,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
})
},
close: function () {
global.clearTimeout(fetchTimer)
if (!self._destroyed)
self.push(null)
},
@@ -64,7 +65,11 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
})
try {
response.body.pipeTo(writable)
response.body.pipeTo(writable).catch(function (err) {
global.clearTimeout(fetchTimer)
if (!self._destroyed)
self.emit('error', err)
})
return
} catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this
}
@@ -75,12 +80,14 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
if (self._destroyed)
return
if (result.done) {
global.clearTimeout(fetchTimer)
self.push(null)
return
}
self.push(new Buffer(result.value))
read()
}).catch(function(err) {
}).catch(function (err) {
global.clearTimeout(fetchTimer)
if (!self._destroyed)
self.emit('error', err)
})
+2174 -1676
View File
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -1,6 +1,6 @@
{
"name": "stream-http",
"version": "2.8.0",
"version": "2.8.1",
"description": "Streaming http in the browser",
"main": "index.js",
"repository": {
@@ -10,8 +10,8 @@
"scripts": {
"test": "npm run test-node && ([ -n \"${TRAVIS_PULL_REQUEST}\" -a \"${TRAVIS_PULL_REQUEST}\" != 'false' ] || npm run test-browser)",
"test-node": "tape test/node/*.js",
"test-browser": "zuul --no-coverage -- test/browser/*.js",
"test-browser-local": "zuul --local 8080 --no-coverage -- test/browser/*.js"
"test-browser": "DEBUG=airtap airtap --loopback airtap.local -- test/browser/*.js",
"test-browser-local": "airtap --no-instrument --local 8080 -- test/browser/*.js"
},
"author": "John Hiesey",
"license": "MIT",
@@ -29,18 +29,18 @@
"dependencies": {
"builtin-status-codes": "^3.0.0",
"inherits": "^2.0.1",
"readable-stream": "^2.3.3",
"readable-stream": "^2.3.6",
"to-arraybuffer": "^1.0.0",
"xtend": "^4.0.0"
},
"devDependencies": {
"airtap": "^0.0.5",
"basic-auth": "^2.0.0",
"brfs": "^1.4.0",
"brfs": "^1.6.1",
"cookie-parser": "^1.4.3",
"express": "^4.16.2",
"tape": "^4.8.0",
"ua-parser-js": "^0.7.17",
"webworkify": "^1.5.0",
"zuul": "^3.10.3"
"express": "^4.16.3",
"tape": "^4.9.0",
"ua-parser-js": "^0.7.18",
"webworkify": "^1.5.0"
}
}
+21
View File
@@ -20,3 +20,24 @@ test('timeout', function (t) {
t.end()
})
})
// TODO: reenable this if there's a way to make it simultaneously
// fast and reliable
test.skip('no timeout after success', function (t) {
var req = http.get({
path: '/basic.txt',
requestTimeout: 50000 // ms
}, function (res) {
res.on('data', function (data) {
})
res.on('end', function () {
t.pass('success')
global.setTimeout(function () {
t.end()
}, 50000)
})
})
req.on('requestTimeout', function () {
t.fail('unexpected timeout')
})
})
+14
View File
@@ -17,6 +17,20 @@ var moduleName = require.resolve('../../')
delete require.cache[moduleName]
var http = require('../../')
test('Make sure http object has correct properties', function (t) {
t.ok(http.Agent, 'Agent defined')
t.ok(http.ClientRequest, 'ClientRequest defined')
t.ok(http.ClientRequest.prototype, 'ClientRequest.prototype defined')
t.ok(http.IncomingMessage, 'IncomingMessage defined')
t.ok(http.IncomingMessage.prototype, 'IncomingMessage.prototype defined')
t.ok(http.METHODS, 'METHODS defined')
t.ok(http.STATUS_CODES, 'STATUS_CODES defined')
t.ok(http.get, 'get defined')
t.ok(http.globalAgent, 'globalAgent defined')
t.ok(http.request, 'request defined')
t.end()
})
test('Test simple url string', function(t) {
var testUrl = { path: '/api/foo' }
var request = http.get(testUrl, noop)
+1 -1
View File
@@ -132,6 +132,6 @@ app.use(function (req, res, next) {
app.use(express.static(path.join(__dirname, 'static')))
var port = parseInt(process.env.ZUUL_PORT) || 8199
var port = parseInt(process.env.AIRTAP_PORT) || 8199
console.log('Test server listening on port', port)
server.listen(port)