jshttp / range-parser Goto Github PK
View Code? Open in Web Editor NEWRange header field parser
License: MIT License
Range header field parser
License: MIT License
npm WARN package.json [email protected] No repository field.
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) ?
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.1The 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)
})
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```
I've asked this question on StackOverflow as well because there doesn't seem to be much activity here. Seems I'm misunderstanding something?
annoying!!!
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.
thank you...
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
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
Expected:
parse(200, 'bytes=x-100') === -2
Actual:
parse(200, 'bytes=x-100') === [ { start: 0, end: 199 }, type: 'bytes' ]
I skimmed the source and it seems as if it should work fine in a browser, but the README specifies this as a Node module.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.