Skip to content

Commit

Permalink
Merge pull request #89 from madvertise/master
Browse files Browse the repository at this point in the history
EXCEPTION: can't convert nil into String in Connection.socket_address
  • Loading branch information
macournoyer committed May 11, 2012
2 parents e141c06 + c744efe commit 9d60f25
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/thin/connection.rb
Expand Up @@ -6,10 +6,10 @@ module Thin
# that is opened.
class Connection < EventMachine::Connection
include Logging

# This is a template async response. N.B. Can't use string for body on 1.9
AsyncResponse = [-1, {}, []].freeze

# Rack application (adapter) served by this connection.
attr_accessor :app

Expand All @@ -25,7 +25,7 @@ class Connection < EventMachine::Connection
# Calling the application in a threaded allowing
# concurrent processing of requests.
attr_writer :threaded

# Get the connection ready to process a request.
def post_init
@request = Request.new
Expand Down Expand Up @@ -59,13 +59,13 @@ def pre_process
@request.remote_address = remote_address

# Connection may be closed unless the App#call response was a [-1, ...]
# It should be noted that connection objects will linger until this
# It should be noted that connection objects will linger until this
# callback is no longer referenced, so be tidy!
@request.async_callback = method(:post_process)

if @backend.ssl?
@request.env["rack.url_scheme"] = "https"

if cert = get_peer_cert
@request.env['rack.peer_cert'] = cert
end
Expand All @@ -89,7 +89,7 @@ def pre_process
def post_process(result)
return unless result
result = result.to_a

# Status code -1 indicates that we're going to respond later (async).
return if result.first == AsyncResponse.first

Expand Down Expand Up @@ -190,7 +190,8 @@ def remote_address
protected
# Returns IP address of peer as a string.
def socket_address
Socket.unpack_sockaddr_in(get_peername)[1]
peer = get_peername
Socket.unpack_sockaddr_in(peer)[1] if peer
end
end
end

0 comments on commit 9d60f25

Please sign in to comment.