Sha256: fcd505be70c3eba93ac8bf97d0d0faebaef2bc417aa291e04358c99a031b9528

Contents?: true

Size: 1.66 KB

Versions: 20

Compression:

Stored size: 1.66 KB

Contents

module Rack::Insight
  module SpeedTracer
    class TraceApp
      include Database::RequestDataClient

      CONTENT_TYPE = 'application/json;charset=UTF-8'.freeze

      FourOhFour = [404, {"Content-Type" => "text/html"}, "App tracker doesn't know that path or id"].freeze

      class << self
        attr_accessor :has_table
      end
      self.has_table = true

      def initialize
        table_setup("speedtracer", "uuid")
        key_sql_template = "'%s'"
      end

      def call(env)
        resp = Rack::Response.new('', 200)
        resp['Content-Type'] = CONTENT_TYPE

        case env['REQUEST_METHOD']
        when 'HEAD' then
          # SpeedTracer dispatches HEAD requests to verify the
          # tracer endpoint when it detects the X-TraceUrl
          # header for the first time. After the initial load
          # the verification is cached by the extension.
          #
          # By default, we'll return 200.

        when 'GET' then
          # GET requests for specific trace are generated by
          # the extension when the user expands the network
          # resource tab. Hence, server-side tracer data is
          # request on-demand, and we need to store it for
          # some time.
          #

          qs = Rack::Utils.parse_query(env['QUERY_STRING'])
          if qs['id'] && (trace = @table.retrieve("uuid = '#{qs['id']}'"))
            resp.write trace.to_json
          else
            # Invalid request or missing request trace id
            return FourOhFour
          end
        else
          # SpeedTracer should only issue GET & HEAD requests
          resp.status = 400
        end

        return resp.finish
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rack-insight-0.6.4 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.6.3 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.6.2 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.30 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.29 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.28 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.27 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.26 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.25 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.24 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.23 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.22 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.21 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.20 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.19 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.18 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.17 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.16 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.15 lib/rack/insight/panels/speedtracer_panel/trace-app.rb
rack-insight-0.5.14 lib/rack/insight/panels/speedtracer_panel/trace-app.rb