mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Use context instead of response in static_headers helper (#681)
This commit is contained in:
		
							parent
							
								
									e69bd400b7
								
							
						
					
					
						commit
						6a29240bbe
					
				
					 3 changed files with 9 additions and 9 deletions
				
			
		|  | @ -141,11 +141,11 @@ describe Kemal::StaticFileHandler do | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   it "should handle setting custom headers" do |   it "should handle setting custom headers" do | ||||||
|     headers = Proc(HTTP::Server::Response, String, File::Info, Void).new do |response, path, stat| |     headers = Proc(HTTP::Server::Context, String, File::Info, Void).new do |env, path, stat| | ||||||
|       if path =~ /\.html$/ |       if path =~ /\.html$/ | ||||||
|         response.headers.add("Access-Control-Allow-Origin", "*") |         env.response.headers.add("Access-Control-Allow-Origin", "*") | ||||||
|       end |       end | ||||||
|       response.headers.add("Content-Size", stat.size.to_s) |       env.response.headers.add("Content-Size", stat.size.to_s) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     static_headers(&headers) |     static_headers(&headers) | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ module Kemal | ||||||
|     property app_name, host_binding, ssl, port, env, public_folder, logging, running |     property app_name, host_binding, ssl, port, env, public_folder, logging, running | ||||||
|     property always_rescue, server : HTTP::Server?, extra_options, shutdown_message |     property always_rescue, server : HTTP::Server?, extra_options, shutdown_message | ||||||
|     property serve_static : (Bool | Hash(String, Bool)) |     property serve_static : (Bool | Hash(String, Bool)) | ||||||
|     property static_headers : (HTTP::Server::Response, String, File::Info -> Void)? |     property static_headers : (HTTP::Server::Context, String, File::Info -> Void)? | ||||||
|     property? powered_by_header : Bool = true |     property? powered_by_header : Bool = true | ||||||
| 
 | 
 | ||||||
|     def initialize |     def initialize | ||||||
|  |  | ||||||
|  | @ -134,7 +134,7 @@ def send_file(env : HTTP::Server::Context, path : String, mime_type : String? = | ||||||
|   filestat = File.info(file_path) |   filestat = File.info(file_path) | ||||||
|   attachment(env, filename, disposition) |   attachment(env, filename, disposition) | ||||||
| 
 | 
 | ||||||
|   Kemal.config.static_headers.try(&.call(env.response, file_path, filestat)) |   Kemal.config.static_headers.try(&.call(env, file_path, filestat)) | ||||||
| 
 | 
 | ||||||
|   File.open(file_path) do |file| |   File.open(file_path) do |file| | ||||||
|     if env.request.method == "GET" && env.request.headers.has_key?("Range") |     if env.request.method == "GET" && env.request.headers.has_key?("Range") | ||||||
|  | @ -250,13 +250,13 @@ end | ||||||
| # Adds headers to `Kemal::StaticFileHandler`. This is especially useful for `CORS`. | # Adds headers to `Kemal::StaticFileHandler`. This is especially useful for `CORS`. | ||||||
| # | # | ||||||
| # ``` | # ``` | ||||||
| # static_headers do |response, filepath, filestat| | # static_headers do |env, filepath, filestat| | ||||||
| #   if filepath =~ /\.html$/ | #   if filepath =~ /\.html$/ | ||||||
| #     response.headers.add("Access-Control-Allow-Origin", "*") | #     env.response.headers.add("Access-Control-Allow-Origin", "*") | ||||||
| #   end | #   end | ||||||
| #   response.headers.add("Content-Size", filestat.size.to_s) | #   env.response.headers.add("Content-Size", filestat.size.to_s) | ||||||
| # end | # end | ||||||
| # ``` | # ``` | ||||||
| def static_headers(&headers : HTTP::Server::Response, String, File::Info -> Void) | def static_headers(&headers : HTTP::Server::Context, String, File::Info -> Void) | ||||||
|   Kemal.config.static_headers = headers |   Kemal.config.static_headers = headers | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue