private static long GetRangeLength(HttpRange range, long contentLength, out long start, out long end)
        {
            if (contentLength == 0)
            {
                start = end = 0;
                return 0;
            }
            start = range.Start ?? 0;
            end = range.End ?? (contentLength - 1);

            return end - start + 1;
        }
        private static Task SendRange(HttpRange range, IStaticResponse response, Stream responseStream, IOwinContext ctx)
        {
            long? length = response.Headers.ContentLength.Value;
            if (!length.HasValue || length.Value == 0)
            {
                SendFullResponse(response, responseStream, ctx);
            }

            long start, end;
            // ReSharper disable PossibleInvalidOperationException
            long rangeLength = GetRangeLength(range, length.Value, out start, out end);
            // ReSharper restore PossibleInvalidOperationException
            if (start < 0 || start >= length.Value || end >= length.Value || rangeLength <= 0)
            {
                return SendRequestedRangeNotSatisfiable(ctx, responseStream);
            }

            SetResponseHeaders(Constants.Http.StatusCodes.Successful.PartialContent, response.Headers, ctx.Response,
                               Constants.Http.Headers.ContentLength);
            ctx.Response.Headers.ContentRange.Range = new HttpContentRange(start, end, length.Value);
            ctx.Response.Headers.ContentLength.Value = rangeLength;

            return SendStreamAsync(responseStream, ctx.Response.Body, start, rangeLength, ctx.CallCancelled);
        }
Beispiel #3
0
 protected void SetRange(HttpRange range)
 {
     SetSingleValue(range == null ? null : range.ToString());
 }