From d42c291df4f2f5c31b9fdec1e503fac9e5f65b22 Mon Sep 17 00:00:00 2001 From: Ravi <33230211+bharjr01@users.noreply.github.com> Date: Thu, 26 Jan 2023 23:03:22 +0000 Subject: [PATCH] Accept put requests (#70) * Alias do_PUT method to handle PUT requests * Unit test to ensure PUT requests are handled --- lib/webrick/httpservlet/prochandler.rb | 1 + test/webrick/test_httpserver.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/webrick/httpservlet/prochandler.rb b/lib/webrick/httpservlet/prochandler.rb index dca5d2d..92e4f80 100644 --- a/lib/webrick/httpservlet/prochandler.rb +++ b/lib/webrick/httpservlet/prochandler.rb @@ -40,6 +40,7 @@ def do_GET(request, response) end alias do_POST do_GET + alias do_PUT do_GET # :startdoc: end diff --git a/test/webrick/test_httpserver.rb b/test/webrick/test_httpserver.rb index 4133be8..56ac677 100644 --- a/test/webrick/test_httpserver.rb +++ b/test/webrick/test_httpserver.rb @@ -540,4 +540,23 @@ def test_big_chunks end } end + + def test_accept_put_requests + TestWEBrick.start_httpserver {|server, addr, port, log| + server.mount_proc("/", lambda {|req, res| + res.status = 200 + assert_equal("abcde", req.body) + }) + Thread.pass while server.status != :Running + + Net::HTTP.start(addr, port) do |http| + req = Net::HTTP::Put.new("/") + req.body = "abcde" + http.request(req){|res| + assert_equal("200", res.code) + } + server.shutdown + end + } + end end