Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 663f88323c | |||
| 12a0b3fd2a | |||
| 520cc451e8 | |||
| 5c3b919dab | |||
| 5bc3a7205e | |||
| 80cbe3c5fe | |||
| c3ab1f7bf0 | |||
| 98095e85eb | |||
| 6547015c3d | |||
| 4b8abf52f3 | |||
| 472ed03ea7 | |||
| 16ec2ee996 | |||
| 8cf284cd4b | |||
| 709d1acc3d | |||
| f800fad249 | |||
| 920dd3cd48 | |||
| 433d1d5e46 | |||
| 86bfe01159 | |||
| 8188419852 | |||
| aa4882c7c6 | |||
| d62864934a | |||
| e875fc72b0 |
@@ -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
@@ -2,4 +2,4 @@
|
||||
bundle.js
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.zuulrc
|
||||
.airtaprc
|
||||
|
||||
+5
-1
@@ -1,3 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6.4"
|
||||
- "node"
|
||||
addons:
|
||||
sauce_connect: true
|
||||
hosts:
|
||||
- airtap.local
|
||||
@@ -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
@@ -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
@@ -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)
|
||||
})
|
||||
|
||||
Generated
+2174
-1676
File diff suppressed because it is too large
Load Diff
+10
-10
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "stream-http",
|
||||
"version": "2.8.0",
|
||||
"version": "2.8.2",
|
||||
"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": "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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user