mimeparse C# port

4 views
Skip to first unread message

mca

unread,
Feb 10, 2009, 11:46:08 PM2/10/09
to Mimeparse-dev
I posted a C# port of the mimeparse library to github:
http://github.com/mamund/mimeparse-csharp/tree/master

I included a simple console app that runs an example and kicks off
simple Debug.Assert code to run the tests.

My initial tests failed for the following cases:
// match using a subtype wildcard
Debug.Assert(MimeParse.BestMatch(mimeTypesSupported, "application/*;
q=1") == "application/xml");
// match using a type wildcard
Debug.Assert(MimeParse.BestMatch(mimeTypesSupported, "*/*") ==
"application/xml");

In both cases, my code returned the "application/xbel+xml" MIME-type.
I modified FitnessAndQuality.CompareTo(object x) method to solve this
problem:
if (this._fitness == faq._fitness)
{
if (this._quality == faq._quality)
{
rtn = string.Compare(this._mimeType, faq._mimeType, true); // sort
using the MimeType for ties
}
else
{
rtn = (this._quality < faq._quality ? -1 : 1);
}
}
else
{
rtn = (this._fitness < faq._fitness ? -1 : 1);
}

I suspect this is not correct. What are the selection rules that
govern cases where the */* type is the only one passed in the Accept
header?

Looking forward to any comments/questions.

MikeA

mca

unread,
Feb 18, 2009, 6:50:04 PM2/18/09
to Mimeparse-dev
I've updated the MIMEParse.cs port.

It now passes the wildcard tests by maintaining the original order of
the FitnessAndQualityCollection.

MCA
Reply all
Reply to author
Forward
0 new messages