mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Added request body parsing
This commit is contained in:
		
							parent
							
								
									8a0f9dffff
								
							
						
					
					
						commit
						efe75196f7
					
				
					 2 changed files with 19 additions and 0 deletions
				
			
		|  | @ -40,4 +40,17 @@ describe "Kemal::Handler" do | |||
|     response = kemal.call(request) | ||||
|     response.headers["Content-Type"].should eq("application/json") | ||||
|   end | ||||
| 
 | ||||
|   it "parses POST body" do | ||||
|     kemal = Kemal::Handler.new | ||||
|     kemal.add_route "POST", "/" do |env| | ||||
|       name = env.request.params["name"] | ||||
|       age = env.request.params["age"] | ||||
|       hasan = env.request.params["hasan"] | ||||
|       "Hello #{name} #{hasan} #{age}" | ||||
|     end | ||||
|     request = HTTP::Request.new("POST", "/?hasan=cemal", body: "name=kemal&age=99") | ||||
|     response = kemal.call(request) | ||||
|     response.body.should eq("Hello kemal cemal 99") | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -29,6 +29,12 @@ class Kemal::Handler < HTTP::Handler | |||
|           params[key] ||= value | ||||
|         end | ||||
| 
 | ||||
|         if body = request.body | ||||
|           HTTP::Params.parse(request.body.not_nil!) do |key, value| | ||||
|             params[key] ||= value | ||||
|           end | ||||
|         end | ||||
| 
 | ||||
|         kemal_request = Request.new(request, params) | ||||
|         context = Context.new(kemal_request) | ||||
|         begin | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue