stream-http
Advanced tools
Comparing version 2.6.3 to 2.7.0
@@ -102,3 +102,3 @@ var capability = require('./capability') | ||
var body = null | ||
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH' || opts.method === 'MERGE') { | ||
if (opts.method !== 'GET' && opts.method !== 'HEAD') { | ||
if (capability.blobConstructor) { | ||
@@ -116,10 +116,20 @@ body = new global.Blob(self._body.map(function (buffer) { | ||
// create flattened list of headers | ||
var headersList = [] | ||
Object.keys(headersObj).forEach(function (keyName) { | ||
var name = headersObj[keyName].name | ||
var value = headersObj[keyName].value | ||
if (Array.isArray(value)) { | ||
value.forEach(function (v) { | ||
headersList.push([name, v]) | ||
}) | ||
} else { | ||
headersList.push([name, value]) | ||
} | ||
}) | ||
if (self._mode === 'fetch') { | ||
var headers = Object.keys(headersObj).map(function (name) { | ||
return [headersObj[name].name, headersObj[name].value] | ||
}) | ||
global.fetch(self._opts.url, { | ||
method: self._opts.method, | ||
headers: headers, | ||
headers: headersList, | ||
body: body || undefined, | ||
@@ -162,4 +172,4 @@ mode: 'cors', | ||
Object.keys(headersObj).forEach(function (name) { | ||
xhr.setRequestHeader(headersObj[name].name, headersObj[name].value) | ||
headersList.forEach(function (header) { | ||
xhr.setRequestHeader(header[0], header[1]) | ||
}) | ||
@@ -166,0 +176,0 @@ |
{ | ||
"name": "stream-http", | ||
"version": "2.6.3", | ||
"version": "2.7.0", | ||
"description": "Streaming http in the browser", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"inherits": "^2.0.1", | ||
"readable-stream": "^2.1.0", | ||
"readable-stream": "^2.2.6", | ||
"to-arraybuffer": "^1.0.0", | ||
@@ -41,3 +41,3 @@ "xtend": "^4.0.0" | ||
"cookie-parser": "^1.3.5", | ||
"express": "^4.13.0", | ||
"express": "^4.15.2", | ||
"tape": "^4.0.0", | ||
@@ -44,0 +44,0 @@ "ua-parser-js": "^0.7.7", |
@@ -49,2 +49,36 @@ var Buffer = require('buffer').Buffer | ||
test('arrays of headers', function (t) { | ||
http.get({ | ||
path: '/testHeaders?Response-Header=bar&Response-Header=BAR2', | ||
headers: { | ||
'Test-Request-Header': ['foo', 'FOO2'] | ||
} | ||
}, function (res) { | ||
var rawHeaders = [] | ||
for (var i = 0; i < res.rawHeaders.length; i += 2) { | ||
var lowerKey = res.rawHeaders[i].toLowerCase() | ||
if (lowerKey.indexOf('test-') === 0) | ||
rawHeaders.push(lowerKey, res.rawHeaders[i + 1]) | ||
} | ||
t.equal(rawHeaders[0], 'test-response-header', 'raw response header present') | ||
t.equal(rawHeaders[1], 'bar, BAR2', 'raw response header value') | ||
t.equal(rawHeaders.length, 2, 'correct number of raw headers') | ||
t.equal(res.headers['test-response-header'], 'bar, BAR2', 'response header') | ||
var buffers = [] | ||
res.on('end', function () { | ||
var body = JSON.parse(Buffer.concat(buffers).toString()) | ||
t.equal(body['test-request-header'], 'foo,FOO2', 'request headers') | ||
t.equal(Object.keys(body).length, 1, 'correct number of request headers') | ||
t.end() | ||
}) | ||
res.on('data', function (data) { | ||
buffers.push(data) | ||
}) | ||
}) | ||
}) | ||
test('content-type response header', function (t) { | ||
@@ -60,6 +94,7 @@ http.get('/testHeaders', function (res) { | ||
var browserVersion = browser.major | ||
var browserMinorVersion = browser.minor | ||
// The content-type header is broken when 'prefer-streaming' or 'allow-wrong-content-type' | ||
// is passed in browsers that rely on xhr.overrideMimeType(), namely older chrome and newer safari | ||
// is passed in browsers that rely on xhr.overrideMimeType(), namely older chrome and safari 6-10.0 | ||
var wrongMimeType = ((browserName === 'Chrome' && browserVersion <= 42) || | ||
((browserName === 'Safari' || browserName === 'Mobile Safari') && browserVersion >= 6)) | ||
((browserName === 'Safari' || browserName === 'Mobile Safari') && browserVersion >= 6 && (browserVersion < 10 || (browserVersion === 10 && browserMinorVersion === 0)))) | ||
@@ -66,0 +101,0 @@ test('content-type response header with forced streaming', function (t) { |
@@ -40,4 +40,7 @@ var cookieParser = require('cookie-parser') | ||
key = key.toLowerCase() | ||
if (key.indexOf('test-') === 0) | ||
reqHeaders[key] = req.headers[key] | ||
if (key.indexOf('test-') === 0) { | ||
// different browsers format request headers with multiple values | ||
// slightly differently, so normalize | ||
reqHeaders[key] = req.headers[key].replace(', ', ',') | ||
} | ||
}) | ||
@@ -44,0 +47,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87527
1417
12
Updatedreadable-stream@^2.2.6