Esempio n. 1
0
        private List <string> Parse(string range)
        {
            List <string> result = new List <string>();
            int           start, end;
            string        startColumnString, endColumnString;

            if (!RangeHelper.ParseRange(range, out startColumnString, out endColumnString, out start, out end))
            {
                return(result);
            }

            if (start != 0 && end != 0 && start <= end)
            {
                ExpandRange(result, startColumnString, endColumnString, start, end);
            }
            else if (start == 0 && end == 0)
            {
                start = 1;
                end   = maximumRowCount;
                ExpandRange(result, startColumnString, endColumnString, start, end);
            }
            else if (end == 0 && start != 0)
            {
                end = maximumRowCount;

                ExpandRange(result, startColumnString, endColumnString, start, end);
            }
            else
            {
                throw new InvalidOperationException("Invalid range");
            }

            return(result);
        }
Esempio n. 2
0
        private static bool ValidLatitude(string?range)
        {
            var parsedRange = RangeHelper.ParseRange(range);

            if (parsedRange == null)
            {
                return(false);
            }

            return(Angle.FromRadians(parsedRange.Value.Start).Degrees <= 90 && Angle.FromRadians(parsedRange.Value.End).Degrees >= -90);
        }
        private void ComputeRange()
        {
            // 14.35 Range
            // http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-24

            // A server MUST ignore a Range header field received with a request method other
            // than GET.
            if (!_isGet)
            {
                return;
            }

            (_isRangeRequest, _range) = RangeHelper.ParseRange(_context, _requestHeaders, _length, _logger);
        }
Esempio n. 4
0
    public void ParseRange_ReturnsNullWhenMultipleRangesProvidedInRangeHeader(string range)
    {
        // Arrange
        var httpContext = new DefaultHttpContext();

        httpContext.Request.Headers.Range = range;

        // Act
        var(isRangeRequest, parsedRangeResult) = RangeHelper.ParseRange(httpContext, httpContext.Request.GetTypedHeaders(), 10, NullLogger.Instance);

        // Assert
        Assert.False(isRangeRequest);
        Assert.Null(parsedRangeResult);
    }
Esempio n. 5
0
        private static bool ValidRange(string?range)
        {
            var parsedRange = RangeHelper.ParseRange(range);

            if (parsedRange == null)
            {
                return(false);
            }

            // Ensure that the start angle isn't the same as the end
            var unwrappedRange = parsedRange.Value.UnwrapLongitude();

            return(Math.Abs(unwrappedRange.Start - unwrappedRange.End) > Constants.FloatingTolerance);
        }
Esempio n. 6
0
    public void ParseRange_ReturnsSingleRangeWhenInputValid()
    {
        // Arrange
        var httpContext = new DefaultHttpContext();
        var range       = new RangeHeaderValue(1, 2);

        httpContext.Request.Headers.Range = range.ToString();

        // Act
        var(isRangeRequest, parsedRange) = RangeHelper.ParseRange(httpContext, httpContext.Request.GetTypedHeaders(), 4, NullLogger.Instance);

        // Assert
        Assert.True(isRangeRequest);
        Assert.Equal(1, parsedRange.From);
        Assert.Equal(2, parsedRange.To);
    }
Esempio n. 7
0
        private static (RangeItemHeaderValue?range, long rangeLength, bool serveBody) SetRangeHeaders(
            HttpContext httpContext,
            RequestHeaders httpRequestHeaders,
            long fileLength,
            ILogger logger)
        {
            var response            = httpContext.Response;
            var httpResponseHeaders = response.GetTypedHeaders();
            var serveBody           = !HttpMethods.IsHead(httpContext.Request.Method);

            // Range may be null for empty range header, invalid ranges, parsing errors, multiple ranges
            // and when the file length is zero.
            var(isRangeRequest, range) = RangeHelper.ParseRange(
                httpContext,
                httpRequestHeaders,
                fileLength,
                logger);

            if (!isRangeRequest)
            {
                return(range : null, rangeLength : 0, serveBody);
            }

            // Requested range is not satisfiable
            if (range == null)
            {
                // 14.16 Content-Range - A server sending a response with status code 416 (Requested range not satisfiable)
                // SHOULD include a Content-Range field with a byte-range-resp-spec of "*". The instance-length specifies
                // the current length of the selected resource.  e.g. */length
                response.StatusCode = StatusCodes.Status416RangeNotSatisfiable;
                httpResponseHeaders.ContentRange = new ContentRangeHeaderValue(fileLength);
                response.ContentLength           = 0;

                return(range : null, rangeLength : 0, serveBody : false);
            }

            response.StatusCode = StatusCodes.Status206PartialContent;
            httpResponseHeaders.ContentRange = new ContentRangeHeaderValue(
                range.From !.Value,
                range.To !.Value,
                fileLength);

            // Overwrite the Content-Length header for valid range requests with the range length.
            var rangeLength = SetContentLength(response, range);

            return(range, rangeLength, serveBody);
        }