Sha256: ed37adb96439b1709e36424a9ac1545a78a1c8366273a16d17a11004e34a5288
Contents?: true
Size: 1001 Bytes
Versions: 12
Compression:
Stored size: 1001 Bytes
Contents
## # Class for midori response # @attr [String] status HTTP response status # @attr [Hash] header HTTP response header # @attr [String] body HTTP response body class Midori::Response attr_accessor :status, :header, :body # @param [Hash] options HTTP response # @option options [Integer] code HTTP response code # @option options [Hash] header HTTP response header # @option options [String] body HTTP response body # Init a Response def initialize(options = {}) code = options[:status] || 200 @status = Midori::Const::STATUS_CODE[code] @header = options[:header] || Midori::Const::DEFAULT_HEADER.clone @body = options[: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
12 entries across 12 versions & 2 rubygems