Class: Excon::SimpleHttpInstrumentor

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/hp/simple_http_instrumentor.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.eventsObject

Returns the value of attribute events.



4
5
6
# File 'lib/fog/hp/simple_http_instrumentor.rb', line 4

def events
  @events
end

Class Method Details

.instrument(name, params = {}, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/hp/simple_http_instrumentor.rb', line 6

def instrument(name, params = {}, &block)
  params = params.dup
  if params.key?(:headers) && params[:headers].key?('Authorization')
    params[:headers] = params[:headers].dup
    params[:headers]['Authorization'] = REDACTED
  end
  if params.key?(:password)
    params[:password] = REDACTED
  end
  $stderr.puts("--- #{name} ---")
  if name.include?('.request')
    query = ''
    tmp_query = ''
    if params.key?(:query) && !params[:query].nil?
      params[:query].each do |key, value|
        tmp_query += "#{key}=#{value}&"
      end
      if !tmp_query.nil?
        query = "?#{tmp_query}"
        query.chomp!('&')
      end
    end
    $stderr.puts("#{params[:method]} #{params[:path]}#{query} HTTP/1.1" )
    $stderr.puts("User-Agent: #{params[:headers]['User-Agent']}")
    $stderr.puts("Host: #{params[:host]} Port: #{params[:port]}")
    $stderr.puts("Accept: #{params[:headers]['Accept']}")
    $stderr.puts("X-Auth-Token: #{params[:headers]['X-Auth-Token']}")
    $stderr.puts("Body: #{params[:body]}")
  elsif name.include?('.response')
    $stderr.puts("HTTP/1.1 #{params[:status]}")
    $stderr.puts("Content-Length: #{params[:headers]['Content-Length']}")
    $stderr.puts("Content-Type: #{params[:headers]['Content-Type']}")
    $stderr.puts("Date: #{params[:headers]['Date']}")
    params[:headers].each do |key, value|
      if !['Content-Length', 'Content-Type', 'Date'].include?(key)
        $stderr.puts("#{key}: #{value}")
      end
    end
    $stderr.puts("Date: #{params[:headers]['Date']}\n")
    $stderr.puts("Body: #{params[:body]}")
  elsif name.include?('.retry')
    $stderr.puts("#{params.inspect}")
  elsif name.include?('.error')
    $stderr.puts("#{params.inspect}")
  end

  if block_given?
    yield
  end
end