aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-11-14 20:03:04 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-11-16 20:29:26 +0100
commit49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed (patch)
tree68c59d67637a297d513e07ea96ba236a7f0cd43b /server/middlewares/pods.js
parent41b5da1d8cb41f5c49f0e0a01a54106c9a5925dd (diff)
downloadPeerTube-49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed.tar.gz
PeerTube-49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed.tar.zst
PeerTube-49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed.zip
Pod URL -> pod host. HTTPS is required to make friends.
Reason: in a network with mix http/https pods, https pods won't be able to play videos from http pod (insecure requests).
Diffstat (limited to 'server/middlewares/pods.js')
-rw-r--r--server/middlewares/pods.js50
1 files changed, 22 insertions, 28 deletions
diff --git a/server/middlewares/pods.js b/server/middlewares/pods.js
index 6e0874a76..487ea1259 100644
--- a/server/middlewares/pods.js
+++ b/server/middlewares/pods.js
@@ -1,38 +1,36 @@
1'use strict' 1'use strict'
2 2
3const urlModule = require('url') 3const constants = require('../initializers/constants')
4
5const logger = require('../helpers/logger')
6 4
7const podsMiddleware = { 5const podsMiddleware = {
8 setBodyUrlsPort, 6 setBodyHostsPort,
9 setBodyUrlPort 7 setBodyHostPort
10} 8}
11 9
12function setBodyUrlsPort (req, res, next) { 10function setBodyHostsPort (req, res, next) {
13 for (let i = 0; i < req.body.urls.length; i++) { 11 for (let i = 0; i < req.body.hosts.length; i++) {
14 const urlWithPort = getUrlWithPort(req.body.urls[i]) 12 const hostWithPort = getHostWithPort(req.body.hosts[i])
15 13
16 // Problem with the url parsing? 14 // Problem with the url parsing?
17 if (urlWithPort === null) { 15 if (hostWithPort === null) {
18 return res.sendStatus(500) 16 return res.sendStatus(500)
19 } 17 }
20 18
21 req.body.urls[i] = urlWithPort 19 req.body.hosts[i] = hostWithPort
22 } 20 }
23 21
24 return next() 22 return next()
25} 23}
26 24
27function setBodyUrlPort (req, res, next) { 25function setBodyHostPort (req, res, next) {
28 const urlWithPort = getUrlWithPort(req.body.url) 26 const hostWithPort = getHostWithPort(req.body.host)
29 27
30 // Problem with the url parsing? 28 // Problem with the url parsing?
31 if (urlWithPort === null) { 29 if (hostWithPort === null) {
32 return res.sendStatus(500) 30 return res.sendStatus(500)
33 } 31 }
34 32
35 req.body.url = urlWithPort 33 req.body.host = hostWithPort
36 34
37 return next() 35 return next()
38} 36}
@@ -43,20 +41,16 @@ module.exports = podsMiddleware
43 41
44// --------------------------------------------------------------------------- 42// ---------------------------------------------------------------------------
45 43
46function getUrlWithPort (url) { 44function getHostWithPort (host) {
47 const urlObj = urlModule.parse(url) 45 const splitted = host.split(':')
48 46
49 // Add the port if it is not specified 47 console.log(splitted)
50 if (urlObj.port === null) { 48 // The port was not specified
51 if (urlObj.protocol === 'http:') { 49 if (splitted.length === 1) {
52 return url + ':80' 50 if (constants.REMOTE_SCHEME.HTTP === 'https') return host + ':443'
53 } else if (urlObj.protocol === 'https:') { 51
54 return url + ':443' 52 return host + ':80'
55 } else {
56 logger.error('Unknown url protocol: ' + urlObj.protocol)
57 return null
58 }
59 } 53 }
60 54
61 return url 55 return host
62} 56}