lib/onebox/engine/standard_embed.rb in onebox-1.5.2 vs lib/onebox/engine/standard_embed.rb in onebox-1.5.3
- old
+ new
@@ -3,11 +3,10 @@
module StandardEmbed
def raw
return @raw if @raw
response = fetch_response(url)
-
html_doc = Nokogiri::HTML(response.body)
# Determine if we should use OEmbed or OpenGraph
oembed_alternate = html_doc.at("//link[@type='application/json+oembed']") || html_doc.at("//link[@type='text/json+oembed']")
if oembed_alternate
@@ -59,11 +58,11 @@
end
og
end
- def fetch_response(location, limit = 5, domain = nil)
+ def fetch_response(location, limit = 5, domain = nil,headers=nil)
raise Net::HTTPError.new('HTTP redirect too deep', location) if limit == 0
uri = URI(location)
if !uri.host
uri = URI("#{domain}#{location}")
@@ -73,14 +72,21 @@
http.read_timeout = Onebox.options.timeout
if uri.is_a?(URI::HTTPS)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
- response = http.request_get(uri.request_uri)
+ response = http.request_get(uri.request_uri,headers)
+
+ cookie = response.get_fields('set-cookie')
+ if (cookie)
+ header = {'cookie' => cookie.join("")}
+ end
+ header = nil unless header.is_a? Hash
+
case response
when Net::HTTPSuccess then response
- when Net::HTTPRedirection then fetch_response(response['location'], limit - 1, "#{uri.scheme}://#{uri.host}")
+ when Net::HTTPRedirection then fetch_response(response['location'], limit - 1, "#{uri.scheme}://#{uri.host}",header)
else
response.error!
end
end