Skip to content

Commit d42c291

Browse files
authored
Accept put requests (#70)
* Alias do_PUT method to handle PUT requests * Unit test to ensure PUT requests are handled
1 parent 73c914e commit d42c291

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/webrick/httpservlet/prochandler.rb

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def do_GET(request, response)
4040
end
4141

4242
alias do_POST do_GET
43+
alias do_PUT do_GET
4344
# :startdoc:
4445
end
4546

test/webrick/test_httpserver.rb

+19
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,23 @@ def test_big_chunks
540540
end
541541
}
542542
end
543+
544+
def test_accept_put_requests
545+
TestWEBrick.start_httpserver {|server, addr, port, log|
546+
server.mount_proc("/", lambda {|req, res|
547+
res.status = 200
548+
assert_equal("abcde", req.body)
549+
})
550+
Thread.pass while server.status != :Running
551+
552+
Net::HTTP.start(addr, port) do |http|
553+
req = Net::HTTP::Put.new("/")
554+
req.body = "abcde"
555+
http.request(req){|res|
556+
assert_equal("200", res.code)
557+
}
558+
server.shutdown
559+
end
560+
}
561+
end
543562
end

0 commit comments

Comments
 (0)