From bb65dcf2c4c4d7c6b63ef5dbe56b399dbc53fa37 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 22 Nov 2011 02:21:30 +0000 Subject: [PATCH] Servers should always return supportedConnectionTypes. --- javascript/protocol/client.js | 12 +++++------- javascript/protocol/server.js | 22 ++++++++++------------ lib/faye/protocol/client.rb | 4 ++-- lib/faye/protocol/server.rb | 16 +++++++--------- spec/javascript/server/handshake_spec.js | 12 ------------ spec/ruby/server/handshake_spec.rb | 12 ------------ 6 files changed, 24 insertions(+), 54 deletions(-) diff --git a/javascript/protocol/client.js b/javascript/protocol/client.js index 0e0ddda9..88625a8a 100644 --- a/javascript/protocol/client.js +++ b/javascript/protocol/client.js @@ -98,13 +98,11 @@ Faye.Client = Faye.Class({ this._clientId = response.clientId; var connectionTypes = response.supportedConnectionTypes; - if (connectionTypes) { - Faye.each(this._disabled, function(feature) { - var index = Faye.indexOf(connectionTypes, feature); - if (index >= 0) connectionTypes.splice(index, 1); - }, this); - this._selectTransport(connectionTypes); - } + Faye.each(this._disabled, function(feature) { + var index = Faye.indexOf(connectionTypes, feature); + if (index >= 0) connectionTypes.splice(index, 1); + }, this); + this._selectTransport(connectionTypes); this.info('Handshake successful: ?', this._clientId); diff --git a/javascript/protocol/server.js b/javascript/protocol/server.js index e2a337ba..75c1a0e2 100644 --- a/javascript/protocol/server.js +++ b/javascript/protocol/server.js @@ -139,18 +139,16 @@ Faye.Server = Faye.Class({ var clientConns = message.supportedConnectionTypes, commonConns; - if (!local) { - response.supportedConnectionTypes = Faye.CONNECTION_TYPES; - - if (clientConns) { - commonConns = Faye.filter(clientConns, function(conn) { - return Faye.indexOf(Faye.CONNECTION_TYPES, conn) >= 0; - }); - if (commonConns.length === 0) - response.error = Faye.Error.conntypeMismatch(clientConns); - } else { - response.error = Faye.Error.parameterMissing('supportedConnectionTypes'); - } + response.supportedConnectionTypes = Faye.CONNECTION_TYPES; + + if (clientConns) { + commonConns = Faye.filter(clientConns, function(conn) { + return Faye.indexOf(Faye.CONNECTION_TYPES, conn) >= 0; + }); + if (commonConns.length === 0) + response.error = Faye.Error.conntypeMismatch(clientConns); + } else { + response.error = Faye.Error.parameterMissing('supportedConnectionTypes'); } response.successful = !response.error; diff --git a/lib/faye/protocol/client.rb b/lib/faye/protocol/client.rb index 4ecec06f..999426bb 100644 --- a/lib/faye/protocol/client.rb +++ b/lib/faye/protocol/client.rb @@ -93,8 +93,8 @@ def handshake(&block) @state = CONNECTED @client_id = response['clientId'] - connection_types = response['supportedConnectionTypes'] - select_transport(connection_types - @disabled) if connection_types + connection_types = response['supportedConnectionTypes'] - @disabled + select_transport(connection_types) info('Handshake successful: ?', @client_id) diff --git a/lib/faye/protocol/server.rb b/lib/faye/protocol/server.rb index 0d0e06d3..30ebc9e1 100644 --- a/lib/faye/protocol/server.rb +++ b/lib/faye/protocol/server.rb @@ -125,15 +125,13 @@ def handshake(message, local = false, &callback) client_conns = message['supportedConnectionTypes'] - unless local - response['supportedConnectionTypes'] = CONNECTION_TYPES - - if client_conns - common_conns = client_conns.select { |c| CONNECTION_TYPES.include?(c) } - response['error'] = Error.conntype_mismatch(*client_conns) if common_conns.empty? - else - response['error'] = Error.parameter_missing('supportedConnectionTypes') - end + response['supportedConnectionTypes'] = CONNECTION_TYPES + + if client_conns + common_conns = client_conns.select { |c| CONNECTION_TYPES.include?(c) } + response['error'] = Error.conntype_mismatch(*client_conns) if common_conns.empty? + else + response['error'] = Error.parameter_missing('supportedConnectionTypes') end response['successful'] = response['error'].nil? diff --git a/spec/javascript/server/handshake_spec.js b/spec/javascript/server/handshake_spec.js index 7f9d44ee..8cf4c658 100644 --- a/spec/javascript/server/handshake_spec.js +++ b/spec/javascript/server/handshake_spec.js @@ -90,18 +90,6 @@ JS.ENV.Server.HandshakeSpec = JS.Test.describe("Server handshake", function() { }, response) }) }}) - - it("returns a successful response for local clients", function() { with(this) { - expect(engine, "createClient").yields(["clientid"]) - server.handshake(message, true, function(response) { - assertEqual({ - channel: "/meta/handshake", - successful: true, - version: "1.0", - clientId: "clientid" - }, response) - }) - }}) }}) describe("with no matching supportedConnectionTypes", function() { with(this) { diff --git a/spec/ruby/server/handshake_spec.rb b/spec/ruby/server/handshake_spec.rb index bb55c626..da6e5832 100644 --- a/spec/ruby/server/handshake_spec.rb +++ b/spec/ruby/server/handshake_spec.rb @@ -92,18 +92,6 @@ } end end - - it "returns a successful response for local clients" do - engine.stub(:create_client).and_yield "clientid" - server.handshake(message, true) do |response| - response.should == { - "channel" => "/meta/handshake", - "successful" => true, - "version" => "1.0", - "clientId" => "clientid" - } - end - end end describe "with no matching supportedConnectionTypes" do