react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / http-browserify / index.js
80713 viewsvar http = module.exports;1var EventEmitter = require('events').EventEmitter;2var Request = require('./lib/request');3var url = require('url')45http.request = function (params, cb) {6if (typeof params === 'string') {7params = url.parse(params)8}9if (!params) params = {};10if (!params.host && !params.port) {11params.port = parseInt(window.location.port, 10);12}13if (!params.host && params.hostname) {14params.host = params.hostname;15}1617if (!params.protocol) {18if (params.scheme) {19params.protocol = params.scheme + ':';20} else {21params.protocol = window.location.protocol;22}23}2425if (!params.host) {26params.host = window.location.hostname || window.location.host;27}28if (/:/.test(params.host)) {29if (!params.port) {30params.port = params.host.split(':')[1];31}32params.host = params.host.split(':')[0];33}34if (!params.port) params.port = params.protocol == 'https:' ? 443 : 80;3536var req = new Request(new xhrHttp, params);37if (cb) req.on('response', cb);38return req;39};4041http.get = function (params, cb) {42params.method = 'GET';43var req = http.request(params, cb);44req.end();45return req;46};4748http.Agent = function () {};49http.Agent.defaultMaxSockets = 4;5051var xhrHttp = (function () {52if (typeof window === 'undefined') {53throw new Error('no window object present');54}55else if (window.XMLHttpRequest) {56return window.XMLHttpRequest;57}58else if (window.ActiveXObject) {59var axs = [60'Msxml2.XMLHTTP.6.0',61'Msxml2.XMLHTTP.3.0',62'Microsoft.XMLHTTP'63];64for (var i = 0; i < axs.length; i++) {65try {66var ax = new(window.ActiveXObject)(axs[i]);67return function () {68if (ax) {69var ax_ = ax;70ax = null;71return ax_;72}73else {74return new(window.ActiveXObject)(axs[i]);75}76};77}78catch (e) {}79}80throw new Error('ajax not supported in this browser')81}82else {83throw new Error('ajax not supported in this browser');84}85})();8687http.STATUS_CODES = {88100 : 'Continue',89101 : 'Switching Protocols',90102 : 'Processing', // RFC 2518, obsoleted by RFC 491891200 : 'OK',92201 : 'Created',93202 : 'Accepted',94203 : 'Non-Authoritative Information',95204 : 'No Content',96205 : 'Reset Content',97206 : 'Partial Content',98207 : 'Multi-Status', // RFC 491899300 : 'Multiple Choices',100301 : 'Moved Permanently',101302 : 'Moved Temporarily',102303 : 'See Other',103304 : 'Not Modified',104305 : 'Use Proxy',105307 : 'Temporary Redirect',106400 : 'Bad Request',107401 : 'Unauthorized',108402 : 'Payment Required',109403 : 'Forbidden',110404 : 'Not Found',111405 : 'Method Not Allowed',112406 : 'Not Acceptable',113407 : 'Proxy Authentication Required',114408 : 'Request Time-out',115409 : 'Conflict',116410 : 'Gone',117411 : 'Length Required',118412 : 'Precondition Failed',119413 : 'Request Entity Too Large',120414 : 'Request-URI Too Large',121415 : 'Unsupported Media Type',122416 : 'Requested Range Not Satisfiable',123417 : 'Expectation Failed',124418 : 'I\'m a teapot', // RFC 2324125422 : 'Unprocessable Entity', // RFC 4918126423 : 'Locked', // RFC 4918127424 : 'Failed Dependency', // RFC 4918128425 : 'Unordered Collection', // RFC 4918129426 : 'Upgrade Required', // RFC 2817130428 : 'Precondition Required', // RFC 6585131429 : 'Too Many Requests', // RFC 6585132431 : 'Request Header Fields Too Large',// RFC 6585133500 : 'Internal Server Error',134501 : 'Not Implemented',135502 : 'Bad Gateway',136503 : 'Service Unavailable',137504 : 'Gateway Time-out',138505 : 'HTTP Version Not Supported',139506 : 'Variant Also Negotiates', // RFC 2295140507 : 'Insufficient Storage', // RFC 4918141509 : 'Bandwidth Limit Exceeded',142510 : 'Not Extended', // RFC 2774143511 : 'Network Authentication Required' // RFC 6585144};145146