WebSocketRouterRequest.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. var util = require('util');
  17. var EventEmitter = require('events').EventEmitter;
  18. function WebSocketRouterRequest(webSocketRequest, resolvedProtocol) {
  19. // Superclass Constructor
  20. EventEmitter.call(this);
  21. this.webSocketRequest = webSocketRequest;
  22. if (resolvedProtocol === '____no_protocol____') {
  23. this.protocol = null;
  24. }
  25. else {
  26. this.protocol = resolvedProtocol;
  27. }
  28. this.origin = webSocketRequest.origin;
  29. this.resource = webSocketRequest.resource;
  30. this.resourceURL = webSocketRequest.resourceURL;
  31. this.httpRequest = webSocketRequest.httpRequest;
  32. this.remoteAddress = webSocketRequest.remoteAddress;
  33. this.webSocketVersion = webSocketRequest.webSocketVersion;
  34. this.requestedExtensions = webSocketRequest.requestedExtensions;
  35. this.cookies = webSocketRequest.cookies;
  36. }
  37. util.inherits(WebSocketRouterRequest, EventEmitter);
  38. WebSocketRouterRequest.prototype.accept = function(origin, cookies) {
  39. var connection = this.webSocketRequest.accept(this.protocol, origin, cookies);
  40. this.emit('requestAccepted', connection);
  41. return connection;
  42. };
  43. WebSocketRouterRequest.prototype.reject = function(status, reason, extraHeaders) {
  44. this.webSocketRequest.reject(status, reason, extraHeaders);
  45. this.emit('requestRejected', this);
  46. };
  47. module.exports = WebSocketRouterRequest;