particle-iot/stream-http

Name: stream-http

Owner: Particle

Description: Streaming node http in the browser

Forked from: jhiesey/stream-http

Created: 2016-03-04 00:14:09.0

Updated: 2016-03-04 00:14:10.0

Pushed: 2018-01-03 18:47:56.0

Homepage: null

Size: 140

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

stream-http Build Status

Sauce Test Status

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 aren't available, since browsers don't give nearly as much control over requests.

This is heavily inspired by, and intended to replace, http-browserify

What does it do?

In accordance with its name, stream-http tries to provide data to its caller before the request has completed whenever possible.

The following browsers support true streaming, where only a small amount of the request has to be held in memory at once:

The following browsers support pseudo-streaming, where the data is available before the request finishes, but the entire response must be held in memory:

All browsers newer than IE8 support binary responses. All of the above browsers that support true streaming or pseudo-streaming support that for binary data as well except for IE10. Old (presto-based) Opera also does not support binary streaming either.

IE8 note:

As of version 2.0.0, IE8 support requires the user to supply polyfills for Object.keys, Array.prototype.forEach, and Array.prototype.indexOf. Example implementations are provided in ie8-polyfill.js; alternately, you may want to consider using es5-shim. All browsers with full ES5 support shouldn't require any polyfills.

How do you use it?

The intent is to have the same api as the client part of the node HTTP module. The interfaces are the same wherever practical, although limitations in browsers make an exact clone of the node api impossible.

This module implements http.request, http.get, and most of http.ClientRequest and http.IncomingMessage in addition to http.METHODS and http.STATUS_CODES. See the node docs for how these work.

Extra features compared to node

This module has to make some tradeoffs to support binary data and/or streaming. Generally, the module can make a fairly good decision about which underlying browser features to use, but sometimes it helps to get a little input from the user.

Features missing compared to node
Example
.get('/bundle.js', function (res) {
var div = document.getElementById('result');
div.innerHTML += 'GET /beep<br>';

res.on('data', function (buf) {
    div.innerHTML += buf;
});

res.on('end', function () {
    div.innerHTML += '<br>__END__';
});

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.

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.

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 © John Hiesey and other contributors.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.