Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d24d5510a | |||
| ff68130d89 | |||
| 6bab67d17a | |||
| 6433ea8cad | |||
| 9ebf801ebb | |||
| 154f6b9e56 | |||
| 6dea87e704 | |||
| 8b9f5a43c1 | |||
| 3c8b44379c | |||
| c36da3bade | |||
| cbc0bd803c | |||
| d6de2ce3a5 | |||
| 4bcff63d46 | |||
| a69310d8fc |
+1
-1
@@ -1,3 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "4.1"
|
||||
@@ -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.
|
||||
@@ -104,6 +104,21 @@ http.get('/bundle.js', function (res) {
|
||||
})
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
There are two sets of tests: the tests that run in node (found in `test/node`) and the tests
|
||||
that run in the browser (found in `test/browser`). Normally the browser tests run on
|
||||
[Sauce Labs](http://saucelabs.com/).
|
||||
|
||||
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).
|
||||
|
||||
To run just the node tests, run `npm run test-node`.
|
||||
|
||||
To run the browser tests locally, run `npm run test-browser-local` and point your browser to
|
||||
`http://localhost:8080/__zuul`
|
||||
|
||||
## License
|
||||
|
||||
MIT. Copyright (C) John Hiesey and other contributors.
|
||||
|
||||
@@ -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
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "stream-http",
|
||||
"version": "2.0.3",
|
||||
"version": "2.1.0",
|
||||
"description": "Streaming http in the browser",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -8,13 +8,17 @@
|
||||
"url": "git://github.com/jhiesey/stream-http.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run test-node && npm run test-browser",
|
||||
"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"
|
||||
},
|
||||
"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",
|
||||
@@ -25,6 +29,7 @@
|
||||
"dependencies": {
|
||||
"builtin-status-codes": "^1.0.0",
|
||||
"inherits": "^2.0.1",
|
||||
"to-arraybuffer": "^1.0.0",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user