mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Update handler
This commit is contained in:
		
							parent
							
								
									c47c9488fe
								
							
						
					
					
						commit
						b4bc818490
					
				
					 3 changed files with 3 additions and 3 deletions
				
			
		|  | @ -1,7 +1,7 @@ | |||
| HTTP_METHODS = %w(get post put patch delete options) | ||||
| 
 | ||||
| {% for method in HTTP_METHODS %} | ||||
|   def {{method.id}}(path, &block : HTTP::Server::Context -> String) | ||||
|   def {{method.id}}(path, &block : HTTP::Server::Context -> _) | ||||
|    Kemal::RouteHandler::INSTANCE.add_route({{method}}.upcase, path, &block) | ||||
|   end | ||||
| {% end %} | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ class Kemal::Route | |||
|   @handler : HTTP::Server::Context -> String | ||||
|   @method : String | ||||
| 
 | ||||
|   def initialize(@method, @path : String, &handler ) | ||||
|   def initialize(@method, @path : String, &handler : HTTP::Server::Context -> _) | ||||
|     @handler = ->(context : HTTP::Server::Context){ handler.call(context).to_s } | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ class Kemal::RouteHandler < HTTP::Handler | |||
| 
 | ||||
|   # Adds a given route to routing tree. As an exception each `GET` route additionaly defines | ||||
|   # a corresponding `HEAD` route. | ||||
|   def add_route(method, path, &handler : HTTP::Server::Context -> String) | ||||
|   def add_route(method, path, &handler : HTTP::Server::Context -> _) | ||||
|     add_to_radix_tree method, path, Route.new(method, path, &handler) | ||||
|     add_to_radix_tree("HEAD", path, Route.new("HEAD", path, &handler)) if method == "GET" | ||||
|   end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue