-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest-handler.js
61 lines (49 loc) · 1.19 KB
/
request-handler.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
57
58
59
60
61
var request = require('request');
var _ = require('underscore');
module.exports = (function () {
'use strict';
function RequestHandler (config) {
config = config || {};
this.defaultRequest = request.defaults(
_.defaults(
config,
{
followRedirect: config.followRedirect,
maxRedirects: config.maxRedirects,
strictSSL: config.strictSSL,
timeout: config.timeout,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36',
'Accept-Language': 'en',
'Accept': '*/*',
'Connection': 'close',
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
},
method: 'GET',
lookup: config.dnsResolver,
pool: false,
gzip: false
}
)
);
}
RequestHandler.prototype.stream = function (url, options) {
_.extend(
options,
{
url: url
}
);
if (options.compression === true) {
options.headers = {
'Accept-Encoding': 'gzip, deflate'
};
options.gzip = true;
}
var requestStream = this.defaultRequest(options);
requestStream.noDelay = true;
return requestStream;
};
return RequestHandler;
})();