Class: Skylight::Middleware Private

Inherits:
Object show all
Includes:
Util::Logging
Defined in:
lib/skylight/middleware.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: BodyProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#debug, #error, #info, #log, #t, #trace, trace?, #warn

Constructor Details

#initialize(app, opts = {}) ⇒ Middleware

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Middleware.



48
49
50
51
# File 'lib/skylight/middleware.rb', line 48

def initialize(app, opts={})
  @app = app
  @config = opts[:config]
end

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

For Util::Logging



46
47
48
# File 'lib/skylight/middleware.rb', line 46

def config
  @config
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/skylight/middleware.rb', line 53

def call(env)
  if env["REQUEST_METHOD"] == "HEAD"
    t { "middleware skipping HEAD" }
    @app.call(env)
  else
    begin
      t { "middleware beginning trace" }
      trace = Skylight.trace "Rack", 'app.rack.request'
      resp = @app.call(env)
      resp[2] = BodyProxy.new(resp[2]) { trace.submit } if trace
      resp
    rescue Exception
      t { "middleware exception: #{trace}"}
      trace.submit if trace
      raise
    ensure
      t { "middleware release: #{trace}"}
      trace.release if trace
    end
  end
end