Sha256: 6abdbc916fa57b4dbe92902178615331fbca32b447b84a6e50248d8ea717e91a
Contents?: true
Size: 928 Bytes
Versions: 15
Compression:
Stored size: 928 Bytes
Contents
require "rubygems" require "json" module Butterfly class Response attr_reader :request, :body, :status, :headers def initialize req, b=nil @request = req @headers = {} @body = b end def return!(b) @body ||= b [status, prepare_headers, prepare_body] end def prepare_headers add_header("ContentType", choose_response_type) headers end def prepare_body case request.request_type when "json" body.to_json else body.to_s end end def add_header(k,v) @headers[k] = v unless @headers.include?(k) end def status @status ||= 200 end def success! @status = 200 end def fail! @status = 404 end def choose_response_type case request.request_type when "json" "application/json" else "text/plain" end end end end
Version data entries
15 entries across 15 versions & 4 rubygems