forked from coapjs/node-coap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (30 loc) · 1.05 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
const optionsConv = require('./lib/option_converter')
, Server = require('./lib/server')
, Agent = require('./lib/agent')
, net = require('net')
, URL = require('url')
, globalAgent = new Agent({ type: 'udp4' })
, globalAgentV6 = new Agent({ type: 'udp6' })
module.exports.request = function(url) {
var agent, req, ipv6
if (typeof url === 'string')
url = URL.parse(url)
ipv6 = net.isIPv6(url.hostname)
if (url.agent)
agent = url.agent
else if (url.agent === false && !ipv6)
agent = new Agent({ type: 'udp4' })
else if (url.agent === false && ipv6)
agent = new Agent({ type: 'udp6' })
else if (ipv6)
agent = globalAgentV6
else
agent = globalAgent
return agent.request(url)
}
module.exports.createServer = Server
module.exports.Agent = Agent
module.exports.globalAgent = globalAgent
module.exports.globalAgentIPv6 = globalAgentV6
module.exports.registerOption = optionsConv.registerOption
module.exports.registerFormat = optionsConv.registerFormat