mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Improve namings
This commit is contained in:
		
							parent
							
								
									30bdcc9759
								
							
						
					
					
						commit
						61caa077b7
					
				
					 5 changed files with 19 additions and 19 deletions
				
			
		|  | @ -9,7 +9,7 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("GET", "/greetings", :before) { test_filter.modified = "true" } |     filter_middleware._add_route_filter("GET", "/greetings", :before) { test_filter.modified = "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
|     request = HTTP::Request.new("GET", "/greetings") |     request = HTTP::Request.new("GET", "/greetings") | ||||||
|  | @ -27,8 +27,8 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("GET", "/greetings", :before) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } |     filter_middleware._add_route_filter("GET", "/greetings", :before) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
|     kemal.add_http_route "POST", "/greetings" { test_filter.modified } |     kemal.add_route "POST", "/greetings" { test_filter.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
| 
 | 
 | ||||||
|  | @ -55,8 +55,8 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("POST", "/greetings", :before) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } |     filter_middleware._add_route_filter("POST", "/greetings", :before) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
|     kemal.add_http_route "POST", "/greetings" { test_filter.modified } |     kemal.add_route "POST", "/greetings" { test_filter.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
| 
 | 
 | ||||||
|  | @ -81,7 +81,7 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("GET", "/greetings", :after) { test_filter.modified = "true" } |     filter_middleware._add_route_filter("GET", "/greetings", :after) { test_filter.modified = "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
|     request = HTTP::Request.new("GET", "/greetings") |     request = HTTP::Request.new("GET", "/greetings") | ||||||
|  | @ -99,8 +99,8 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("GET", "/greetings", :after) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } |     filter_middleware._add_route_filter("GET", "/greetings", :after) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
|     kemal.add_http_route "POST", "/greetings" { test_filter.modified } |     kemal.add_route "POST", "/greetings" { test_filter.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
| 
 | 
 | ||||||
|  | @ -127,8 +127,8 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("POST", "/greetings", :after) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } |     filter_middleware._add_route_filter("POST", "/greetings", :after) { test_filter.modified = test_filter.modified == "true" ? "false" : "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
|     kemal.add_http_route "POST", "/greetings" { test_filter.modified } |     kemal.add_route "POST", "/greetings" { test_filter.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
|     request = HTTP::Request.new("GET", "/greetings") |     request = HTTP::Request.new("GET", "/greetings") | ||||||
|  | @ -158,9 +158,9 @@ describe "Kemal::FilterHandler" do | ||||||
|     filter_middleware._add_route_filter("ALL", "/greetings", :before) { test_filter_third.modified = test_filter_third.modified == "true" ? "false" : "true" } |     filter_middleware._add_route_filter("ALL", "/greetings", :before) { test_filter_third.modified = test_filter_third.modified == "true" ? "false" : "true" } | ||||||
| 
 | 
 | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "GET", "/greetings" { test_filter.modified } |     kemal.add_route "GET", "/greetings" { test_filter.modified } | ||||||
|     kemal.add_http_route "POST", "/greetings" { test_filter_second.modified } |     kemal.add_route "POST", "/greetings" { test_filter_second.modified } | ||||||
|     kemal.add_http_route "PUT", "/greetings" { test_filter_third.modified } |     kemal.add_route "PUT", "/greetings" { test_filter_third.modified } | ||||||
| 
 | 
 | ||||||
|     test_filter.modified.should eq("false") |     test_filter.modified.should eq("false") | ||||||
|     test_filter_second.modified.should eq("false") |     test_filter_second.modified.should eq("false") | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ describe "ParamParser" do | ||||||
| 
 | 
 | ||||||
|   it "parses url params" do |   it "parses url params" do | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "POST", "/hello/:hasan" do |env| |     kemal.add_route "POST", "/hello/:hasan" do |env| | ||||||
|       "hello #{env.params.url["hasan"]}" |       "hello #{env.params.url["hasan"]}" | ||||||
|     end |     end | ||||||
|     request = HTTP::Request.new("POST", "/hello/cemal") |     request = HTTP::Request.new("POST", "/hello/cemal") | ||||||
|  | @ -35,7 +35,7 @@ describe "ParamParser" do | ||||||
| 
 | 
 | ||||||
|   it "decodes url params" do |   it "decodes url params" do | ||||||
|     kemal = Kemal::RouteHandler::INSTANCE |     kemal = Kemal::RouteHandler::INSTANCE | ||||||
|     kemal.add_http_route "POST", "/hello/:email/:money/:spanish" do |env| |     kemal.add_route "POST", "/hello/:email/:money/:spanish" do |env| | ||||||
|       email = env.params.url["email"] |       email = env.params.url["email"] | ||||||
|       money = env.params.url["money"] |       money = env.params.url["money"] | ||||||
|       spanish = env.params.url["spanish"] |       spanish = env.params.url["spanish"] | ||||||
|  |  | ||||||
|  | @ -10,13 +10,13 @@ FILTER_METHODS = %w(get post put patch delete options all) | ||||||
| {% for method in HTTP_METHODS %} | {% for method in HTTP_METHODS %} | ||||||
|   def {{method.id}}(path : String, &block : HTTP::Server::Context -> _) |   def {{method.id}}(path : String, &block : HTTP::Server::Context -> _) | ||||||
|     raise Kemal::Exceptions::InvalidPathStartException.new({{method}}, path) unless Kemal::Utils.path_starts_with_slash?(path) |     raise Kemal::Exceptions::InvalidPathStartException.new({{method}}, path) unless Kemal::Utils.path_starts_with_slash?(path) | ||||||
|     Kemal::RouteHandler::INSTANCE.add_http_route({{method}}.upcase, path, &block) |     Kemal::RouteHandler::INSTANCE.add_route({{method}}.upcase, path, &block) | ||||||
|   end |   end | ||||||
| {% end %} | {% end %} | ||||||
| 
 | 
 | ||||||
| def ws(path : String, &block : HTTP::WebSocket, HTTP::Server::Context -> Void) | def ws(path : String, &block : HTTP::WebSocket, HTTP::Server::Context -> Void) | ||||||
|   raise Kemal::Exceptions::InvalidPathStartException.new("ws", path) unless Kemal::Utils.path_starts_with_slash?(path) |   raise Kemal::Exceptions::InvalidPathStartException.new("ws", path) unless Kemal::Utils.path_starts_with_slash?(path) | ||||||
|   Kemal::WebSocketHandler::INSTANCE.add_ws_route path, &block |   Kemal::WebSocketHandler::INSTANCE.add_route path, &block | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| def error(status_code : Int32, &block : HTTP::Server::Context, Exception -> _) | def error(status_code : Int32, &block : HTTP::Server::Context, Exception -> _) | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ module Kemal | ||||||
| 
 | 
 | ||||||
|     # Adds a given route to routing tree. As an exception each `GET` route additionaly defines |     # Adds a given route to routing tree. As an exception each `GET` route additionaly defines | ||||||
|     # a corresponding `HEAD` route. |     # a corresponding `HEAD` route. | ||||||
|     def add_http_route(method : String, path : String, &handler : HTTP::Server::Context -> _) |     def add_route(method : String, path : String, &handler : HTTP::Server::Context -> _) | ||||||
|       add_to_http_radix_tree method, path, Route.new(method, path, &handler) |       add_to_http_radix_tree method, path, Route.new(method, path, &handler) | ||||||
|       add_to_http_radix_tree("HEAD", path, Route.new("HEAD", path) { |ctx| "" }) if method == "GET" |       add_to_http_radix_tree("HEAD", path, Route.new("HEAD", path) { |ctx| "" }) if method == "GET" | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ module Kemal | ||||||
|       @ws_routes.find "/ws#{path}" |       @ws_routes.find "/ws#{path}" | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def add_ws_route(path : String, &handler : HTTP::WebSocket, HTTP::Server::Context -> Void) |     def add_route(path : String, &handler : HTTP::WebSocket, HTTP::Server::Context -> Void) | ||||||
|       add_to_ws_radix_tree path, WebSocket.new(path, &handler) |       add_to_ws_radix_tree path, WebSocket.new(path, &handler) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue