Method: Thin::Connection#pre_process

Defined in:
lib/thin/connection.rb

#pre_processObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/thin/connection.rb', line 59

def pre_process
  # Add client info to the request env
  @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
  # 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
  end

  # When we're under a non-async framework like rails, we can still spawn
  # off async responses using the callback info, so there's little point
  # in removing this.
  response = AsyncResponse
  catch(:async) do
    # Process the request calling the Rack adapter
    response = @app.call(@request.env)
  end
  response
rescue Exception => e
  unexpected_error(e)
  # Pass through error response
  can_persist? && @request.persistent? ? Response::PERSISTENT_ERROR : Response::ERROR
end