Sha256: fab09ec06915e4e93250eca5a8635c5b9f1724ca0d51eddfd97d1c8ce1cbde11

Contents?: true

Size: 849 Bytes

Versions: 16

Compression:

Stored size: 849 Bytes

Contents

##
# Class for midori response
# @attr [String] HTTP response status
# @attr [Hash] HTTP response header
# @attr [String] HTTP response body
class Midori::Response
  attr_accessor :status, :header, :body

  # @param [Fixnum] code HTTP response code
  # @param [Hash] header HTTP response header
  # @param [String] body HTTP response body
  def initialize(code = 200, header = Midori::Const::DEFAULT_HEADER.clone, body = '')
    @status = Midori::Const::STATUS_CODE[code]
    @header = header
    @body = body
  end

  # Generate header string from hash
  # @return [String] generated string
  def generate_header
    @header.map do |key, value|
      "#{key}: #{value}\r\n"
    end.join
  end

  # Convert response to raw string
  # @return [String] generated string
  def to_s
    "HTTP/1.1 #{@status}\r\n#{generate_header}\r\n#{@body}"
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
em-midori-0.1.6.1 lib/midori/response.rb
em-midori-0.1.6 lib/midori/response.rb
em-midori-0.1.5.4 lib/em-midori/response.rb
em-midori-0.1.5.3 lib/em-midori/response.rb
em-midori-0.1.5.2 lib/em-midori/response.rb
em-midori-0.1.5.1 lib/em-midori/response.rb
em-midori-0.1.5 lib/em-midori/response.rb
em-midori-0.1.4.1 lib/em-midori/response.rb
em-midori-0.1.4 lib/em-midori/response.rb
em-midori-0.1.3 lib/em-midori/response.rb
em-midori-0.1.2 lib/em-midori/response.rb
em-midori-0.1.1 lib/em-midori/response.rb
em-midori-0.1.0 lib/em-midori/response.rb
em-midori-0.0.9.5 lib/em-midori/response.rb
em-midori-0.0.9.4 lib/em-midori/response.rb
em-midori-0.0.9.3 lib/em-midori/response.rb