mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Early return from range if request type is not GET
This commit is contained in:
		
							parent
							
								
									0543142a10
								
							
						
					
					
						commit
						476b27892e
					
				
					 5 changed files with 37 additions and 40 deletions
				
			
		|  | @ -1,30 +1,30 @@ | ||||||
| require "./spec_helper" | require "./spec_helper" | ||||||
| 
 | 
 | ||||||
| describe "Run" do | describe "Run" do | ||||||
|   it "runs a code block after starting" do |   it "runs a code block after starting" do | ||||||
|     Kemal.config.env = "test" |     Kemal.config.env = "test" | ||||||
|     make_me_true = false |     make_me_true = false | ||||||
|     Kemal.run do |     Kemal.run do | ||||||
|       make_me_true = true |       make_me_true = true | ||||||
|       Kemal.stop |       Kemal.stop | ||||||
|     end |     end | ||||||
|     make_me_true.should eq true |     make_me_true.should eq true | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   it "runs without a block being specified" do |   it "runs without a block being specified" do | ||||||
|     Kemal.config.env = "test" |     Kemal.config.env = "test" | ||||||
|     Kemal.run |     Kemal.run | ||||||
|     Kemal.config.running.should eq true |     Kemal.config.running.should eq true | ||||||
|     Kemal.stop |     Kemal.stop | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   it "runs with just a block" do |   it "runs with just a block" do | ||||||
|     Kemal.config.env = "test" |     Kemal.config.env = "test" | ||||||
|     make_me_true = false |     make_me_true = false | ||||||
|     Kemal.run do |     Kemal.run do | ||||||
|       make_me_true = true |       make_me_true = true | ||||||
|       Kemal.stop |       Kemal.stop | ||||||
|     end |     end | ||||||
|     make_me_true.should eq true |     make_me_true.should eq true | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -119,9 +119,9 @@ describe Kemal::StaticFileHandler do | ||||||
|         match = response.headers["Content-Range"].match(/bytes (\d+)-(\d+)\/(\d+)/) |         match = response.headers["Content-Range"].match(/bytes (\d+)-(\d+)\/(\d+)/) | ||||||
|         match.should_not be nil |         match.should_not be nil | ||||||
|         if match |         if match | ||||||
|           start_range = match[1].to_i {0} |           start_range = match[1].to_i { 0 } | ||||||
|           end_range = match[2].to_i {0} |           end_range = match[2].to_i { 0 } | ||||||
|           range_size = match[3].to_i {0} |           range_size = match[3].to_i { 0 } | ||||||
| 
 | 
 | ||||||
|           range_size.should eq file_size |           range_size.should eq file_size | ||||||
|           (end_range < file_size).should eq true |           (end_range < file_size).should eq true | ||||||
|  |  | ||||||
|  | @ -4,7 +4,6 @@ require "./kemal/*" | ||||||
| require "./kemal/helpers/*" | require "./kemal/helpers/*" | ||||||
| 
 | 
 | ||||||
| module Kemal | module Kemal | ||||||
| 
 |  | ||||||
|   # Overload of self.run with the default startup logging |   # Overload of self.run with the default startup logging | ||||||
|   def self.run(port = nil) |   def self.run(port = nil) | ||||||
|     self.run port do |     self.run port do | ||||||
|  | @ -14,9 +13,8 @@ module Kemal | ||||||
| 
 | 
 | ||||||
|   # Overload of self.run to allow just a block |   # Overload of self.run to allow just a block | ||||||
|   def self.run(&block) |   def self.run(&block) | ||||||
|     self.run nil &block |     self.run nil & block | ||||||
|   end |   end | ||||||
|     |  | ||||||
| 
 | 
 | ||||||
|   # The command to run a `Kemal` application. |   # The command to run a `Kemal` application. | ||||||
|   # The port can be given to `#run` but is optional. |   # The port can be given to `#run` but is optional. | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| class HTTP::Server::Response | class HTTP::Server::Response | ||||||
|   class Output |   class Output | ||||||
|     def close |     def close | ||||||
| 
 |  | ||||||
|       unless response.wrote_headers? && !response.headers.has_key?("Content-Range") |       unless response.wrote_headers? && !response.headers.has_key?("Content-Range") | ||||||
|         response.content_length = @out_count |         response.content_length = @out_count | ||||||
|       end |       end | ||||||
|  |  | ||||||
|  | @ -56,7 +56,7 @@ module Kemal | ||||||
|         request_headers = context.request.headers |         request_headers = context.request.headers | ||||||
|         filesize = File.size(file_path) |         filesize = File.size(file_path) | ||||||
|         File.open(file_path) do |file| |         File.open(file_path) do |file| | ||||||
|           if context.request.headers.has_key?("Range") && context.request.method == "GET" |           if context.request.method == "GET" && context.request.headers.has_key?("Range") | ||||||
|             next multipart(file, context) |             next multipart(file, context) | ||||||
|           end |           end | ||||||
|           if request_headers.includes_word?("Accept-Encoding", "gzip") && config.is_a?(Hash) && config["gzip"] == true && filesize > minsize && Utils.zip_types(file_path) |           if request_headers.includes_word?("Accept-Encoding", "gzip") && config.is_a?(Hash) && config["gzip"] == true && filesize > minsize && Utils.zip_types(file_path) | ||||||
|  | @ -80,7 +80,7 @@ module Kemal | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def multipart(file, env) |     def multipart(file, env) | ||||||
|       #See http://httpwg.org/specs/rfc7233.html |       # See http://httpwg.org/specs/rfc7233.html | ||||||
|       fileb = file.size |       fileb = file.size | ||||||
| 
 | 
 | ||||||
|       range = env.request.headers["Range"] |       range = env.request.headers["Range"] | ||||||
|  | @ -100,7 +100,7 @@ module Kemal | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       if endb == 0 |       if endb == 0 | ||||||
|           endb = fileb |         endb = fileb | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       if startb < endb && endb <= fileb |       if startb < endb && endb <= fileb | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue