Class: Rack::HTTPLogger
- Inherits:
-
Object
- Object
- Rack::HTTPLogger
- Defined in:
- lib/rack/http-logger.rb
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ HTTPLogger
constructor
A new instance of HTTPLogger.
Constructor Details
#initialize(app, options = {}) ⇒ HTTPLogger
Returns a new instance of HTTPLogger.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rack/http-logger.rb', line 5 def initialize(app, = {}) @app = app @stream = [:stream] || $stdout @stream.sync = true unless .fetch(:sync, true) @source = [:source] || "rack-http-logger" @method = [:method] ? "#{options[:method]}".upcase : "LOG" @path = [:path] || "/" end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/http-logger.rb', line 16 def call(env) return @app.call(env) unless env["REQUEST_METHOD"] == @method and env["REQUEST_PATH"] == @path request = Rack::Request.new(env) if request.media_type == "application/json" and (body = env[POST_BODY].read).length.nonzero? log JSON.parse(body) else log request.params end [201, {"Content-Type" => "text/plain"}, []] end |