Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix parsing multiple ranges

Fix parsing miltiple ranges in HTTP_RANGE header according to w3 rfc2616 (according to last example in sec14.35.1 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1 ) (according to BNF rules in http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.1 )
  • Loading branch information...
commit 251e6e0fbaf404ac3ae897c24c08b5392413881e 1 parent 1824547
Sokolov Yura authored November 09, 2012

Showing 1 changed file with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. 12  lib/rack/utils.rb
12  lib/rack/utils.rb
@@ -316,16 +316,16 @@ def rfc2822(time)
316 316
     def byte_ranges(env, size)
317 317
       # See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35>
318 318
       http_range = env['HTTP_RANGE']
319  
-      return nil unless http_range
  319
+      return nil unless http_range && http_range =~ /bytes=([^;]+)/
320 320
       ranges = []
321  
-      http_range.split(/,\s*/).each do |range_spec|
322  
-        matches = range_spec.match(/bytes=(\d*)-(\d*)/)
323  
-        return nil  unless matches
324  
-        r0,r1 = matches[1], matches[2]
  321
+      $1.split(/,\s*/).each do |range_spec|
  322
+        return nil  unless range_spec =~ /(\d*)-(\d*)/
  323
+        r0,r1 = $1, $2
325 324
         if r0.empty?
326 325
           return nil  if r1.empty?
327 326
           # suffix-byte-range-spec, represents trailing suffix of file
328  
-          r0 = [size - r1.to_i, 0].max
  327
+          r0 = size - r1.to_i
  328
+          r0 = 0  if r0 < 0
329 329
           r1 = size - 1
330 330
         else
331 331
           r0 = r0.to_i

0 notes on commit 251e6e0

Please sign in to comment.
Something went wrong with that request. Please try again.