Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8c0966c63 | |||
| efaad2a3c7 | |||
| 9059849673 | |||
| aeabb2cc70 | |||
| 588e5874f3 | |||
| 5fc4858d6d | |||
| 22b3cc7acb | |||
| 5ffc869490 |
@@ -1,6 +1,6 @@
|
||||
# stream-http [](https://travis-ci.org/jhiesey/stream-http)
|
||||
|
||||
[](https://saucelabs.com/u/jhiesey)
|
||||
[](https://saucelabs.com/u/stream-http)
|
||||
|
||||
This module is an implementation of node's native `http` module for the browser.
|
||||
It tries to match node's api and behavior as closely as possible, but some features
|
||||
|
||||
@@ -25,9 +25,6 @@ http.request = function (opts, cb) {
|
||||
opts.hostname = opts.hostname || hostHostname || window.location.hostname
|
||||
opts.port = opts.port || hostPort || defaultPort
|
||||
|
||||
if (opts.withCredentials === undefined)
|
||||
opts.withCredentials = true
|
||||
|
||||
// Also valid opts.auth, opts.mode
|
||||
|
||||
var req = new ClientRequest(opts)
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ ClientRequest.prototype._onFinish = function () {
|
||||
headers: headers,
|
||||
body: body,
|
||||
mode: 'cors',
|
||||
credentials: opts.withCredentials ? 'include' : 'omit'
|
||||
credentials: opts.withCredentials ? 'include' : 'same-origin'
|
||||
}).then(function (response) {
|
||||
self._fetchResponse = response
|
||||
self._connect()
|
||||
|
||||
+9
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "stream-http",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"description": "Streaming http in the browser",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -15,6 +15,13 @@
|
||||
},
|
||||
"author": "John Hiesey",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"http",
|
||||
"stream",
|
||||
"streaming",
|
||||
"xhr",
|
||||
"http-browserify"
|
||||
],
|
||||
"dependencies": {
|
||||
"builtin-status-codes": "~1.0.0",
|
||||
"foreach": "^2.0.5",
|
||||
@@ -26,6 +33,7 @@
|
||||
"devDependencies": {
|
||||
"basic-auth": "^1.0.3",
|
||||
"brfs": "^1.4.0",
|
||||
"cookie-parser": "^1.3.5",
|
||||
"express": "^4.13.0",
|
||||
"tape": "^4.0.0",
|
||||
"ua-parser-js": "^0.7.7",
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
var Buffer = require('buffer').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
var http = require('../..')
|
||||
|
||||
test('cookie', function (t) {
|
||||
var cookie = 'hello=world'
|
||||
window.document.cookie = cookie
|
||||
|
||||
http.get({
|
||||
path: '/cookie',
|
||||
withCredentials: false
|
||||
}, function (res) {
|
||||
var buffers = []
|
||||
|
||||
res.on('end', function () {
|
||||
t.ok(new Buffer(cookie).equals(Buffer.concat(buffers)), 'hello cookie echoed')
|
||||
t.end()
|
||||
})
|
||||
|
||||
res.on('data', function (data) {
|
||||
buffers.push(data)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -85,7 +85,7 @@ test('Test withCredentials param', function(t) {
|
||||
t.equal( request._xhr.withCredentials, true, 'xhr.withCredentials should be true')
|
||||
|
||||
var request = http.get({ url: url }, noop)
|
||||
t.equal( request._xhr.withCredentials, true, 'xhr.withCredentials should be true')
|
||||
t.equal( request._xhr.withCredentials, false, 'xhr.withCredentials should be false')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
var cookieParser = require('cookie-parser')
|
||||
var basicAuth = require('basic-auth')
|
||||
var express = require('express')
|
||||
var fs = require('fs')
|
||||
@@ -46,6 +47,12 @@ app.get('/testHeaders', function (req, res) {
|
||||
res.end()
|
||||
})
|
||||
|
||||
app.get('/cookie', cookieParser(), function (req, res) {
|
||||
res.setHeader('Content-Type', 'text/plain')
|
||||
res.write('hello=' + req.cookies.hello)
|
||||
res.end()
|
||||
})
|
||||
|
||||
app.get('/auth', function (req, res) {
|
||||
var user = basicAuth(req)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user