Some of my services return video - I am wondering if there’s a good way to detect that an inbound request is a range request vs. perhaps the original request of the resource. My current test is to see if the header Range is either not present, or is present and starts with the string “bytes=0-”. I also make sure the request is a GET (because it appears that some browsers do a HEAD to see if range requests are supported).
This test doesn’t seem to work in all cases.
The reasons I want to detect this is 1) accurate logging of how many videos have been requested, and 2) I want to send some extra information back in the response headers for the first request.
Have a look at the 2 places where ServiceStack checks for HTTP Range requests, when returning a file or stream in a HttpResult:
And if a HTTP Range request was made to a static file:
Note: in order to check for Range requests in both Service and static file requests you’ll need to register a IAppHost.PreRequestFilters which is the first filter in the Request Pipeline.