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 | ||||
|       @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 | ||||
| 
 | ||||
|     def redirect(url, status_code = 302) | ||||
|  |  | |||
|  | @ -75,8 +75,20 @@ module Kemal | |||
|       end | ||||
|     end | ||||
| 
 | ||||
|     def parse_part(part) | ||||
|       HTTP::Params.parse(part.to_s || "") | ||||
|     def parse_part(part : IO?) | ||||
|       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 | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ | |||
| class HTTP::Request | ||||
|   property override_method | ||||
|   property url_params : Hash(String, String)? | ||||
|   getter param_parser : Kemal::ParamParser? | ||||
| 
 | ||||
|   def override_method | ||||
|     @override_method ||= check_for_method_override! | ||||
|  | @ -18,7 +19,8 @@ class HTTP::Request | |||
|   private def check_for_method_override! | ||||
|     @override_method = @method | ||||
|     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"]) | ||||
|         @override_method = params["_method"] | ||||
|       end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue