From ed2f66002e8979f827734d88d0d2f35acfc43e55 Mon Sep 17 00:00:00 2001 From: Jessica Dillon & Jessica Lynn Suttles Date: Mon, 1 Jul 2013 16:46:08 -0700 Subject: [PATCH] adds Microformats2::Parser#http_headers and Microformats2::Parser#http_body and saves them from the response --- lib/microformats2/parser.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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