MIMEParse port to C#

2009-02-18 @ 19:45#

I posted a full port of Joe Gregorio's MIMEParse utilty. The primary method of this utility accepts two inputs:

A string array of MIME types
Such as those supported by a web server for a selected resource
A single string of acceptable MIME types
Sush as those sent by common browsers in the Accept Header when requesting a resource from a web server

The utility evaluates the options based on rules in the RFC2616 section 14.1 and returns the "best match" as a result (or no result if no match can be found). Below are some test examples:

mimeTypesSupported = new string[] { "application/xbel+xml", "text/xml" };
// match using a type versus a lower weighted subtype
Debug.Assert(MimeParse.BestMatch(mimeTypesSupported, "text/*;q=0.5,*/*; q=0.1") == "text/xml");
// fail to match anything
Debug.Assert(MimeParse.BestMatch(mimeTypesSupported, "text/html,application/atom+xml; q=0.9") == string.Empty);
			

Some other links:

code