Compare commits

...

13 Commits

Author SHA1 Message Date
Feross Aboukhadijeh 945083bd1d 2.1.1 2016-02-15 21:32:47 -08:00
Feross Aboukhadijeh 2054c18374 sauce labs: add microsoft edge 2016-02-15 20:54:38 -08:00
Feross Aboukhadijeh 218fd54ef0 builtin-status-codes@2 2016-02-15 20:51:06 -08:00
John Hiesey 9d24d5510a 2.1.0 2016-01-13 05:46:14 +01:00
John Hiesey ff68130d89 Add missing "bugs" and "homepage" entries to package.json 2016-01-13 05:10:57 +01:00
John Hiesey 6bab67d17a Use to-arraybuffer instead of manual conversion
This fixes some more edge cases when converting from a Buffer to
an ArrayBuffer.

Additionally, compared v2.0.5, this avoids an unnecessary copy
when sending data in a request body.
2016-01-13 03:40:41 +01:00
John Hiesey 6433ea8cad Replace buffer.buffer with more compatible version
Unforunately some browsers use a version of Buffer
that isn't based on a Uint8Array. Add logic to convert
when necessary but not make copies when unnecessary.
2016-01-13 01:33:11 +01:00
John Hiesey 9ebf801ebb Fix typos 2016-01-12 22:39:46 +01:00
John Hiesey 154f6b9e56 Fix buffer usage in tests as well 2016-01-12 22:18:41 +01:00
John Hiesey 6dea87e704 Merge pull request #36 from karissa/master
Use .buffer to comply with buffer@4 and browserify@13.
2016-01-12 21:56:37 +01:00
Karissa McKelvey 8b9f5a43c1 Use .buffer to comply with buffer@4 and browserify@13 2016-01-12 12:30:39 -08:00
John Hiesey 3c8b44379c 2.0.5 2016-01-09 03:56:05 +01:00
John Hiesey c36da3bade Use 'http:' as a default protocol
If global.location.protocol isn't 'http:' or 'https:', use
'http:'. This makes behavior reasonable when the page is
opened directly without using a server.
2016-01-09 03:55:14 +01:00
7 changed files with 40 additions and 8 deletions
+3 -1
View File
@@ -6,6 +6,8 @@ browsers:
version: 34..latest
- name: safari
version: 5..latest
- name: microsoftedge
version: 20..latest
- name: ie
version: 9..latest
- name: opera
@@ -17,4 +19,4 @@ browsers:
server: ./test/server/index.js
scripts:
- "/ie8-polyfill.js"
- "/test-polyfill.js"
- "/test-polyfill.js"
+2 -2
View File
@@ -81,7 +81,7 @@ characteristics as this mode did in versions before 1.5.
* Any operations, including `request.setTimeout`, that operate directly on the underlying
socket.
* Any options that are disallowed for security reasons. This includes setting or getting
certian headers.
certain headers.
* `message.httpVersion`
* `message.rawHeaders` is modified by the browser, and may not quite match what is sent by
the server.
@@ -112,7 +112,7 @@ that run in the browser (found in `test/browser`). Normally the browser tests ru
Running `npm test` will run both sets of tests, but in order for the Sauce Labs tests to run
you will need to sign up for an account (free for open source projects) and put the
credentials in [a `.zuulrc` file](https://github.com/defunctzombie/zuul/wiki/zuulrc).
credentials in a [`.zuulrc` file](https://github.com/defunctzombie/zuul/wiki/zuulrc).
To run just the node tests, run `npm run test-node`.
+6 -1
View File
@@ -11,7 +11,12 @@ http.request = function (opts, cb) {
else
opts = extend(opts)
var protocol = opts.protocol || ''
// Normally, the page is loaded from http or https, so not specifying a protocol
// will result in a (valid) protocol-relative url. However, this won't work if
// the protocol is something else, like 'file:'
var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : ''
var protocol = opts.protocol || defaultProtocol
var host = opts.hostname || opts.host
var port = opts.port
var path = opts.path || '/'
+2 -1
View File
@@ -3,6 +3,7 @@ var capability = require('./capability')
var inherits = require('inherits')
var response = require('./response')
var stream = require('stream')
var toArrayBuffer = require('to-arraybuffer')
var IncomingMessage = response.IncomingMessage
var rStates = response.readyStates
@@ -96,7 +97,7 @@ ClientRequest.prototype._onFinish = function () {
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
if (capability.blobConstructor) {
body = new global.Blob(self._body.map(function (buffer) {
return buffer.toArrayBuffer()
return toArrayBuffer(buffer)
}), {
type: (headersObj['content-type'] || {}).value || ''
})
+7 -2
View File
@@ -1,6 +1,6 @@
{
"name": "stream-http",
"version": "2.0.4",
"version": "2.1.1",
"description": "Streaming http in the browser",
"main": "index.js",
"repository": {
@@ -15,6 +15,10 @@
},
"author": "John Hiesey",
"license": "MIT",
"bugs": {
"url": "https://github.com/jhiesey/stream-http/issues"
},
"homepage": "https://github.com/jhiesey/stream-http#readme",
"keywords": [
"http",
"stream",
@@ -23,8 +27,9 @@
"http-browserify"
],
"dependencies": {
"builtin-status-codes": "^1.0.0",
"builtin-status-codes": "^2.0.0",
"inherits": "^2.0.1",
"to-arraybuffer": "^1.0.0",
"xtend": "^4.0.0"
},
"devDependencies": {
+1 -1
View File
@@ -9,7 +9,7 @@ module.exports = function (self) {
var buffers = []
res.on('end', function () {
self.postMessage(Buffer.concat(buffers).toArrayBuffer())
self.postMessage(Buffer.concat(buffers).buffer)
})
res.on('data', function (data) {
+19
View File
@@ -64,6 +64,25 @@ test('Test alt protocol', function(t) {
t.end()
})
test('Test page with \'file:\' protocol', function (t) {
var params = {
hostname: 'localhost',
port: 3000,
path: '/bar'
}
var fileLocation = 'file:///home/me/stuff/index.html'
var normalLocation = global.location
global.location = url.parse(fileLocation) // Temporarily change the location
var request = http.get(params, noop)
global.location = normalLocation // Reset the location
var resolved = url.resolve(fileLocation, request._opts.url)
t.equal(resolved, 'http://localhost:3000/bar', 'Url should be correct')
t.end()
})
test('Test string as parameters', function(t) {
var testUrl = '/api/foo'
var request = http.get(testUrl, noop)