xref: /unit/src/nodejs/unit-http/websocket_router_request.js (revision 1132:9ac5b5f33ed9)
1/************************************************************************
2 *  Copyright 2010-2015 Brian McKelvey.
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *  Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 ***********************************************************************/
16
17var util = require('util');
18var EventEmitter = require('events').EventEmitter;
19
20function WebSocketRouterRequest(webSocketRequest, resolvedProtocol) {
21    // Superclass Constructor
22    EventEmitter.call(this);
23
24    this.webSocketRequest = webSocketRequest;
25    if (resolvedProtocol === '____no_protocol____') {
26        this.protocol = null;
27    }
28    else {
29        this.protocol = resolvedProtocol;
30    }
31    this.origin = webSocketRequest.origin;
32    this.resource = webSocketRequest.resource;
33    this.resourceURL = webSocketRequest.resourceURL;
34    this.httpRequest = webSocketRequest.httpRequest;
35    this.remoteAddress = webSocketRequest.remoteAddress;
36    this.webSocketVersion = webSocketRequest.webSocketVersion;
37    this.requestedExtensions = webSocketRequest.requestedExtensions;
38    this.cookies = webSocketRequest.cookies;
39}
40
41util.inherits(WebSocketRouterRequest, EventEmitter);
42
43WebSocketRouterRequest.prototype.accept = function(origin, cookies) {
44    var connection = this.webSocketRequest.accept(this.protocol, origin, cookies);
45    this.emit('requestAccepted', connection);
46    return connection;
47};
48
49WebSocketRouterRequest.prototype.reject = function(status, reason, extraHeaders) {
50    this.webSocketRequest.reject(status, reason, extraHeaders);
51    this.emit('requestRejected', this);
52};
53
54module.exports = WebSocketRouterRequest;
55