Sha256: 160f96b9d5b6ac237da303a7f4e31414828c985b3178bb7ab8f58cb0ff7c810d

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

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

        def initialize(response)
          @response = response
        end

        def handle(ctx, params)
          params[:response] = @response
          body = StringIO.new
          total = 0
          @response.read_body { |part|
            total += part.length
            body.write(part)
            Mechanize.log.debug("Read #{total} bytes") if Mechanize.log
          }
          body.rewind

          res_klass = Net::HTTPResponse::CODE_TO_OBJ[@response.code.to_s]
          raise ResponseCodeError.new(@response) unless res_klass

          # Net::HTTP ignores EOFError if Content-length is given, so we emulate it here.
          unless res_klass <= Net::HTTPRedirection
            raise EOFError if (!params[:request].is_a?(Net::HTTP::Head)) && @response.content_length() && @response.content_length() != total
          end
  
          @response.each_header { |k,v|
            Mechanize.log.debug("response-header: #{ k } => #{ v }")
          } if Mechanize.log

          params[:response_body] = body
          params[:res_klass] = res_klass
          super
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
eric-mechanize-0.9.3.20090623142847 lib/www/mechanize/chain/response_reader.rb
knu-mechanize-0.9.3.20090623142847 lib/www/mechanize/chain/response_reader.rb
tenderlove-mechanize-0.9.3.20090617085936 lib/www/mechanize/chain/response_reader.rb
tenderlove-mechanize-0.9.3.20090623142847 lib/www/mechanize/chain/response_reader.rb
mechanize-ntlm-0.9.1 lib/www/mechanize/chain/response_reader.rb
mechanize-0.8.5 lib/www/mechanize/chain/response_reader.rb
mechanize-0.9.0 lib/www/mechanize/chain/response_reader.rb
mechanize-0.9.3 lib/www/mechanize/chain/response_reader.rb
mechanize-0.9.1 lib/www/mechanize/chain/response_reader.rb
mechanize-0.9.2 lib/www/mechanize/chain/response_reader.rb