New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

http-browserify-xdr

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-browserify-xdr

http module compatability for browserify

latest
Source
npmnpm
Version
1.4.1
Version published
Weekly downloads
4
-50%
Maintainers
1
Weekly downloads
 
Created
Source

http-browserify-xdr

The http module from browserify, but for browsers that can only do cross-origin requests with XDomainRequest (IE8 & IE9).

The out-of-the-box [http-browserify] does not work for cross-origin requests with XDomainRequest, and an open issue has gone unresponded to for almost 3 years.

Use this in your browserify project by adding the following to your package.json:

"browser": {
    "http": "http-browserify-xdr"
}

Note: XDomainRequests cannot send cookies, so 'withCredentials' options will be ignored. The way to do cross-origin requests withCredentials in these browsers is, well, you can't. You have to open an iframe serving a src on the origin you want to request, then postMessage into it, have it make the request, then postMessage the response out. See sockjs-client for a referenc eimplementation of that.

The following is the original http-browserify README because the API is the same.

example

var http = require('http');

http.get({ host: 'anotherorigin.com', path : '/beep' }, 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__';
    });
});

http methods

var http = require('http');

var req = http.request(opts, cb)

where opts are:

  • opts.method='GET' - http method verb
  • opts.path - path string, example: '/foo/bar?baz=555'
  • opts.headers={} - as an object mapping key names to string or Array values
  • opts.host=window.location.host - http host
  • opts.port=window.location.port - http port
  • opts.responseType - response type to set on the underlying xhr object

The callback will be called with the response object.

var req = http.get(options, cb)

A shortcut for

options.method = 'GET';
var req = http.request(options, cb);
req.end();

request methods

req.setHeader(key, value)

Set an http header.

req.getHeader(key)

Get an http header.

req.removeHeader(key)

Remove an http header.

req.write(data)

Write some data to the request body.

req.end(data)

Close and send the request body, optionally with additional data to append.

response methods

res.getHeader(key)

Return an http header, if set. key is case-insensitive.

response attributes

  • res.statusCode, the numeric http response code
  • res.headers, an object with all lowercase keys

compatibility

This module has been tested and works with:

  • Internet Explorer 5.5, 6, 7, 8, 9
  • Firefox 3.5
  • Chrome 7.0
  • Opera 10.6
  • Safari 5.0

Multipart streaming responses are buffered in all versions of Internet Explorer and are somewhat buffered in Opera. In all the other browsers you get a nice unbuffered stream of "data" events when you send down a content-type of multipart/octet-stream or similar.

protip

You can do:

var bundle = browserify({
    require : { http : 'http-browserify-xdr' }
});

in order to map "http-browserify-xdr" over require('http') in your browserified source.

install

With npm do:

npm install http-browserify-xdr

license

MIT

Keywords

http

FAQs

Package last updated on 08 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts