Sha256: e50a24c06308f9f01e01529011f2d665523d6d2588fabe129fad3dd6233eec30

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Thin
  class JsSpecConnection < Connection
    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

    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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
js_spec-0.2.0 lib/js_spec/thin/js_spec_connection.rb