lib/peddler/parser.rb in peddler-1.0.0 vs lib/peddler/parser.rb in peddler-1.0.1
- old
+ new
@@ -10,18 +10,24 @@
# army of Amazon developers
def new(res, encoding = 'ISO-8859-1')
# Don't parse if there's no body
return res unless res.body
- content_type = res.headers['Content-Type']
- if content_type.start_with?('text/xml')
+ if xml?(res)
XMLResponseParser.new(res)
else
# Amazon returns a variety of content types for flat files, so we
# simply assume that anything not XML is a flat file rather than code
# defensively and check content type again.
FlatFileParser.new(res, encoding)
end
+ end
+
+ def xml?(res)
+ return true if res.headers['Content-Type'].start_with?('text/xml')
+ return true if res.body.start_with?('<?xml')
+
+ false
end
end
end
end