Skip to content

Commit

Permalink
Merge pull request #25 from rud/bugfix/honor-https-during-reconnect
Browse files Browse the repository at this point in the history
Reconnect with HTTPS fix: establish SSL connection also when reconnecting
  • Loading branch information
voloko committed Apr 10, 2012
2 parents 79f7eb7 + 60f5369 commit 7e3f963
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/twitter/json_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def self.connect options = {}
end

connection = EventMachine.connect host, port, self, options
connection.start_tls if options[:ssl]
connection
end

Expand Down Expand Up @@ -122,6 +121,7 @@ def receive_data(data)
end

def connection_completed
start_tls if @options[:ssl]
send_request
end

Expand Down
13 changes: 13 additions & 0 deletions spec/twitter/json_stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def receive_data data
stream = JSONStream.connect(:proxy => "http://my-proxy:8080") {}
end

it "should not trigger SSL until connection is established" do
connection = stub('connection')
EM.should_receive(:connect).and_return(connection)
stream = JSONStream.connect(:ssl => true)
stream.should == connection
end

end

context "on valid stream" do
Expand Down Expand Up @@ -197,6 +204,12 @@ def receive_data data
end
end

it "should reconnect with SSL if enabled" do
connect_stream :ssl => true do
stream.should_receive(:start_tls).twice
end
end

it_should_behave_like "network failure"
end

Expand Down

0 comments on commit 7e3f963

Please sign in to comment.