Skip to content

Commit

Permalink
simplify response header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stve authored and sferik committed Jul 29, 2013
1 parent 5b31f3a commit 8ff3336
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/twitter/stream/core/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ class IO

def initialize(host, port)
@reconnect_manager = Twitter::Stream::ReconnectManager.new
client_context = OpenSSL::SSL::SSLContext.new
@parser = Http::Parser.new(self)
client = Celluloid::IO::TCPSocket.new(host, port)
@ssl_client = Celluloid::IO::SSLSocket.new(client, client_context)
@response = Response.new
client_context = OpenSSL::SSL::SSLContext.new
@parser = Http::Parser.new(self)
client = Celluloid::IO::TCPSocket.new(host, port)
@ssl_client = Celluloid::IO::SSLSocket.new(client, client_context)
@response = Response.new
end

def on_headers_complete(headers)
@response_code = @parser.status_code

if @response_code.to_i == 200
@reconnect_manager.reset
return
end
@response_code = @parser.status_code.to_i

case @response_code
when 200 then @reconnect_manager.reset
when 401 then @stream_client.invoke_callback(:unauthorized)
when 403 then @stream_client.invoke_callback(:forbidden)
when 404 then @stream_client.invoke_callback(:not_found)
Expand Down

0 comments on commit 8ff3336

Please sign in to comment.