Socket
Socket
Sign inDemoInstall

superagent-defaults

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superagent-defaults - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

52

lib/context.js

@@ -7,2 +7,3 @@ /**

var methods = require('./methods');
var protoMethods = Object.keys(request.Request.prototype);

@@ -23,31 +24,26 @@ /**

if (!(this instanceof Context)) return new Context(superagent);
this.headers = [];
this.authCredentials = {};
this.request = superagent || request;
this.stack = []; // store the default operation on the context
}
/**
* Set default auth credentials
*
* @api public
*/
Context.prototype.auth = function (user, pass) {
this.authCredentials.user = user;
this.authCredentials.pass = pass;
};
// setup methods for context
/**
* Add a default header to the context
*
* @api public
*/
each(protoMethods, function(m) {
if (methods.indexOf(m) > -1) { // m is a HttpVerb method , don't record operation
return;
}
Context.prototype.set = function() {
this.headers.push(arguments);
return this;
};
Context.prototype[m] = function() {
this.stack.push({
method: m,
args: [].slice.call(arguments)
});
return this;
}
});
/**
* Set the default headers on the req
* apply the operations on the context to real Request instance
*

@@ -57,5 +53,5 @@ * @api private

Context.prototype.applyHeaders = function(req) {
each(this.headers, function(header) {
req.set.apply(req, header);
Context.prototype.applyStack = function(req) {
this.stack.forEach(function(op){ // op -> operation
req[op.method].apply(req,op.args);
});

@@ -72,12 +68,6 @@ };

var req = this.request(method, url);
var auth = this.authCredentials;
// Do the attaching here
this.applyHeaders(req);
this.applyStack(req);
// Call superagent's auth method
if(auth.hasOwnProperty('user') && auth.hasOwnProperty('pass')) {
req.auth(auth.user, auth.pass);
}
// Tell the listeners we've created a new request

@@ -84,0 +74,0 @@ this.emit('request', req);

{
"name": "superagent-defaults",
"version": "0.1.11",
"version": "0.1.12",
"description": "Create some defaults for superagent requests",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc