adds Microformats2::Parser#http_headers and Microformats2::Parser#http_body and saves them from the response

This commit is contained in:
Jessica Dillon & Jessica Lynn Suttles 2013-07-01 16:46:08 -07:00
parent 22d84e0845
commit ed2f66002e

View file

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