servo/servo — pull request #4094 by IdeaHat (2014-11-25 02:08:04+00:00)
Title: T29: Getting Review on Mime Sniffer

Not to merge, for review only.

Hi @jdm. I am one of the NC State students working on the MIME Sniffer. We are looking to get some review on the mime classifier algorithm we've been working on (mostly in file components/net/mime_classifier.rs) We've pretty much implemented all of section 6 and 7 of https://mimesniff.spec.whatwg.org. We are looking for guidance on where to focus our efforts in the week remaining.

Specifically, we are not sure if section 5 will happen as part of the MIME sniffing task or before, and where we would be able to get the context information for section 8.

The fonts are a particular area of confusion. It seems the only branching path that will allow the font to be parsed if mislabelled is when it is used in a Context (section 8). In addition, the types listed in 4.3 does not match the types in 6.3.

We've deliberately decoupled the interface of the main class here from the LoadData et.al. data structures, as the sniffing algorithm should probably be as independent as possible. The underlying data structure currently is pretty heavily dependent on the Composite pattern...this mostly emergent based on the way the document describes the algorithm. I believe I could expand the composite pattern more and DRY up some of the code duplication in the Uknown type and known type calculations, but it would make the control flow different than that of the document.

Our test data has been added to the `tests/content/parsable_mime/` folder. I've been building and running them with

`./mach rustc --test -g components/net/mime_classifier.rs`
`./mime_classifier`