Method: Thin::Connection#post_process

Defined in:
lib/thin/connection.rb

#post_process(result) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/thin/connection.rb', line 91

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

  @response.status, @response.headers, @response.body = *result

  log_error("Rack application returned nil body. " \
            "Probably you wanted it to be an empty string?") if @response.body.nil?

  # HEAD requests should not return a body.
  @response.body = EMPTY_BODY if @request.head?

  # Make the response persistent if requested by the client
  @response.persistent! if @request.persistent?

  # Send the response
  @response.each do |chunk|
    trace chunk
    send_data chunk
  end

rescue Exception => e
  unexpected_error(e)
  # Close connection since we can't handle response gracefully
  close_connection
ensure
  # If the body is being deferred, then terminate afterward.
  if @response.body.respond_to?(:callback) && @response.body.respond_to?(:errback)
    @response.body.callback { terminate_request }
    @response.body.errback  { terminate_request }
  else
    # Don't terminate the response if we're going async.
    terminate_request unless result && result.first == AsyncResponse.first
  end
end