Sha256: 68dc9ae822fd0692d450202a8738a01ef08f2e1587ad6c95441cf5125dfe28f3

Contents?: true

Size: 1.84 KB

Versions: 34

Compression:

Stored size: 1.84 KB

Contents

var ClientRequest = require('./lib/request')
var response = require('./lib/response')
var extend = require('xtend')
var statusCodes = require('builtin-status-codes')
var url = require('url')

var http = exports

http.request = function (opts, cb) {
	if (typeof opts === 'string')
		opts = url.parse(opts)
	else
		opts = extend(opts)

	// 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 || '/'

	// Necessary for IPv6 addresses
	if (host && host.indexOf(':') !== -1)
		host = '[' + host + ']'

	// This may be a relative url. The browser should always be able to interpret it correctly.
	opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
	opts.method = (opts.method || 'GET').toUpperCase()
	opts.headers = opts.headers || {}

	// Also valid opts.auth, opts.mode

	var req = new ClientRequest(opts)
	if (cb)
		req.on('response', cb)
	return req
}

http.get = function get (opts, cb) {
	var req = http.request(opts, cb)
	req.end()
	return req
}

http.ClientRequest = ClientRequest
http.IncomingMessage = response.IncomingMessage

http.Agent = function () {}
http.Agent.defaultMaxSockets = 4

http.globalAgent = new http.Agent()

http.STATUS_CODES = statusCodes

http.METHODS = [
	'CHECKOUT',
	'CONNECT',
	'COPY',
	'DELETE',
	'GET',
	'HEAD',
	'LOCK',
	'M-SEARCH',
	'MERGE',
	'MKACTIVITY',
	'MKCOL',
	'MOVE',
	'NOTIFY',
	'OPTIONS',
	'PATCH',
	'POST',
	'PROPFIND',
	'PROPPATCH',
	'PURGE',
	'PUT',
	'REPORT',
	'SEARCH',
	'SUBSCRIBE',
	'TRACE',
	'UNLOCK',
	'UNSUBSCRIBE'
]

Version data entries

34 entries across 33 versions & 11 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/stream-http/index.js
disco_app-0.18.0 test/dummy/node_modules/stream-http/index.js
disco_app-0.18.2 test/dummy/node_modules/stream-http/index.js
disco_app-0.16.1 test/dummy/node_modules/stream-http/index.js
disco_app-0.15.2 test/dummy/node_modules/stream-http/index.js
disco_app-0.18.4 test/dummy/node_modules/stream-http/index.js
disco_app-0.18.1 test/dummy/node_modules/stream-http/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/stream-http/index.js
disco_app-0.14.0 test/dummy/node_modules/stream-http/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/stream-http/index.js
tang-0.2.1 spec/tang_app/node_modules/stream-http/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/stream-http/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/stream-http/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/stream-http/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/stream-http/index.js
tang-0.2.0 spec/tang_app/node_modules/stream-http/index.js
tang-0.1.0 spec/tang_app/node_modules/stream-http/index.js
tang-0.0.9 spec/tang_app/node_modules/stream-http/index.js
enju_library-0.3.8 spec/dummy/node_modules/stream-http/index.js
ilog-0.4.1 node_modules/stream-http/index.js