Class: Net::HTTP
- Inherits:
-
Object
- Object
- Net::HTTP
- Defined in:
- lib/net-http-spy.rb
Class Attribute Summary collapse
-
.http_logger ⇒ Object
Returns the value of attribute http_logger.
-
.http_logger_options ⇒ Object
Returns the value of attribute http_logger_options.
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ HTTP
constructor
A new instance of HTTP.
- #old_initialize ⇒ Object
- #old_request ⇒ Object
- #request(*args, &block) ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ HTTP
Returns a new instance of HTTP.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/net-http-spy.rb', line 16 def initialize(*args, &block) self.class. ||= {} defaults = {:body => false, :trace => false, :verbose => false, :limit => -1} self.class. = (self.class. == :default) ? defaults : self.class. @logger_options = defaults.merge(self.class.) @params_limit = @logger_options[:params_limit] || @logger_options[:limit] @body_limit = @logger_options[:body_limit] || @logger_options[:limit] self.class.http_logger.info "CONNECT: #{args.inspect}" if !@logger_options[:verbose] old_initialize(*args, &block) @debug_output = self.class.http_logger if @logger_options[:verbose] end |
Class Attribute Details
.http_logger ⇒ Object
Returns the value of attribute http_logger.
12 13 14 |
# File 'lib/net-http-spy.rb', line 12 def http_logger @http_logger end |
.http_logger_options ⇒ Object
Returns the value of attribute http_logger_options.
13 14 15 |
# File 'lib/net-http-spy.rb', line 13 def @http_logger_options end |
Instance Method Details
#old_initialize ⇒ Object
8 |
# File 'lib/net-http-spy.rb', line 8 alias :old_initialize :initialize |
#old_request ⇒ Object
9 |
# File 'lib/net-http-spy.rb', line 9 alias :old_request :request |
#request(*args, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/net-http-spy.rb', line 31 def request(*args, &block) unless started? || @logger_options[:verbose] req = args[0].class::METHOD self.class.http_logger.info "#{req} #{args[0].path}" end result = old_request(*args, &block) unless started? || @logger_options[:verbose] self.class.http_logger.info "PARAMS #{CGI.parse(args[0].body).inspect[0..@params_limit]} " if args[0].body && req != 'CONNECT' self.class.http_logger.info "TRACE: #{caller.reverse}" if @logger_options[:trace] self.class.http_logger.info "BODY: #{(@logger_options[:body] ? result.body : result.class.name)[0..@body_limit]}" end result end |