lib/feedzirra/feed.rb in pauldix-feedzirra-0.0.6 vs lib/feedzirra/feed.rb in pauldix-feedzirra-0.0.7

- old
+ new

@@ -151,19 +151,24 @@ # # === Parameters # [curl_request<Curl::Easy>] The Curl::Easy response object from the request. # === Returns # A decoded string of XML. - def self.decode_content(curl_request) - if curl_request.header_str.match(/Content-Encoding: gzip/) - gz = Zlib::GzipReader.new(StringIO.new(curl_request.body_str)) - xml = gz.read - gz.close - elsif curl_request.header_str.match(/Content-Encoding: deflate/) - xml = Zlib::Deflate.inflate(curl_request.body_str) + def self.decode_content(c) + if c.header_str.match(/Content-Encoding: gzip/) + begin + gz = Zlib::GzipReader.new(StringIO.new(c.body_str)) + xml = gz.read + gz.close + rescue Zlib::GzipFile::Error + # Maybe this is not gzipped? + xml = c.body_str + end + elsif c.header_str.match(/Content-Encoding: deflate/) + xml = Zlib::Inflate.inflate(c.body_str) else - xml = curl_request.body_str + xml = c.body_str end xml end @@ -226,10 +231,12 @@ feed.etag = etag_from_header(c.header_str) feed.last_modified = last_modified_from_header(c.header_str) responses[url] = feed options[:on_success].call(url, feed) if options.has_key?(:on_success) else - raise NoParserAvailable.new("Error determining parser for #{url} - #{c.last_effective_url}.") + # puts "Error determining parser for #{url} - #{c.last_effective_url}" + # raise NoParserAvailable.new("no valid parser for content.") (this would unfirtunately fail the whole 'multi', so it's not really useable) + options[:on_failure].call(url, c.response_code, c.header_str, c.body_str) if options.has_key?(:on_failure) end end curl.on_failure do |c| add_url_to_multi(multi, url_queue.shift, url_queue, responses, options) unless url_queue.empty? \ No newline at end of file