|
Project Information
Members
Featured
Downloads
Links
|
This module provides basic functions for parsing mime-type names and matching them against a list of media-ranges. See section 14.1 of RFC 2616 (the HTTP specification) for a complete explanation. More information on the library can be found in the XML.com article Just use Media Types? Contents
UsageIn Erlang1> mimeparse:best_match(["application/xbel+xml", "text/xml"], "text/*;q=0.5,*/*; q=0.1"). "text/xml" Note that neither quality_parsed() nor fitness_and_quality_parsed() are exported from the Erlang version. In JavaScriptRhino 1.7 release 1 2008 03 06
js> load('mimeparse.js');
js> Mimeparse.bestMatch(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*/*; q=0.1');
text/xmlThis example uses the Rhino JavaScript shell but usage should be similar for other JavaScript environments. In Perluse MIMEParse qw( best_match ); print best_match(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*/*; q=0.1'); # text/xml In PHPinclude_once 'mimeparse.php';
echo Mimeparse::best_match(array('application/xbel+xml', 'text/xml'),
'text/*;q=0.5,*/*; q=0.1');
==>"text/xml"In Python>>> import mimeparse
>>> mimeparse.best_match(['application/xbel+xml', 'text/xml'],
'text/*;q=0.5,*/*; q=0.1')
'text/xml'In Rubyrequire "mimeparse"
==>true
MIMEParse.best_match(['application/xbel+xml', 'text/xml'],
'text/*;q=0.5,*/*; q=0.1')
==>"text/xml"In JavaList<String> mimeTypesSupported = Arrays.asList(StringUtils.split(
"application/xbel+xml,text/xml", ','));
String bestMatch = MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1");In Goimport "mimeparse" bestmatch := mimeparse.BestMatch(["application/xbel+xml", "text/xml"], "text/*;q=0.5,*/*; q=0.1"); |