Socket
Socket
Sign inDemoInstall

request

Package Overview
Dependencies
0
Maintainers
0
Versions
126
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.9.0

._main.js

6

._package.json

@@ -1,4 +0,4 @@

Mac OS X  2��ATTR���"�"com.macromates.caret{
column = 20;
line = 3;
Mac OS X  2��ATTR0yc��#�#com.macromates.caret{
column = 23;
line = 11;
}

@@ -16,4 +16,6 @@ // Copyright 2010-2011 Mikeal Rogers

var http = require('http')
, https = require('https')
, url = require('url')
, sys = require('sys')
, util = require('util')
, stream = require('stream')
, qs = require('querystring')

@@ -28,4 +30,27 @@ ;

function request (options, callback) {
if (!options.callback) options.callback = callback;
var globalPool = {};
var Request = function (options) {
stream.Stream.call(this);
this.readable = true;
this.writable = true;
for (i in options) {
this[i] = options[i];
}
if (!this.pool) this.pool = globalPool;
}
util.inherits(Request, stream.Stream);
Request.prototype.getAgent = function (host, port) {
if (!this.pool[host+':'+port]) {
this.pool[host+':'+port] = new this.httpModule.Agent({host:host, port:port});
}
return this.pool[host+':'+port];
}
Request.prototype.pipe = function (dest) {
this.dest = dest;
}
Request.prototype.request = function () {
var options = this;
if (options.url) {

@@ -70,12 +95,15 @@ // People use this property instead all the time so why not just support it.

if (options.bodyStream) {
sys.error('options.bodyStream is deprecated. use options.reponseBodyStream instead.');
options.responseBodyStream = options.bodyStream;
if (options.bodyStream || options.responseBodyStream) {
console.error('options.bodyStream and options.responseBodyStream is deprecated. You should now send the request object to stream.pipe()');
this.pipe(options.responseBodyStream || options.bodyStream)
}
if (!options.client) {
if (options.proxy) {
options.client = http.createClient(options.proxy.port, options.proxy.hostname, options.proxy.protocol === 'https:');
} else {
options.client = http.createClient(options.uri.port, options.uri.hostname, options.uri.protocol === 'https:');
}
if (options.proxy) {
options.port = options.proxy.port;
options.host = options.proxy.hostname;
// options.client = http.createClient(options.proxy.port, options.proxy.hostname, options.proxy.protocol === 'https:');
} else {
options.port = options.uri.port;
options.host = options.uri.hostname;
// options.client = http.createClient(options.uri.port, options.uri.hostname, options.uri.protocol === 'https:');
}

@@ -87,3 +115,3 @@

}
var clientErrorHandler = function (error) {

@@ -94,3 +122,2 @@ if (setHost) delete options.headers.host;

};
options.client.addListener('error', clientErrorHandler);

@@ -104,6 +131,6 @@ if (options.uri.auth && !options.headers.authorization) {

options.fullpath = options.uri.href.replace(options.uri.protocol + '//' + options.uri.host, '');
if (options.fullpath.length === 0) options.fullpath = '/';
options.path = options.uri.href.replace(options.uri.protocol + '//' + options.uri.host, '');
if (options.path.length === 0) options.path = '/';
if (options.proxy) options.fullpath = (options.uri.protocol + '//' + options.uri.host + options.fullpath);
if (options.proxy) options.path = (options.uri.protocol + '//' + options.uri.host + options.path);

@@ -141,9 +168,18 @@ if (options.json) {

}
options.httpModule =
{"http:":http, "https:":https}[options.proxy ? options.proxy.protocol : options.uri.protocol]
if (!options.httpModule) throw new Error("Invalid protocol");
if (options.maxSockets) {
options.agent = options.getAgent(options.host, options.port);
options.agent.maxSockets = options.maxSockets;
}
if (options.pool.maxSockets) {
options.agent = options.getAgent(options.host, options.port);
options.agent.maxSockets = options.pool.maxSockets;
}
options.request = options.client.request(options.method, options.fullpath, options.headers);
options.request.addListener("response", function (response) {
options.req = options.httpModule.request(options, function (response) {
if (setHost) delete options.headers.host;
response.on("end", function () {
options.client.removeListener("error", clientErrorHandler);
});

@@ -153,5 +189,7 @@ if (response.statusCode >= 300 &&

options.followRedirect &&
options.method !== 'PUT' &&
options.method !== 'POST' &&
response.headers.location) {
if (options._redirectsFollowed >= options.maxRedirects) {
client.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop."));
options.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop."));
}

@@ -163,3 +201,3 @@ options._redirectsFollowed += 1;

options.uri = response.headers.location;
delete options.client;
delete options.req;
if (options.headers) {

@@ -173,4 +211,4 @@ delete options.headers.host;

if (options.encoding) response.setEncoding(options.encoding);
if (options.responseBodyStream) {
sys.pump(response, options.responseBodyStream);
if (options.dest) {
response.pipe(options.dest);
if (options.onResponse) options.onResponse(null, response);

@@ -191,16 +229,61 @@ if (options.callback) options.callback(null, response, options.responseBodyStream);

}
});
})
options.req.on('error', clientErrorHandler);
this.once('pipe', function (src) {
options.src = src;
})
process.nextTick(function () {
if (options.body) {
options.req.write(options.body);
options.req.end();
} else if (options.requestBodyStream) {
console.warn("options.requestBodyStream is deprecated, please pass the request object to stream.pipe.")
options.requestBodyStream.pipe(options);
} else if (!options.src) {
options.req.end();
}
})
}
if (options.body) {
options.request.write(options.body);
options.request.end();
} else if (options.requestBodyStream) {
sys.pump(options.requestBodyStream, options.request);
} else {
options.request.end();
}
Request.prototype.write = function (chunk) {
if (!this.req) throw new Error("This request has been piped before http.request() was called.");
this.req.write(chunk);
}
Request.prototype.end = function () {
this.req.end();
}
function request (options, callback) {
if (callback) options.callback = callback;
var r = new Request(options);
r.request();
return r;
}
module.exports = request;
request.defaults = function (options) {
var def = function (method) {
var d = function (opts, callback) {
for (i in options) {
if (!opts[i]) opts[i] = options[i];
return method(opts, callback);
}
}
return d;
}
de = def(request);
de.get = def(request.get);
de.post = def(request.post);
de.put = def(request.put);
de.head = def(request.head);
return d;
}
request.get = request;

@@ -210,3 +293,3 @@ request.post = function (options, callback) {

if (!options.body && !options.requestBodyStream && !options.json && !options.multipart) {
sys.error("HTTP POST requests need a body or requestBodyStream");
console.error("HTTP POST requests need a body or requestBodyStream");
}

@@ -218,3 +301,3 @@ request(options, callback);

if (!options.body && !options.requestBodyStream && !options.json && !options.multipart) {
sys.error("HTTP PUT requests need a body or requestBodyStream");
console.error("HTTP PUT requests need a body or requestBodyStream");
}

@@ -221,0 +304,0 @@ request(options, callback);

{ "name" : "request"
, "description" : "Simplified HTTP request client."
, "tags" : ["http", "simple", "util", "utility"]
, "version" : "1.2.0"
, "version" : "1.9.0"
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>"

@@ -12,4 +12,4 @@ , "repository" :

{ "web" : "http://github.com/mikeal/request/issues" }
, "engines" : ["node < 0.3.6"]
, "engines" : ["node >= 0.3.6"]
, "main" : "./main"
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTR���!�!com.macromates.caret{
Mac OS X  2��ATTR0yg��!�!com.macromates.caret{
column = 0;
line = 2;
line = 5;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTR���#�#com.macromates.caret{
column = 25;
line = 89;
Mac OS X  2��ATTR0yi��"�"com.macromates.caret{
column = 7;
line = 79;
}

@@ -1,4 +0,4 @@

Mac OS X  2��ATTR� ��#�#com.macromates.caret{
column = 16;
line = 29;
Mac OS X  2��ATTR0yk��"�"com.macromates.caret{
column = 0;
line = 11;
}
var server = require('./server')
, events = require('events')
, stream = require('stream')
, assert = require('assert')

@@ -10,3 +11,3 @@ , request = require('../main.js')

var createPostStream = function (text) {
var postStream = new events.EventEmitter();
var postStream = new stream.Stream();
postStream.writeable = true;

@@ -13,0 +14,0 @@ postStream.readable = true;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc