I am designing a web application for iPad which makes use of HTML5 in mobile safari. I am transmitting the file manually through an ASP.NET .ashx file hosted on IIS 7 running .NET Framework v2.0.

The essential code looks partly like this:

// If we receive range header only transmit partial file
if (context.Request.Headers["Range"] != null)
{
    var fi = new FileInfo(filePath);
    long fileSize = fi.Length;

    // Read start/end index
    string headerRange = context.Request.Headers["Range"].Replace("bytes=", "");
    string[] range = headerRange.Split('-');
    int startIndex = Convert.ToInt32(range[0]);
    int endIndex = Convert.ToInt32(range[1]);

    // Add header Content-Range,Last-Modified
    context.Response.StatusCode = (int)HttpStatusCode.PartialContent;
    context.Response.AddHeader(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderContentRange), String.Format("bytes {0}-{1}/{2}", startIndex, endIndex, fileSize));
    context.Response.AddHeader(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderLastModified), String.Format("{0:r}", fi.CreationTime));

    long length = (endIndex - startIndex) + 1;
    context.Response.TransmitFile(filePath, startIndex, length);
}
else
    context.Response.TransmitFile(filePath);

Now what confuses me to no end is the the protocols for requesting that safari seems to use. From proxying the requests through fiddler i get the following for an aprox 2MB file.

Fiddler requests

NOTE: When requesting an mp4 file, directly served through IIS 7, the protocol and amount of request are the same

  1. First it requests 2 bytes which allows it to read the 'Content-Range' header.
  2. Now it request the entire content (?)
  3. -
  4. It proceeds to do step 1. & 2. again (??)
  5. -
  6. It now requests only parts of the file (???)

Edit
Report