Make handleRequest optional in WebSocketResources

If no request handler is provided, respond with 404 to any incoming
requests.
This commit is contained in:
lilia 2015-07-28 13:22:06 -07:00
parent cd363bd84d
commit 637cbcbf99
2 changed files with 16 additions and 2 deletions

View file

@ -38563,7 +38563,14 @@ TextSecureWebSocket = function (url, opts) {
);
};
window.WebSocketResource = function(socket, handleRequest, keepalive) {
window.WebSocketResource = function(socket, opts) {
opts = opts || {};
var handleRequest = opts.handleRequest;
if (typeof handleRequest !== 'function') {
handleRequest = function(request) {
request.respond(404);
};
}
this.sendRequest = function(options) {
return new OutgoingWebSocketRequest(options, socket);
};

View file

@ -92,7 +92,14 @@
);
};
window.WebSocketResource = function(socket, handleRequest, keepalive) {
window.WebSocketResource = function(socket, opts) {
opts = opts || {};
var handleRequest = opts.handleRequest;
if (typeof handleRequest !== 'function') {
handleRequest = function(request) {
request.respond(404);
};
}
this.sendRequest = function(options) {
return new OutgoingWebSocketRequest(options, socket);
};