mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Treat HTTP::Request body as IO. Fixes #257
This commit is contained in:
		
							parent
							
								
									f11b0e07e4
								
							
						
					
					
						commit
						3b9a3f84ab
					
				
					 3 changed files with 22 additions and 4 deletions
				
			
		|  | @ -9,7 +9,11 @@ class HTTP::Server | ||||||
| 
 | 
 | ||||||
|     def params |     def params | ||||||
|       @request.url_params ||= route_lookup.params |       @request.url_params ||= route_lookup.params | ||||||
|       @params ||= Kemal::ParamParser.new(@request) |       @params ||= if @request.param_parser | ||||||
|  |                     @request.param_parser.not_nil! | ||||||
|  |                   else | ||||||
|  |                     Kemal::ParamParser.new(@request) | ||||||
|  |                   end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def redirect(url, status_code = 302) |     def redirect(url, status_code = 302) | ||||||
|  |  | ||||||
|  | @ -75,8 +75,20 @@ module Kemal | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def parse_part(part) |     def parse_part(part : IO?) | ||||||
|       HTTP::Params.parse(part.to_s || "") |       if part | ||||||
|  |         HTTP::Params.parse(part.gets_to_end) | ||||||
|  |       else | ||||||
|  |         HTTP::Params.parse("") | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     def parse_part(part : String?) | ||||||
|  |       if part | ||||||
|  |         HTTP::Params.parse(part.to_s) | ||||||
|  |       else | ||||||
|  |         HTTP::Params.parse("") | ||||||
|  |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| class HTTP::Request | class HTTP::Request | ||||||
|   property override_method |   property override_method | ||||||
|   property url_params : Hash(String, String)? |   property url_params : Hash(String, String)? | ||||||
|  |   getter param_parser : Kemal::ParamParser? | ||||||
| 
 | 
 | ||||||
|   def override_method |   def override_method | ||||||
|     @override_method ||= check_for_method_override! |     @override_method ||= check_for_method_override! | ||||||
|  | @ -18,7 +19,8 @@ class HTTP::Request | ||||||
|   private def check_for_method_override! |   private def check_for_method_override! | ||||||
|     @override_method = @method |     @override_method = @method | ||||||
|     if @method == "POST" |     if @method == "POST" | ||||||
|       params = Kemal::ParamParser.new(self).body |       @param_parser = Kemal::ParamParser.new(self) | ||||||
|  |       params = @param_parser.not_nil!.body | ||||||
|       if params.has_key?("_method") && HTTP::Request.override_method_valid?(params["_method"]) |       if params.has_key?("_method") && HTTP::Request.override_method_valid?(params["_method"]) | ||||||
|         @override_method = params["_method"] |         @override_method = params["_method"] | ||||||
|       end |       end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue