Class: Thin::Response

### Home Classes Methods

### In Files

- lib/thin/response.rb

### Parent

Object

### Methods

- ::new
- #close
- #each
- #head
- #headers=
- #headers_output
- #persistent!
- #persistent?
- #skip_body!

### Class/Module Index

Quicksearch

- Thin
- Thin::Backends
- Thin::Backends::Base
- Thin::Backends::SwiftiplyClient
- Thin::Backends::TcpServer
- Thin::Backends::UnixServer
- Thin::Command
- Thin::Connection
- Thin::Controllers
- Thin::Controllers::Cluster
- Thin::Controllers::Controller
- Thin::Controllers::Service
- Thin::Daemonizable
- Thin::Daemonizable::ClassMethods
- Thin::Headers
- Thin::InvalidOption
- Thin::InvalidRequest
- Thin::Logging
- Thin::Logging::SimpleFormatter
- Thin::OptionRequired
- Thin::PidFileExist
- Thin::PidFileNotFound
- Thin::PlatformNotSupported
- Thin::Request
- Thin::Response
- Thin::RestartTimeout
- Thin::Runner
- Thin::RunnerError
- Thin::Server
- Thin::Stats
- Thin::Stats::Adapter
- Thin::SwiftiplyConnection
- Thin::UnixConnection
- Rack
- Rack::Adapter
- Rack::Adapter::Rails
- Rack::Adapter::Rails::CGIWrapper
- Rack::Adapter::Rails::CgiApp
- Rack::AdapterNotFound
- Process

No matching classes.

# Thin::Response

A response sent to the client.

### Constants

BAD_REQUEST
CLOSE
CONNECTION
CONTENT_LENGTH
ERROR

  Error Responses

KEEP_ALIVE
PERSISTENT_ERROR
PERSISTENT_STATUSES
SERVER

### Attributes

body[RW]

Response body, must respond to `each`.

headers[R]

Headers key-value hash

status[RW]

Status code

### Public Class Methods

new() click to toggle source

    # File lib/thin/response.rb, line 26
    def initialize
      @headers    = Headers.new
      @status     = 200
      @persistent = false
      @skip_body  = false
    end

### Public Instance Methods

close() click to toggle source

Close any resource used by the response

    # File lib/thin/response.rb, line 82
    def close
      @body.close if @body.respond_to?(:close)
    end

each() click to toggle source

Yields each chunk of the response. To control the size of each chunk define your own `each` method on `body`.

    # File lib/thin/response.rb, line 89
    def each
      yield head

      unless @skip_body
        if @body.is_a?(String)
          yield @body
        else
          @body.each { |chunk| yield chunk }
        end
      end
    end

head() click to toggle source

Top header of the response, containing the status code and response headers.

    # File lib/thin/response.rb, line 45
    def head
      "HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status.to_i]}\r\n#{headers_output}\r\n"
    end

headers=(key_value_pairs) click to toggle source

Ruby 1.8 implementation. Respects Rack specs.

See rack.rubyforge.org/doc/files/SPEC.html

    # File lib/thin/response.rb, line 55
    def headers=(key_value_pairs)
      key_value_pairs.each do |k, vs|
        vs.each { |v| @headers[k] = v.chomp } if vs
      end if key_value_pairs
    end

headers_output() click to toggle source

String representation of the headers to be sent in the response.

    # File lib/thin/response.rb, line 35
    def headers_output
      # Set default headers
      @headers[CONNECTION] = persistent? ? KEEP_ALIVE : CLOSE unless @headers.has_key?(CONNECTION)
      @headers[SERVER]     = Thin::NAME unless @headers.has_key?(SERVER)

      @headers.to_s
    end

persistent!() click to toggle source

Tell the client the connection should stay open

    # File lib/thin/response.rb, line 102
    def persistent!
      @persistent = true
    end

persistent?() click to toggle source

Persistent connection must be requested as keep-alive from the server and have a Content-Length, or the response status must require that the connection remain open.

    # File lib/thin/response.rb, line 109
    def persistent?
      (@persistent && @headers.has_key?(CONTENT_LENGTH)) || PERSISTENT_STATUSES.include?(@status)
    end

skip_body!() click to toggle source

    # File lib/thin/response.rb, line 113
    def skip_body!
      @skip_body = true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.