mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	fix process request when a response already closed (#550)
This commit is contained in:
		
							parent
							
								
									ff3b28c6f7
								
							
						
					
					
						commit
						e99129ab50
					
				
					 2 changed files with 19 additions and 0 deletions
				
			
		|  | @ -63,6 +63,24 @@ describe "Macros" do | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   describe "#callbacks" do | ||||||
|  |     it "can break block with halt macro from before_* callback" do | ||||||
|  |       filter_middleware = Kemal::FilterHandler.new | ||||||
|  |       filter_middleware._add_route_filter("GET", "/", :before) do |env| | ||||||
|  |         halt env, status_code: 400, response: "Missing origin." | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|  |       get "/" do |env| | ||||||
|  |         "Hello world" | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|  |       request = HTTP::Request.new("GET", "/") | ||||||
|  |       client_response = call_request_on_app(request) | ||||||
|  |       client_response.status_code.should eq(400) | ||||||
|  |       client_response.body.should eq("Missing origin.") | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   describe "#headers" do |   describe "#headers" do | ||||||
|     it "can add headers" do |     it "can add headers" do | ||||||
|       get "/headers" do |env| |       get "/headers" do |env| | ||||||
|  |  | ||||||
|  | @ -45,6 +45,7 @@ module Kemal | ||||||
|     # Processes the route if it's a match. Otherwise renders 404. |     # Processes the route if it's a match. Otherwise renders 404. | ||||||
|     private def process_request(context) |     private def process_request(context) | ||||||
|       raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_found? |       raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_found? | ||||||
|  |       return if context.response.closed? | ||||||
|       content = context.route.handler.call(context) |       content = context.route.handler.call(context) | ||||||
| 
 | 
 | ||||||
|       if !Kemal.config.error_handlers.empty? && Kemal.config.error_handlers.has_key?(context.response.status_code) |       if !Kemal.config.error_handlers.empty? && Kemal.config.error_handlers.has_key?(context.response.status_code) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue