Class: Thin::JsSpecConnection

Inherits:
Connection
  • Object
show all
Defined in:
lib/js_spec/thin/js_spec_connection.rb

Instance Method Summary collapse

Instance Method Details

#handle_errorObject



37
38
39
40
41
# File 'lib/js_spec/thin/js_spec_connection.rb', line 37

def handle_error
  log "!! Unexpected error while processing request: #{$!.message}"
  log_error
  close_connection rescue nil
end

#processObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/js_spec/thin/js_spec_connection.rb', line 3

def process
  # Add client info to the request env
  @request.remote_address = remote_address

  env = @request.env
  env['js_spec.connection'] = self
  status, headers, body = @app.call(env)
  unless status.to_i == 0
    send_response(status, headers, body)
  end
rescue
  handle_error
end

#send_response(status, headers, body) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/js_spec/thin/js_spec_connection.rb', line 17

def send_response(status, headers, body)
  @response.status, @response.headers, @response.body = status, headers, body
  @response.persistent! if @request.persistent?
  @response.each do |chunk|
    trace { chunk }
    send_data chunk
  end
  # If no more request on that same connection, we close it.
  close_connection_after_writing unless persistent?
rescue
  handle_error
ensure
  @request.close  rescue nil
  @response.close rescue nil

  # Prepare the connection for another request if the client
  # supports HTTP pipelining (persistent connection).
  post_init if persistent?
end