adds Microformats2::Parser#http_headers and Microformats2::Parser#http_body and saves them from the response
This commit is contained in:
parent
22d84e0845
commit
ed2f66002e
1 changed files with 10 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue