HTTP Examples

Exploring HTTP on the Windows Platform.

MIMEParse Port to C# Posted


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:

TO-DO Sample Posted


I posted a simple TO-DO app to show how easy it is to support the HTTP DELETE method using modern browsers. I did this as a follow up to my rant after find (yet another) example of mis-using POST in an ASP.NET/MVC code snippet.

This first step is to render the TO-DO item as HTML. Below is my example using XSLT to convert raw data (from SDS into the proper HTML:

<xsl:template match="todo">
    <xsl:value-of select="message"/>
    <form name="delete-form" class="delete-form" action="{s:Id}" method="get" 
      rel="delete" refresh="/{$root}/" style="display:none;">
      <input type="submit" value="Delete" />

The important code in my example is the following client-side Javascript (in response to a FORM POST:

  function deleteItem()
    var formName,refreshUrl;
    formName = this.getAttribute('name');
    refreshUrl = this.getAttribute('refresh');
    ajax.httpDeleteForm(null, null, deleteCallback, false, refreshUrl,formName);
    return false;        
  function deleteCallback(response,headers,context,status,msg)
    return false;

The point here is that you can use standard FORM POST HTML markup to render the UI and use javascript to link an Ajax DELETE to the FORM. There is no need to 'overload' POST with other meanings (like 'delete this thing' or 'update this thing' or 'wash my socks', etc.)

Feel free to download the code example from GitHub (see link above) and play around with it. Feedback is welcome, too.