File: request_resolver.rb

package info (click to toggle)
libwww-mechanize-ruby 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 956 kB
  • ctags: 883
  • sloc: ruby: 6,621; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 725 bytes parent folder | download
1
2
3
4
5
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
class Mechanize
  class Chain
    class RequestResolver
      include Mechanize::Handler

      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
    end
  end
end