Sha256: 6804a1ced7f2943d7fcb348cf5810eb12420c7b1b4fb713ac5775a9e46356d7b

Contents?: true

Size: 1.38 KB

Versions: 37

Compression:

Stored size: 1.38 KB

Contents

##   RSence
 #   Copyright 2008 Riassence Inc.
 #   http://riassence.com/
 #
 #   You should have received a copy of the GNU General Public License along
 #   with this software package. If not, contact licensing@riassence.com
 ##



module RSence
  
  # Classic WEBrick -compatible Response object for Rack.
  # Implements only the methods used by the framework.
  class Response
    
    # Adds the + method "operator" to an extended Array.
    # Used for pushing http body data.
    class ResponseBody < Array
      def +(body_data)
        self.push(body_data)
      end
    end

    def initialize
      @body = ResponseBody.new(1)
      @body[0] = ''
      @status = 200
      @header = {
        'Content-Type' => 'text/plain',
        'Server' => 'RSence'
      }
    end
    def body=(body_data)
      @body = ResponseBody.new(1)
      @body[0] = body_data
    end
    def body
      @body.join
    end
    def content_type=(new_content_type)
      @header['Content-Type'] = new_content_type
    end
    def content_type
      @header['Content-Type']
    end
    def camelize( header_key )
      header_key.capitalize.gsub(/\-([a-z])/) { '-'+$1.upcase }
    end
    def []=(header_key,header_val)
      @header[camelize( header_key )] = header_val.to_s
    end
    def status=(new_val)
      @status = new_val.to_i
    end
    def status
      @status
    end
    def header
      @header
    end
  end

end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
rsence-2.1.6 lib/http/response.rb
rsence-2.1.5 lib/http/response.rb
rsence-2.1.4 lib/http/response.rb
rsence-2.1.3 lib/http/response.rb
rsence-2.1.2 lib/http/response.rb
rsence-2.1.1 lib/http/response.rb
rsence-2.1.0 lib/http/response.rb
rsence-pre-2.1.0.21 lib/http/response.rb
rsence-pre-2.1.0.20 lib/http/response.rb
rsence-pre-2.1.0.19 lib/http/response.rb
rsence-pre-2.1.0.18 lib/http/response.rb
rsence-pre-2.1.0.17 lib/http/response.rb
rsence-pre-2.1.0.16 lib/http/response.rb
rsence-pre-2.1.0.15 lib/http/response.rb
rsence-pre-2.1.0.14 lib/http/response.rb
rsence-pre-2.1.0.13 lib/http/response.rb
rsence-pre-2.1.0.12 lib/http/response.rb
rsence-pre-2.1.0.11 lib/http/response.rb
rsence-pre-2.1.0.10 lib/http/response.rb
rsence-pre-2.1.0.9 lib/http/response.rb