Skip to content

Commit

Permalink
Accept put requests (#70)
Browse files Browse the repository at this point in the history
* Alias do_PUT method to handle PUT requests

* Unit test to ensure PUT requests are handled
  • Loading branch information
bharjr01 authored Jan 26, 2023
1 parent 73c914e commit d42c291
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/webrick/httpservlet/prochandler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def do_GET(request, response)
end

alias do_POST do_GET
alias do_PUT do_GET
# :startdoc:
end

Expand Down
19 changes: 19 additions & 0 deletions test/webrick/test_httpserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d42c291

Please sign in to comment.