Sha256: 0118923e486d3fe5e16e8268a10bea8553892a45d0d34a2caa645aa29452a183

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

module WWW
  class Mechanize
    class Chain
      class ResponseHeaderHandler
        include WWW::Handler

        def initialize(cookie_jar, connection_cache)
          @cookie_jar = cookie_jar
          @connection_cache = connection_cache
        end

        def handle(ctx, params)
          response = params[:response]
          uri = params[:uri]
          page = params[:page]
          cache_obj = (@connection_cache["#{uri.host}:#{uri.port}"] ||= {
            :connection         => nil,
            :keep_alive_options => {},
          })

          # If the server sends back keep alive options, save them
          if keep_alive_info = response['keep-alive']
            keep_alive_info.split(/,\s*/).each do |option|
              k, v = option.split(/=/)
              cache_obj[:keep_alive_options] ||= {}
              cache_obj[:keep_alive_options][k.intern] = v
            end
          end
  
          if page.is_a?(Page) && page.body =~ /Set-Cookie/
            page.search('//meta[@http-equiv="Set-Cookie"]').each do |meta|
              Cookie::parse(uri, meta['content']) { |c|
                Mechanize.log.debug("saved cookie: #{c}") if Mechanize.log
                @cookie_jar.add(uri, c)
              }
            end
          end

          (response.get_fields('Set-Cookie')||[]).each do |cookie|
            Cookie::parse(uri, cookie) { |c|
              Mechanize.log.debug("saved cookie: #{c}") if Mechanize.log
              @cookie_jar.add(uri, c)
            }
          end
          super
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mechanize-0.8.0 lib/www/mechanize/chain/response_header_handler.rb
mechanize-0.8.2 lib/www/mechanize/chain/response_header_handler.rb
mechanize-0.8.3 lib/www/mechanize/chain/response_header_handler.rb
mechanize-0.8.4 lib/www/mechanize/chain/response_header_handler.rb
mechanize-0.8.1 lib/www/mechanize/chain/response_header_handler.rb
mechanize-0.9.0 lib/www/mechanize/chain/response_header_handler.rb
mechanize-0.8.5 lib/www/mechanize/chain/response_header_handler.rb