-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
56 lines (43 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var Agent = require('./lib/agent')
var Request = require('./lib/request')
var Response = require('./lib/response')
var Url = require('./lib/url')
var send = require('./lib/send')
exports = module.exports = function(opts) {
opts = opts || {}
var a = exports.basic()
function use(name, optional) {
if (opts[name] === false) return
if (optional && !opts[name]) return
a.use(exports[name](opts[name]))
}
use('cookies', true)
use('redirects')
use('unzip')
if (typeof opts.parser == 'function')
a.use(opts.parser)
else
use('parser')
use('serialize')
use('handler')
use('timeout', true)
return a
}
/**
* Create a "basic" agent
*
* @api public
*/
exports.basic = function() {
return new Agent(send)
}
exports.Url = Url
exports.Agent = Agent
exports.Request = Request
exports.Response = Response
// export middlewares
require('fs')
.readdirSync(require('path').join(__dirname, 'lib/middlewares'))
.forEach(function(file) {
exports[file.slice(0, file.length - 3)] = require('./lib/middlewares/' + file)
})