diff --git a/lib/microformats2/parser.rb b/lib/microformats2/parser.rb index 680a034..1238690 100644 --- a/lib/microformats2/parser.rb +++ b/lib/microformats2/parser.rb @@ -1,13 +1,19 @@ module Microformats2 class Parser - def parse(html) - html = read_html(html) + attr_reader :http_headers, :http_body + + def parse(html, headers={}) + html = read_html(html, headers) document = Nokogiri::HTML(html) Collection.new(document).parse end - def read_html(html) - open(html).read + def read_html(html, headers={}) + open(html, headers) do |response| + @http_headers = response.meta if response.respond_to?(:meta) + @http_body = response.read + end + @http_body rescue Errno::ENOENT, Errno::ENAMETOOLONG => e html end