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