Class: WWW::Mechanize::Chain::RequestResolver

Inherits:
Object
  • Object
show all
Includes:
Handler
Defined in:
lib/www/mechanize/chain/request_resolver.rb

Instance Attribute Summary

Attributes included from Handler

#chain

Instance Method Summary collapse

Instance Method Details

#handle(ctx, params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/www/mechanize/chain/request_resolver.rb', line 7

def handle(ctx, params)
  uri = params[:uri]
  if %w{ http https }.include?(uri.scheme.downcase)
    klass = Net::HTTP.const_get(params[:verb].to_s.capitalize)
    params[:request] ||= klass.new(uri.request_uri)
  end

  if %w{ file }.include?(uri.scheme.downcase)
    o = Struct.new(:uri).new(uri)
    class << o
      def add_field(*args); end
      alias :[]= :add_field
      def path
        uri.path
      end
      def each_header; end
    end
    params[:request] ||= o
  end

  super
end