class Stub::Reply
Attributes
body[RW]
headers[RW]
status[RW]
Public Class Methods
new(status = 200)
click to toggle source
# File lib/uaa/stub/server.rb, line 90 def initialize(status = 200) @status, @headers, @cookies, @body = status, {}, [], "" end
Public Instance Methods
empty()
click to toggle source
# File lib/uaa/stub/server.rb, line 120 def empty() @status = 204 @body = '' nil end
html(status = nil, info)
click to toggle source
# File lib/uaa/stub/server.rb, line 113 def html(status = nil, info) @status = status if status headers["content-type"] = "text/html" info = ERB::Util.html_escape(info.pretty_inspect) unless info.is_a?(String) @body = "<html><body>#{info}</body></html>" nil end
json(status = nil, info)
click to toggle source
# File lib/uaa/stub/server.rb, line 100 def json(status = nil, info) info = {message: info} unless info.respond_to? :each @status = status if status headers["content-type"] = "application/json" @body = MultiJson.dump(info) nil end
text(status = nil, info)
click to toggle source
# File lib/uaa/stub/server.rb, line 107 def text(status = nil, info) @status = status if status headers["content-type"] = "text/plain" @body = info.pretty_inspect nil end
to_s()
click to toggle source
# File lib/uaa/stub/server.rb, line 91 def to_s message = Rack::Utils::HTTP_STATUS_CODES[@status] reply = "HTTP/1.1 #{@status} #{message.upcase if message}\r\n" headers["server"], headers["date"] = "stub server", DateTime.now.httpdate headers["content-length"] = body.bytesize headers.each { |k, v| reply << "#{k}: #{v}\r\n" } @cookies.each { |c| reply << "Set-Cookie: #{c}\r\n" } reply << "\r\n" << body end