Compare commits

...

24 Commits

Author SHA1 Message Date
John Hiesey 92500c71be 2.4.0 2016-09-08 16:38:51 -07:00
John Hiesey 05c6f4394c Merge pull request #52 from jhiesey/bump-test-node-ver
Bump travis node version
2016-09-08 15:57:23 -07:00
John Hiesey 9ed7614aed Bump travis node version
Trying to debug tests that fail only on travis
2016-09-08 15:48:33 -07:00
John Hiesey bad84ecb3a Merge pull request #51 from alexjeffburke/allow-disabling-fetch
Allow using a mode to disable the use of fetch
2016-09-08 14:37:38 -07:00
John Hiesey 70b928bbb9 Fix arraybuffer for phantomjs
This should be an equivalent fix to #42
2016-09-08 14:35:22 -07:00
Alex J Burke 53bf1d38e2 Allow using a mode to disable the use of fetch and add a test for the case. 2016-09-01 07:48:38 +01:00
John Hiesey ac250a9b04 Bump minimum iphone version 2016-07-27 21:34:08 -07:00
John Hiesey 83f7b7ef32 Bump zuul version 2016-07-27 21:33:37 -07:00
John Hiesey f3df5d7ace Bump iphone and android minimum tested versions
Sauce Labs no longer supports ios 6. Also correct
the floating point version format.
2016-07-27 18:33:37 -07:00
John Hiesey 345149d708 2.3.1 2016-07-27 18:15:02 -07:00
John Hiesey 9c18855feb Check for ReadableStream instead of ReadableByteStream
ReadableByteStream was removed from the spec and from
Chrome 51. Fixes #46
2016-07-27 14:24:51 -07:00
John Hiesey ff601a9eff 2.3.0 2016-04-28 00:58:52 -07:00
John Hiesey e046049394 Merge pull request #41 from jhiesey/readable-stream
use readable-stream
2016-04-28 00:58:19 -07:00
Feross Aboukhadijeh 333b0437a9 sauce labs: fix edge version 2016-04-28 01:13:17 +02:00
Feross Aboukhadijeh 0552e1e4f5 use readable-stream
For a consistent version of the stream package.

Also, I believe this will help fix
https://github.com/feross/webtorrent/issues/771
2016-04-28 00:55:58 +02:00
John Hiesey 1fbfc4264a Merge pull request #40 from jhiesey/response-url
Expose response url
2016-04-20 13:10:11 -07:00
John Hiesey a0c6d49ba4 Expose response url
Fixes #39
2016-04-20 12:53:54 -07:00
John Hiesey 1d3fca03fa Remove dead line 2016-04-20 01:24:31 -07:00
John Hiesey 5e25ed2f65 2.2.1 2016-03-25 18:53:56 -07:00
John Hiesey b339f4afa9 Fix microsoft edge versions for newer zuul 2016-03-24 03:09:09 -07:00
John Hiesey 4b1419cff7 2.2.0 2016-03-01 15:25:22 -08:00
John Hiesey c9183cd2ad Style fixup 2016-03-01 15:05:17 -08:00
John Hiesey 0f1f0c6365 Merge pull request #37 from sportle/feature/set-cookie-array
Set-Cookie headers should be arrays
2016-03-01 15:04:03 -08:00
Phil Larson 581a4d12da Set-Cookie headers should be arrays 2016-03-01 10:15:19 -08:00
9 changed files with 97 additions and 17 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "4.1"
- "6.4"
+3 -3
View File
@@ -7,15 +7,15 @@ browsers:
- name: safari
version: 5..latest
- name: microsoftedge
version: 20..latest
version: 13..latest
- name: ie
version: 9..latest
- name: opera
version: 11..latest
- name: iphone
version: 5.1..latest
version: '8.1..latest'
- name: android
version: 4.0..latest
version: '4.0..latest'
server: ./test/server/index.js
scripts:
- "/ie8-polyfill.js"
+8
View File
@@ -48,6 +48,10 @@ node docs for how these work.
### Extra features compared to node
* The `message.url` property provides access to the final url after all redirects. This
is useful since the browser follows all redirects silently, unlike node. It is available
in Chrome 37 and newer, Firefox 32 and newer, and Safari 9 and newer.
* The `options.withCredentials` boolean flag, used to indicate if the browser should send
cookies or authentication information with a CORS request. Default false.
@@ -71,6 +75,8 @@ also be a bit slow. This was the default in versions of this module before 1.5.
that isn't a single-byte ASCII or utf8 character) will be corrupted. Of course, this option
is only safe for text data. May also cause the 'content-type' response header to be
incorrectly reported (as 'text/plain; charset=x-user-defined').
* 'disable-fetch': Force the use of plain XHR regardless of the browser declaring a fetch
capability. Preserves the correctness of binary data and the 'content-type' response header.
* 'prefer-fast': Deprecated; now a synonym for 'default', which has the same performance
characteristics as this mode did in versions before 1.5.
@@ -86,6 +92,8 @@ certain headers.
* `message.rawHeaders` is modified by the browser, and may not quite match what is sent by
the server.
* `message.trailers` and `message.rawTrailers` will remain empty.
* Redirects are followed silently by the browser, so it isn't possible to access the 301/302
redirect pages.
## Example
+1 -1
View File
@@ -1,4 +1,4 @@
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream)
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
exports.blobConstructor = false
try {
+10 -6
View File
@@ -1,15 +1,14 @@
// var Base64 = require('Base64')
var capability = require('./capability')
var inherits = require('inherits')
var response = require('./response')
var stream = require('stream')
var stream = require('readable-stream')
var toArrayBuffer = require('to-arraybuffer')
var IncomingMessage = response.IncomingMessage
var rStates = response.readyStates
function decideMode (preferBinary) {
if (capability.fetch) {
function decideMode (preferBinary, useFetch) {
if (capability.fetch && useFetch) {
return 'fetch'
} else if (capability.mozchunkedarraybuffer) {
return 'moz-chunked-arraybuffer'
@@ -38,7 +37,12 @@ var ClientRequest = module.exports = function (opts) {
})
var preferBinary
if (opts.mode === 'prefer-streaming') {
var useFetch = true
if (opts.mode === 'disable-fetch') {
// If the use of XHR should be preferred and includes preserving the 'content-type' header
useFetch = false
preferBinary = true
} else if (opts.mode === 'prefer-streaming') {
// If streaming is a high priority but binary compatibility and
// the accuracy of the 'content-type' header aren't
preferBinary = false
@@ -51,7 +55,7 @@ var ClientRequest = module.exports = function (opts) {
} else {
throw new Error('Invalid value for opts.mode')
}
self._mode = decideMode(preferBinary)
self._mode = decideMode(preferBinary, useFetch)
self.on('finish', function () {
self._onFinish()
+12 -4
View File
@@ -1,6 +1,6 @@
var capability = require('./capability')
var inherits = require('inherits')
var stream = require('stream')
var stream = require('readable-stream')
var rStates = exports.readyStates = {
UNSENT: 0,
@@ -31,6 +31,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
if (mode === 'fetch') {
self._fetchResponse = response
self.url = response.url
self.statusCode = response.status
self.statusMessage = response.statusText
// backwards compatible version of for (<item> of <iterable>):
@@ -60,6 +61,7 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
self._xhr = xhr
self._pos = 0
self.url = xhr.responseURL
self.statusCode = xhr.status
self.statusMessage = xhr.statusText
var headers = xhr.getAllResponseHeaders().split(/\r?\n/)
@@ -67,10 +69,16 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) {
var matches = header.match(/^([^:]+):\s*(.*)/)
if (matches) {
var key = matches[1].toLowerCase()
if (self.headers[key] !== undefined)
if (key === 'set-cookie') {
if (self.headers[key] === undefined) {
self.headers[key] = []
}
self.headers[key].push(matches[2])
} else if (self.headers[key] !== undefined) {
self.headers[key] += ', ' + matches[2]
else
} else {
self.headers[key] = matches[2]
}
self.rawHeaders.push(matches[1], matches[2])
}
})
@@ -135,7 +143,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
}
break
case 'arraybuffer':
if (xhr.readyState !== rStates.DONE)
if (xhr.readyState !== rStates.DONE || !xhr.response)
break
response = xhr.response
self.push(new Buffer(new Uint8Array(response)))
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "stream-http",
"version": "2.1.1",
"version": "2.4.0",
"description": "Streaming http in the browser",
"main": "index.js",
"repository": {
@@ -29,6 +29,7 @@
"dependencies": {
"builtin-status-codes": "^2.0.0",
"inherits": "^2.0.1",
"readable-stream": "^2.1.0",
"to-arraybuffer": "^1.0.0",
"xtend": "^4.0.0"
},
@@ -40,6 +41,6 @@
"tape": "^4.0.0",
"ua-parser-js": "^0.7.7",
"webworkify": "^1.0.2",
"zuul": "^3.1.0"
"zuul": "^3.10.3"
}
}
+37
View File
@@ -0,0 +1,37 @@
var Buffer = require('buffer').Buffer
var test = require('tape')
var http = require('../..')
test('disable fetch', function (t) {
var originalFetch
if (typeof fetch === 'function') {
originalFetch = fetch
}
var fetchCalled = false
fetch = function (input, options) {
fetchCalled = true
if (originalFetch) {
return originalFetch(input, options)
}
}
http.get({
path: '/browserify.png',
mode: 'disable-fetch'
}, function (res) {
t.ok(!fetchCalled, 'fetch was not called')
if (originalFetch) {
fetch = originalFetch
}
res.on('end', function () {
t.ok(res.headers['content-type'] === 'image/png', 'content-type was set correctly')
t.end()
})
res.on('data', function () {})
})
})
+22
View File
@@ -1,13 +1,35 @@
var Buffer = require('buffer').Buffer
var fs = require('fs')
var test = require('tape')
var UAParser = require('ua-parser-js')
var url = require('url')
var http = require('../..')
var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser()
var browserName = browser.name
var browserVersion = browser.major
// Response urls don't work on many browsers
var skipResponseUrl = ((browserName === 'Opera') ||
(browserName === 'IE') ||
(browserName === 'Edge') ||
(browserName === 'Chrome' && browserVersion <= 36) ||
(browserName === 'Firefox' && browserVersion <= 31) ||
((browserName === 'Safari' || browserName === 'Mobile Safari') && browserVersion <= 8) ||
(browserName === 'WebKit') || // Old mobile safari
(browserName === 'Android Browser' && browserVersion <= 4))
var reference = fs.readFileSync(__dirname + '/../server/static/basic.txt')
test('basic functionality', function (t) {
http.get('/basic.txt', function (res) {
if (!skipResponseUrl) {
var testUrl = url.resolve(global.location.href, '/basic.txt')
// Redirects aren't tested, but presumably only browser bugs
// would cause this to fail only after redirects.
t.equals(res.url, testUrl, 'response url correct')
}
var buffers = []
res.on('end', function () {