-
-
Save tisba/5a89f03432e140fa1626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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