Sha256: a3f2dc4209ec8ba47837f8ad9dbdb87fc0cce2bbda4db810d23a159b7d4481f3

Contents?: true

Size: 1.36 KB

Versions: 11

Compression:

Stored size: 1.36 KB

Contents

require 'opbeat/interfaces'

module Opbeat

  class HttpInterface < Interface

    name 'http'
    property :url, :required => true
    property :method, :required => true
    property :data
    property :query_string
    property :cookies
    property :headers
    property :remote_host
    property :http_host
    property :env

    def initialize(*arguments)
      self.headers = {}
      self.env = {}
      super(*arguments)
    end

    def from_rack(env)
      require 'rack'
      req = ::Rack::Request.new(env)
      self.url = req.url.split('?').first
      self.method = req.request_method
      self.query_string = req.query_string
      self.cookies = req.cookies.collect {|k,v| "#{k}=#{v}"}.join(';')
      self.remote_host = req.ip
      self.http_host = req.host_with_port
      env.each_pair do |key, value|
        next unless key.upcase == key # Non-upper case stuff isn't either
        if key.start_with?('HTTP_')
          # Header
          http_key = key[5..key.length-1].split('_').map{|s| s.capitalize}.join('-')
          self.headers[http_key] = value.to_s
        else
          # Environment
          self.env[key] = value.to_s
        end
      end
      self.data = if req.form_data?
        req.POST
      elsif req.body
        data = req.body.read
        req.body.rewind
        data
      end
    end

  end

  register_interface :http => HttpInterface

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
opbeat-0.9.1 lib/opbeat/interfaces/http.rb
opbeat-0.9.0 lib/opbeat/interfaces/http.rb
opbeat-0.8.0 lib/opbeat/interfaces/http.rb
opbeat-0.7.1 lib/opbeat/interfaces/http.rb
opbeat-0.7.0 lib/opbeat/interfaces/http.rb
opbeat-0.6.1 lib/opbeat/interfaces/http.rb
opbeat-0.6.0 lib/opbeat/interfaces/http.rb
opbeat-0.5.2 lib/opbeat/interfaces/http.rb
opbeat-0.5.1 lib/opbeat/interfaces/http.rb
opbeat-0.5 lib/opbeat/interfaces/http.rb
opbeat-0.4 lib/opbeat/interfaces/http.rb