-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
xhr-polling.js
61 lines (55 loc) · 1.43 KB
/
xhr-polling.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
'use strict';
const ResponseReceiver = require('./response-receiver');
const Session = require('../session');
const middleware = require('../middleware');
const xhr = require('./xhr');
class XhrPollingReceiver extends ResponseReceiver {
constructor(req, res, options) {
super(req, res, options);
this.protocol = 'xhr-polling';
this.max_response_size = 1;
}
sendFrame(payload) {
return super.sendFrame(payload + '\n');
}
}
function xhr_poll(req, res, _head, next) {
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
res.writeHead(200);
Session.register(req, this, new XhrPollingReceiver(req, res, this.options));
next();
}
module.exports = {
routes: [
{
method: 'POST',
path: '/xhr',
handlers: [middleware.h_sid, middleware.h_no_cache, middleware.xhr_cors, xhr_poll],
transport: true
},
{
method: 'OPTIONS',
path: '/xhr',
handlers: [middleware.h_sid, middleware.xhr_cors, middleware.xhr_options],
transport: true
},
{
method: 'POST',
path: '/xhr_send',
handlers: [
middleware.h_sid,
middleware.h_no_cache,
middleware.xhr_cors,
middleware.expect_xhr,
xhr.xhr_send
],
transport: true
},
{
method: 'OPTIONS',
path: '/xhr_send',
handlers: [middleware.h_sid, middleware.xhr_cors, middleware.xhr_options],
transport: true
}
]
};