Feed Handling/Type Determination

From MozillaWiki
Jump to: navigation, search


About a third of web feeds are served with an incorrect MIME type, e.g. text/html. In order to be able to correctly identify web feeds as feeds, parse and handle them correctly we need to resort to content sniffing.

Content Sniffing

Through bug 324985, the ability was added to necko to register content sniffers using the net-content-sniffers category entry. A contract id to a component implementing nsIContentSniffer is added. When any file is transferred, the content sniffer is invoked with the raw data, with the method getMIMETypeFromContent. It must look at the data and see if it can determine the type, regardless of what the channel thinks the type is.

Feeds and Content Sniffing

In browser/components/feeds/src/nsFeedSniffer.cpp is an implementation of nsIContentSniffer which (depending on the Content-Encoding) decompresses the data and then runs some basic tests against it looking for feed content. If it determines the data is a web feed, it sets the content type to application/vnd.mozilla.maybe.feed, so that the document will be handled specially elsewhere in the system.