forked from socketio/socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.js
70 lines (55 loc) · 1.12 KB
/
http.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
62
63
64
65
66
67
68
69
70
/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <[email protected]>
* MIT Licensed
*/
/**
* Module requirements.
*/
const Transport = require('../transport')
, parser = require('../parser');
/**
* Export the constructor.
*/
exports = module.exports = HTTPTransport;
/**
* HTTP interface constructor. For all non-websocket transports.
*
* @api public
*/
function HTTPTransport (mng, data) {
Transport.call(this, mng, data);
};
/**
* Inherits from Transport.
*/
HTTPTransport.prototype.__proto__ = Transport.prototype;
/**
* Handles a request.
*
* @api private
*/
HTTPTransport.prototype.handleRequest = function (req) {
if (req.method == 'POST') {
var buffer = ''
, res = req.res;
res.on('data', function (data) {
buffer += data;
});
res.on('end', function () {
self.onData(buffer);
});
} else {
this.response = req.res;
this.open = true;
Transport.prototype.handleRequest.call(this, req);
}
};
/**
* Writes a payload of messages
*
* @api private
*/
HTTPTransport.prototype.payload = function (msgs) {
this.write(parser.encodePayload(msgs));
};