1 /************************************************************************
2 * Copyright 2010-2015 Brian McKelvey.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 ***********************************************************************/
17 var util = require('util');
18 var EventEmitter = require('events').EventEmitter;
20 function WebSocketRouterRequest(webSocketRequest, resolvedProtocol) {
21 // Superclass Constructor
22 EventEmitter.call(this);
24 this.webSocketRequest = webSocketRequest;
25 if (resolvedProtocol === '____no_protocol____') {
29 this.protocol = resolvedProtocol;
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;
41 util.inherits(WebSocketRouterRequest, EventEmitter);
43 WebSocketRouterRequest.prototype.accept = function(origin, cookies) {
44 var connection = this.webSocketRequest.accept(this.protocol, origin, cookies);
45 this.emit('requestAccepted', connection);
49 WebSocketRouterRequest.prototype.reject = function(status, reason, extraHeaders) {
50 this.webSocketRequest.reject(status, reason, extraHeaders);
51 this.emit('requestRejected', this);
54 module.exports = WebSocketRouterRequest;