Skip to content

Commit ced38bc

Browse files
author
Andrey Litvinovich
committed
Add http2 support.
1 parent 8f48255 commit ced38bc

File tree

9 files changed

+786
-13
lines changed

9 files changed

+786
-13
lines changed

config.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
relativeStaticUrl: "/s",
2121
DEBUG: false,
2222

23+
SPDY_AGENT_DEFAULT_PORT: 443,
2324
WHITELIST_URL: 'https://iframely.com/qa/whitelist.json',
2425
WHITELIST_URL_RELOAD_PERIOD: 60 * 60 * 1000, // will reload WL every hour, if no local files are found in /whitelist folder
2526

lib/core.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var _ = require('underscore'),
44
request = require('request'),
5+
spdy = require('spdy'),
56
urlLib = require('url');
67

78
var pluginUtils = require('./loader/utils'),
@@ -1069,7 +1070,7 @@
10691070
var link2 = canonical.replace(/\/+$/, '');
10701071

10711072
if (link1 === link2 && link.rel.indexOf(CONFIG.R.oembed) == -1) {
1072-
// allow the canonical links for oEmbeds, as such mistakes are usually made for OG and Twitter:
1073+
// allow the canonical links for oEmbeds, as such mistakes are usually made for OG and Twitter:
10731074
// if publisher has oEmbed, he is most likely to have the valid embed codes
10741075
link.error = "Removed canonical link";
10751076
}
@@ -1408,6 +1409,12 @@
14081409
requestWrapper(options_from_plugin, options, callback);
14091410
}
14101411

1412+
options.agent = spdy.createAgent({
1413+
host: urlLib.parse(uri).hostname,
1414+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
1415+
rejectUnauthorized: false
1416+
});
1417+
14111418
var requiredPlugins = pluginsSet.initialPlugins,
14121419
pluginsUrlMatches = pluginsSet.pluginsUrlMatches,
14131420
usedDomains = pluginsSet.usedDomains,
@@ -1621,4 +1628,4 @@
16211628

16221629
exports.getOembed = oembedUtils.getOembed;
16231630

1624-
})(exports);
1631+
})(exports);

lib/utils.js

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var events = require('events');
22
var request = require('request');
3+
var spdy = require('spdy');
4+
var URL = require('url');
35
var zlib = require('zlib');
46
var iconv = require('iconv-lite');
57
var async = require('async');
@@ -91,8 +93,15 @@ var getUrl = exports.getUrl = function(url, options) {
9193

9294
var supportGzip = !process.version.match(/^v0\.8/);
9395

96+
var agent = spdy.createAgent({
97+
host: URL.parse(url).hostname,
98+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
99+
rejectUnauthorized: false
100+
});
101+
94102
var r = request(prepareRequestOptions({
95103
uri: url,
104+
agent: agent,
96105
method: 'GET',
97106
headers: {
98107
'User-Agent': options.user_agent || CONFIG.USER_AGENT,
@@ -167,9 +176,15 @@ var getHead = function(url, options) {
167176

168177
process.nextTick(function() {
169178
try {
179+
var agent = spdy.createAgent({
180+
host: URL.parse(url).hostname,
181+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
182+
rejectUnauthorized: false
183+
});
170184

171185
var r = request(prepareRequestOptions({
172186
uri: url,
187+
agent: agent,
173188
method: 'HEAD',
174189
headers: {
175190
'User-Agent': CONFIG.USER_AGENT,
@@ -650,8 +665,15 @@ exports.sendLogToWhitelist = function(uri, meta, oembed, oembedLinks, whitelistR
650665
data.oembed = oembedHref;
651666
}
652667

668+
var agent = spdy.createAgent({
669+
host: URL.parse(CONFIG.WHITELIST_LOG_URL).hostname,
670+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
671+
rejectUnauthorized: false
672+
});
673+
653674
request({
654675
uri: CONFIG.WHITELIST_LOG_URL,
676+
agent: agent,
655677
method: 'GET',
656678
qs: data
657679
})
@@ -823,8 +845,15 @@ var getUriStatus = function(uri, options, cb) {
823845

824846
try {
825847

848+
var agent = spdy.createAgent({
849+
host: URL.parse(uri).hostname,
850+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
851+
rejectUnauthorized: false
852+
});
853+
826854
var r = request(prepareRequestOptions({
827855
uri: uri,
856+
agent: agent,
828857
method: 'GET',
829858
headers: {
830859
'User-Agent': CONFIG.USER_AGENT

lib/whitelist.js

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
crypto = require('crypto'),
77
_ = require('underscore'),
88
request = require('request'),
9+
spdy = require('spdy'),
10+
URL = require('url'),
911
utils = require('./utils'),
1012
logging = require('../logging');
1113

@@ -328,8 +330,15 @@
328330

329331
logging.log("Loading whitelist from " + CONFIG.WHITELIST_URL);
330332

333+
var agent = spdy.createAgent({
334+
host: URL.parse(CONFIG.WHITELIST_URL).hostname,
335+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
336+
rejectUnauthorized: false
337+
});
338+
331339
var options = {
332340
uri: CONFIG.WHITELIST_URL,
341+
agent: agent,
333342
json: true,
334343
qs: {
335344
domain: CONFIG.baseAppUrl && CONFIG.baseAppUrl.replace(/.+\/\//, ''),

modules/tests-ui/utils.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var _ = require('underscore');
22
var FeedParser = require('feedparser');
33
var request = require('request');
4+
var spdy = require('spdy');
45
var async = require('async');
56
var url = require('url');
67

@@ -74,7 +75,13 @@ var fetchFeedUrls = exports.fetchFeedUrls = function(feedUrl, options, cb) {
7475
cb(error, urls);
7576
};
7677

77-
request(feedUrl)
78+
var agent = spdy.createAgent({
79+
host: url.parse(feedUrl, true).hostname,
80+
port: CONFIG.SPDY_AGENT_DEFAULT_PORT,
81+
rejectUnauthorized: false
82+
});
83+
84+
request(feedUrl, {agent: agent})
7885
.pipe(new FeedParser({addmeta: false}))
7986
.on('error', function(error) {
8087
_cb(error);

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
"moment": "2.19.3",
3737
"node-cache": "1.*",
3838
"parse-iso-duration": "1.0.0",
39+
"patch-package": "^6.1.2",
3940
"readabilitySAX": "1.6.1",
4041
"redis": "2.7.1",
4142
"request": "^2.88.0",
4243
"sax": "1.2.2",
4344
"send": "0.16.1",
45+
"spdy": "^4.0.0",
4446
"underscore": "1.8.3"
4547
},
4648
"devDependencies": {
@@ -55,6 +57,7 @@
5557
"iframely-proxy-plugins": true,
5658
"main": "./lib/core",
5759
"scripts": {
60+
"prepare": "patch-package",
5861
"test": "vows test/main.js --isolate --spec && npm run test-e2e",
5962
"test-e2e": "NODE_ENV=test PORT=8080 mocha --exit test/e2e.js"
6063
},

patches/spdy-transport+3.0.0.patch

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git a/node_modules/spdy-transport/lib/spdy-transport/protocol/base/utils.js b/node_modules/spdy-transport/lib/spdy-transport/protocol/base/utils.js
2+
index 72a380f..042199e 100644
3+
--- a/node_modules/spdy-transport/lib/spdy-transport/protocol/base/utils.js
4+
+++ b/node_modules/spdy-transport/lib/spdy-transport/protocol/base/utils.js
5+
@@ -45,13 +45,13 @@ exports.addHeaderLine = function addHeaderLine (field, value, dest) {
6+
7+
switch (field) {
8+
// Array headers:
9+
- case 'set-cookie':
10+
- if (dest[field] !== undefined) {
11+
- dest[field].push(value)
12+
- } else {
13+
- dest[field] = [ value ]
14+
- }
15+
- break
16+
+ // case 'set-cookie':
17+
+ // if (dest[field] !== undefined) {
18+
+ // dest[field].push(value)
19+
+ // } else {
20+
+ // dest[field] = [ value ]
21+
+ // }
22+
+ // break
23+
24+
/* eslint-disable max-len */
25+
// list is taken from:
26+
@@ -74,6 +74,7 @@ exports.addHeaderLine = function addHeaderLine (field, value, dest) {
27+
}
28+
break
29+
30+
+ case 'set-cookie':
31+
case 'cookie':
32+
// make semicolon-separated list
33+
if (dest[field] !== undefined) {

server.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var spdy = require('spdy');
12
var sysUtils = require('./utils');
23
var app = require('./app');
34

@@ -7,7 +8,7 @@ var server = app.listen(process.env.PORT || CONFIG.port, process.env.HOST || CON
78
});
89

910
if (CONFIG.ssl) {
10-
require('https').createServer(CONFIG.ssl, app).listen(CONFIG.ssl.port);
11+
spdy.createServer(CONFIG.ssl, app).listen(CONFIG.ssl.port);
1112
}
1213

1314
console.log('');
@@ -24,4 +25,4 @@ if (!CONFIG.DEBUG) {
2425
});
2526
}
2627

27-
module.exports = server;
28+
module.exports = server;

0 commit comments

Comments
 (0)