lib/angelo/server.rb in angelo-0.4.1 vs lib/angelo/server.rb in angelo-0.5.0

- old
+ new

@@ -3,11 +3,11 @@ module Angelo class Server < Reel::Server::HTTP extend Forwardable - include Celluloid::Logger + include Celluloid::Internals::Logger def_delegators :@base, :websockets, :sses attr_reader :base @@ -49,25 +49,36 @@ static! meth, connection, request, lp else route! meth, connection, request end rescue URI::InvalidURIError => e - Angelo.log connection, request, nil, :bad_request + Angelo.log meth, connection, request, nil, :bad_request connection.respond :bad_request, DEFAULT_RESPONSE_HEADERS, e.message end + def post_override! meth, request + if meth == :post and request.headers.has_key? POST_OVERRIDE_REQUEST_HEADER_KEY + new_meth = request.headers[POST_OVERRIDE_REQUEST_HEADER_KEY].downcase.to_sym + meth = new_meth if POST_OVERRIDABLE.include? new_meth + end + meth + rescue + meth + end + def route! meth, connection, request + meth = post_override! meth, request if rs = @base.routes[meth][request.path] responder = rs.dup responder.reset! responder.base = @base.new responder responder.connection = connection responder.request = request responder.handle_request responder else - Angelo.log connection, request, nil, :not_found + Angelo.log meth, connection, request, nil, :not_found connection.respond :not_found, DEFAULT_RESPONSE_HEADERS, NOT_FOUND end end def staticable? meth @@ -75,11 +86,11 @@ end def static! meth, connection, request, local_path etag = etag_for local_path if request.headers[IF_NONE_MATCH_HEADER_KEY] == etag - Angelo.log connection, request, nil, :not_modified, 0 + Angelo.log meth, connection, request, nil, :not_modified, 0 connection.respond :not_modified else headers = { # Content-Type @@ -94,10 +105,10 @@ # ETag # ETAG_HEADER_KEY => etag } - Angelo.log connection, request, nil, :ok, headers[CONTENT_LENGTH_HEADER_KEY] + Angelo.log meth, connection, request, nil, :ok, headers[CONTENT_LENGTH_HEADER_KEY] connection.respond :ok, headers, (meth == :head ? nil : File.read(local_path)) end end def etag_for local_path