Implementation question...

May 26, 2011 at 5:49 PM

This project solved a big problem of mine, streaming MP4 content to iOS devices from an MVC controller.  It was easy to implement.  Thank you.

I think that further documentation would be helpful.  I implemented by action based off of your example, but I'd like to have a better understanding for all of the classes.  Also, I'm not clear on why the method argument name must be given to the action filter?

May 26, 2011 at 6:12 PM

It's true I'm quite bad at documentation. I've been looking at farming this out but it turns out not many other people are interested in documentation either!

Do you have any specific suggestions for improvement? Was there any part you found you needed to look at the code to figure out what it did? This was my first ever OSS project and I've learned a lot since but I haven't had a lot of time to reinvest into making many improvements. Without specific feedback I have a hard time figuring out if and what needs attention.

With respect to the method name, I thought this was the easiest way to specify where the parsed request header information should be stored. This is made available in the action in case you want to see if the request was partial in case this would reduce resource loading by only pulling a subset of the data rather than the whole object. I think I was aiming for maximum flexibility because I had no idea how it would be used. In experimental code I never completed/checked-in I have a method for abstracting all this away completely and handle the parsing and response automatically. Would this be a feature you would find helpful?

Thanks so much for taking the time to leave feedback. I really appreciate knowing how the project is being used (or just that it IS being used!) and the feedback helps force me to focus on making things better.

May 27, 2011 at 4:46 PM

One thing that I'm not clear on is the purpose of the Precondition classes.  Any help on that?

May 27, 2011 at 4:57 PM
Edited May 27, 2011 at 5:17 PM

Preconditions are request headers that dictate the type of HTTP response that is returned.

Essentially a client can request a resource path, specify the range of bytes it wants from that resource but only if the following condition is true. The types we support (and from what I can tell is all that is required from the HTTP 1.1 spec) are IfMatch, IfModifiedSince, IfNoneMatch, IfRange, and IfUnmodifiedSince.

Each of those preconditions has a parameter that is specified. For instance, IfModifiedSince will supply a date that it previously obtained for the same resource. Our job is to figure out if the resource has been modified since. If it has, we respond with a success code and the data it has requested. If it has not been modified, we can save time and bandwidth by returning 304 - Not Modified. This instructs the client to use their own cache rather than re-downloading the resource.

Each of the preconditions, their parameters and how a server should respond are all documented in the HTTP specification. Though all situations could happen, in reality I've only seen use of IfMatch, IfModifiedSince and rarely IfNoneMatch.

This is the resource I used when determining how to deal with HTTP headers:

The Precondition classes were just an attempt at parsing out these "where clauses" and executing the logic necessary to return the proper status codes: 200, 206, 304 being the most common.


Does this answer your question? Or were you more interested in why I did it the way I did? Because I have no real excuse for that. :)

May 27, 2011 at 5:08 PM

The reason I ask is I've been seeing two iOS devices load the video and play it fine the first time, then subsequent times just show a black screen.  The IIS logs indicate that an HTTP 304 is being sent on the subsequent requests.  So, I thought maybe the device was stopping after receiving the "Not Modified" header.

I removed the PreCondition methods from your code and now the devices work after multiple refreshes.  IIS logs show HTTP 206 (Partial Content).

May 27, 2011 at 5:15 PM

That seems like a bug in iOS. Can you let me know which iOS version that was? With my devices on (at the time) 3.x I would see two requests, the first with IfModifiedSince to which I'd respond with a 304 and then immediately the same request without the IfModifiedSince precondition. I assumed it was the client checking to see if there was an update, seeing there wasn't but then realizing it doesn't have the data in local cache so requesting again.

It sounds like your clients aren't making the second request.

May 27, 2011 at 5:19 PM

Thanks. One device is an iPhone version 4.3.1.  The other is an iPad 2 version 4.3.