File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,23 @@ internals.Range = class {
18
18
} ;
19
19
20
20
21
+ // RFC 7233 (https://tools.ietf.org/html/rfc7233#appendix-D)
22
+ //
23
+ // Range = "bytes" "=" byte-range-set
24
+ // byte-range-set = *( "," OWS ) byte-range-spec *( OWS "," [ OWS byte-range-spec ] )
25
+ // byte-range-spec = ( 1*DIGIT "-" [ 1*DIGIT ] ) / ( "-" 1*DIGIT )
26
+
27
+
28
+ // 12 3 3 4 425 6 7 7 8 865 1
29
+ internals . headerRx = / ^ b y t e s = [ \s , ] * ( (?: (?: \d + \- \d * ) | (?: \- \d + ) ) (?: \s * , \s * (?: (?: \d + \- \d * ) | (?: \- \d + ) ) ) * ) $ / i;
30
+
31
+
21
32
exports . header = function ( header , length ) {
22
33
23
34
// Parse header
24
35
25
- const parts = header . split ( '=' ) ;
26
- if ( parts . length !== 2 ||
27
- parts [ 0 ] !== 'bytes' ) {
28
-
36
+ const parts = internals . headerRx . exec ( header ) ;
37
+ if ( ! parts ) {
29
38
return null ;
30
39
}
31
40
@@ -36,12 +45,7 @@ exports.header = function (header, length) {
36
45
37
46
// Handle headers with multiple ranges
38
47
39
- for ( let i = 0 ; i < ranges . length ; ++ i ) {
40
- let range = ranges [ i ] ;
41
- if ( range . length === 1 ) { // '-'
42
- return null ;
43
- }
44
-
48
+ for ( let range of ranges ) {
45
49
let from ;
46
50
let to ;
47
51
range = range . split ( '-' ) ;
You can’t perform that action at this time.
0 commit comments