about summary refs log tree commit homepage
path: root/extras/try_gzip_static.rb
diff options
context:
space:
mode:
Diffstat (limited to 'extras/try_gzip_static.rb')
-rw-r--r--extras/try_gzip_static.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/extras/try_gzip_static.rb b/extras/try_gzip_static.rb
index d412589..4dd435a 100644
--- a/extras/try_gzip_static.rb
+++ b/extras/try_gzip_static.rb
@@ -49,7 +49,7 @@ class TryGzipStatic
     end
 
     size = st.size
-    ranges = Rack::Utils.byte_ranges(env, size)
+    ranges = byte_ranges(env, size)
     if ranges.nil? || ranges.length > 1
       [ 200 ] # serve the whole thing, possibly with static gzip \o/
     elsif ranges.empty?
@@ -221,4 +221,12 @@ class TryGzipStatic
       [ code, h, [ msg ] ]
     end
   end
+
+  if Rack::Utils.respond_to?(:get_byte_ranges) # rack 2.0+
+    def byte_ranges(env, size)
+      Rack::Utils.get_byte_ranges(env['HTTP_RANGE'], size)
+    end
+  else # rack 1.x
+    def byte_ranges(env, size); Rack::Utils.byte_ranges(env, size); end
+  end
 end