Skip to content

Commit 801b327

Browse files
author
deiu
committed
Use the websocket scheme instead of http for live updates
1 parent 9b021e1 commit 801b327

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/handlers/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function handler (req, res, next) {
4242

4343
// Set live updates
4444
if (ldp.live) {
45-
res.header('Updates-Via', utils.uriBase(req))
45+
res.header('Updates-Via', req.protocol.replace(/^http/, 'ws') + '://' + req.get('host'))
4646
}
4747

4848
debug(req.originalUrl + ' on ' + req.hostname)

test/http.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var path = require('path')
88

99
var suffixAcl = '.acl'
1010
var suffixMeta = '.meta'
11-
var ldpServer = ldnode({
11+
var ldpServer = ldnode.createServer({
12+
live: true,
1213
root: path.join(__dirname, '/resources')
1314
})
1415
var server = supertest(ldpServer)
@@ -193,6 +194,11 @@ describe('HTTP APIs', function () {
193194
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Resource>; rel="type"/)
194195
.expect(200, done)
195196
})
197+
it('should have set Updates-Via to use WebSockets', function (done) {
198+
server.get('/sampleContainer/example1.ttl')
199+
.expect('updates-via', /wss?:\/\//)
200+
.expect(200, done)
201+
})
196202
it('should have set acl and describedBy Links for resource',
197203
function (done) {
198204
server.get('/sampleContainer/example1.ttl')
@@ -310,6 +316,11 @@ describe('HTTP APIs', function () {
310316
.expect(emptyResponse)
311317
.expect(200, done)
312318
})
319+
it('should have set Updates-Via to use WebSockets', function (done) {
320+
server.get('/sampleContainer/example1.ttl')
321+
.expect('updates-via', /wss?:\/\//)
322+
.expect(200, done)
323+
})
313324
it('should have set Link as Resource', function (done) {
314325
server.head('/sampleContainer/example1.ttl')
315326
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Resource>; rel="type"/)

0 commit comments

Comments
 (0)