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

- old
+ new

@@ -16,13 +16,17 @@ DELETE = 'DELETE' OPTIONS = 'OPTIONS' HTTPABLE = [:get, :post, :put, :delete, :options] STATICABLE = [:get, :head] + POST_OVERRIDABLE = [:put, :delete] ACCEPT_REQUEST_HEADER_KEY = 'Accept' + POST_OVERRIDE_REQUEST_HEADER_KEY = 'X-Angelo-PostOverride' + REAL_IP_REQUEST_HEADER_KEY = 'X-Real-IP' + CONTENT_TYPE_HEADER_KEY = 'Content-Type' CONTENT_DISPOSITION_HEADER_KEY = 'Content-Disposition' CONTENT_LENGTH_HEADER_KEY = 'Content-Length' ATTACHMENT_CONTENT_DISPOSITION = 'attachment; filename="%s"' ETAG_HEADER_KEY = 'ETag' @@ -77,26 +81,27 @@ @response_log_level ||= DEFAULT_RESPONSE_LOG_LEVEL end end - def self.log connection, request, socket, status, body_size = '-' + def self.log meth, connection, request, socket, status, body_size = '-' - remote_ip = ->{ - if socket.nil? - connection.remote_ip rescue 'unknown' - else - socket.peeraddr(false)[3] - end - } + remote_ip = case + when request.headers[REAL_IP_REQUEST_HEADER_KEY] + request.headers[REAL_IP_REQUEST_HEADER_KEY] + when socket + socket.peeraddr(false)[3] + else + connection.remote_ip rescue 'unknown' + end - Celluloid::Logger.__send__ Angelo.response_log_level, LOG_FORMAT % [ - remote_ip[], - request.method, + Celluloid::Internals::Logger.__send__ Angelo.response_log_level, LOG_FORMAT % [ + remote_ip, + (meth && meth.upcase) || request.method, request.url, request.version, - Symbol === status ? HTTP::Response::SYMBOL_TO_STATUS_CODE[status] : status, + Symbol === status ? HTTP::Response::Status::SYMBOL_CODES[status] : status, body_size ] end @@ -131,9 +136,10 @@ require 'angelo/params_parser' require 'angelo/server' require 'angelo/responder' require 'angelo/responder/eventsource' require 'angelo/responder/websocket' +require 'angelo/templates' require 'angelo/tilt/erb' require 'angelo/base' require 'angelo/stash' # trap "INT" do