diff options
| author | Alee14 <alee14498@gmail.com> | 2017-03-26 15:18:10 -0400 |
|---|---|---|
| committer | Alee14 <alee14498@gmail.com> | 2017-03-26 15:18:10 -0400 |
| commit | 29433e2f7dbd0e4a73d3c78ffe1005b922fb5982 (patch) | |
| tree | aa0ad3fe59468cbe452ee597e914839b68c01436 /node_modules/superagent/lib/node/agent.js | |
| parent | 878fefb4c4e1f12b804ae5c0def433fa873f4c8b (diff) | |
| download | AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.gz AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.bz2 AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.zip | |
Don't mind me i'm adding the discord.js files
Diffstat (limited to 'node_modules/superagent/lib/node/agent.js')
| -rw-r--r-- | node_modules/superagent/lib/node/agent.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/node_modules/superagent/lib/node/agent.js b/node_modules/superagent/lib/node/agent.js new file mode 100644 index 0000000..ad2a8f6 --- /dev/null +++ b/node_modules/superagent/lib/node/agent.js @@ -0,0 +1,90 @@ + +/** + * Module dependencies. + */ + +var CookieJar = require('cookiejar').CookieJar; +var CookieAccess = require('cookiejar').CookieAccessInfo; +var parse = require('url').parse; +var request = require('../..'); +var methods = require('methods'); + +/** + * Expose `Agent`. + */ + +module.exports = Agent; + +/** + * Initialize a new `Agent`. + * + * @api public + */ + +function Agent(options) { + if (!(this instanceof Agent)) return new Agent(options); + if (options) { + this._ca = options.ca; + this._key = options.key; + this._pfx = options.pfx; + this._cert = options.cert; + } + this.jar = new CookieJar; +} + +/** + * Save the cookies in the given `res` to + * the agent's cookie jar for persistence. + * + * @param {Response} res + * @api private + */ + +Agent.prototype._saveCookies = function(res){ + var cookies = res.headers['set-cookie']; + if (cookies) this.jar.setCookies(cookies); +}; + +/** + * Attach cookies when available to the given `req`. + * + * @param {Request} req + * @api private + */ + +Agent.prototype._attachCookies = function(req){ + var url = parse(req.url); + var access = CookieAccess(url.hostname, url.pathname, 'https:' == url.protocol); + var cookies = this.jar.getCookies(access).toValueString(); + req.cookies = cookies; +}; + +// generate HTTP verb methods +if (methods.indexOf('del') == -1) { + // create a copy so we don't cause conflicts with + // other packages using the methods package and + // npm 3.x + methods = methods.slice(0); + methods.push('del'); +} +methods.forEach(function(method){ + var name = method; + method = 'del' == method ? 'delete' : method; + + method = method.toUpperCase(); + Agent.prototype[name] = function(url, fn){ + var req = new request.Request(method, url); + req.ca(this._ca); + req.key(this._key); + req.pfx(this._pfx); + req.cert(this._cert); + + req.on('response', this._saveCookies.bind(this)); + req.on('redirect', this._saveCookies.bind(this)); + req.on('redirect', this._attachCookies.bind(this, req)); + this._attachCookies(req); + + fn && req.end(fn); + return req; + }; +}); |
