# File lib/mechanize/page.rb, line 26
    def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
      @encoding = nil

      method = response.respond_to?(:each_header) ? :each_header : :each
      response.send(method) do |header,v|
        next unless v =~ /charset/i
        encoding = v[/charset=([^; ]+)/, 1]
        @encoding = encoding unless encoding == 'none'
      end

      # Force the encoding to be 8BIT so we can perform regular expressions.
      # We'll set it to the detected encoding later
      body.force_encoding('ASCII-8BIT') if body && body.respond_to?(:force_encoding)

      @encoding ||= Util.detect_charset(body)

      super(uri, response, body, code)
      @mech           ||= mech

      @encoding = nil if html_body =~ /<meta[^>]*charset[^>]*>/i

      raise Mechanize::ContentTypeError.new(response['content-type']) unless
        response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/i
      @parser = @links = @forms = @meta = @bases = @frames = @iframes = nil
    end