Git Product home page Git Product logo

range-parser's People

Contributors

carpasse avatar dougwilson avatar jcready avatar jonathanong avatar nook-scheel avatar redchair123 avatar tj avatar zubairov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

range-parser's Issues

Support range unit ?

I have a REST API and using the range headers for my resource lists. The unit I am using is item (not bytes, obviously). I am actually handling it by my own.

I came across this module while looking at express dependencies.

Wouldn't it be better to not hard code the unit (bytes) ?

A range request is valid if ANY of the range-specifier values overlap the representation

If a valid byte-range-set includes at least one byte-range-spec with
a first-byte-pos that is less than the current length of the
representation, or at least one suffix-byte-range-spec with a
non-zero suffix-length, then the byte-range-set is satisfiable.
โ€” https://tools.ietf.org/html/rfc7233#section-2.1

The 416 (Range Not Satisfiable) status code indicates that none of
the ranges in the request's Range header field (Section 3.1) overlap
the current extent of the selected resource or that the set of ranges
requested has been rejected due to invalid ranges or an excessive
request of small or overlapping ranges. For byte ranges, failing to
overlap the current extent means that the first-byte-pos of all of the
byte-range-spec values were greater than the current length of the
selected representation.
โ€” https://tools.ietf.org/html/rfc7233#section-4.4

So the following tests should pass:

it('should omit any invalid ranges if at least one is valid', function(){
  var range = parse(200, 'bytes=0-499,500-999')
  assert.strictEqual(range.type, 'bytes')
  assert.strictEqual(range.length, 1)
  assert.deepEqual(range[0], { start: 0, end: 199 })
})

it('should return -1 if all specified ranges are invalid', function(){
  assert.strictEqual(parse(200, 'bytes=500-20'), -1)
  assert.strictEqual(parse(200, 'bytes=500-999'), -1)
  assert.strictEqual(parse(200, 'bytes=500-999,1000-1499'), -1)
})

rangeParser is not a function

Im working with a backend node server for our api and I need to use range parser

here is how I have it used:

import RangeParse from 'range-parser';
const ranges = RangeParse(100000, request.range, { combine: true });

this should yield the default export which indicates that this is a valid method. but I am recieving a crash error of:

 (0 , range_parser_1.default) is not a function
TypeError: (0 , range_parser_1.default) is not a function```

Why is size required

Hi,
I'm looking at your library to parse the range http header.
And I was wondering why you are making the size a required field, even though it is not part of the header.
A range is supposed to be like this:

Range: <unit>=<range-start>-
Range: <unit>=<range-start>-<range-end>
Range: <unit>=<range-start>-<range-end>, <range-start>-<range-end>
Range: <unit>=<range-start>-<range-end>, <range-start>-<range-end>, <range-start>-<range-end>

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range

I've tried to go around it by setting size to Infinity, but then when I use this format of header:

Range: bytes=10-

then it returns end: Infinity instead of null.

I've read the comment here: https://github.com/expressjs/express/blob/b97faff6e2aa4d34d79485fe4331cb0eec13ad57/lib/request.js#L188
But if you look at these simple examples:
https://stackoverflow.com/questions/8293687/sample-http-range-request-session#answer-8507991
The client is only sending the range, without any content-length.

Or do you mean that in order to parse the range, the server should get the size of the file, given that he will need it to correctly format the content-range header in the response.

Range: bytes=0-

Chrome (version: Version 42.0.2311.135 linux) generates a Range request with this value:

Range: bytes=0-

range-parser returns :

{ start: 0, end: 0 }

Some libraries (send) seems to be disturb by this value ...

I'm using this patch:

if(end == start) {
  end = size-start-1;
}

But i'm sure that it's true?

Thanks

the `size` parameter should probably be optional

One issue with the existing API is it assumes size is always known up-front. but for live streams this isn't possible.

I believe according to the spec, in the case of a stream that doesn't have a known length it's acceptable to return the bytes that are available, and just leave the length as * https://www.rfc-editor.org/rfc/rfc7233.html#section-4.2 :

this second example illustrates when the complete length is
   unknown:

     Content-Range: bytes 42-1233/*

Would you be an open to a PR that supports this? It would definitely require a semver major bump were it approved though.

Relates to #16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.