-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
response-receiver.js
51 lines (46 loc) · 1.19 KB
/
response-receiver.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
'use strict';
const BaseReceiver = require('./base-receiver');
const debug = require('debug')('sockjs:response-receiver');
// Write stuff to response, using chunked encoding if possible.
class ResponseReceiver extends BaseReceiver {
constructor(request, response, options) {
super(request.socket);
this.max_response_size = options.response_limit;
this.delay_disconnect = true;
this.request = request;
this.response = response;
this.options = options;
this.curr_response_size = 0;
try {
this.request.socket.setKeepAlive(true, 5000);
} catch (x) {
// intentionally empty
}
}
sendFrame(payload) {
debug('sendFrame');
this.curr_response_size += payload.length;
let r = false;
try {
this.response.write(payload);
r = true;
} catch (x) {
// intentionally empty
}
if (this.max_response_size && this.curr_response_size >= this.max_response_size) {
this.close();
}
return r;
}
close() {
super.close(...arguments);
try {
this.response.end();
} catch (x) {
// intentionally empty
}
this.request = null;
this.response = null;
}
}
module.exports = ResponseReceiver;