Skip to content

Instantly share code, notes, and snippets.

@tisba

tisba/gist:5a89f03432e140fa1626 Secret

Created Jun 10, 2012
Embed
What would you like to do?
module Arango
class HttpRequest
attr_reader :body, :headers, :parameters, :request_type, :suffix
end
end
module Arango
class HttpResponse
attr_accessor :content_type, :body
attr_reader :status
def status=(new_status)
@status = case new_status
when :ok then 200
when :created then 201
when :method_not_allowed then 405
else new_status.to_i
end
end
end
end
module Arango
class AbstractServlet
HTTP_METHODS = [:get, :put, :post, :delete, :head]
def service(req, res)
requested_method = req.request_type.to_s.downcase.to_sym
if HTTP_METHODS.include? requested_method
self.send(requested_method, req, res)
else
self.unknown_method(req, res, requested_method)
end
end
HTTP_METHODS.each do |meth|
define_method(meth.to_sym) do |req, res|
res.status = :method_not_allowed
end
end
def unknown_method(req, res, method)
res.status = :method_not_allowed
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.