Forum: Ruby Does webrick support the http PUT command?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A158d537e62cea11c9415df699136ac7?d=identicon&s=25 acechase (Guest)
on 2005-12-21 01:28
(Received via mailing list)
The subject line pretty much sums it up. I'm having trouble finding
documentation on whether or not webrick supports the http 1.1 PUT
command. Also, if the answer is yes, is it done in manner similar to
Apache (with a server side script that handles the actual file copy)?

Thanks,
Andrew
82e62c756d89bc6fa0a0a2d7f2b1e617?d=identicon&s=25 Ross Bamford (Guest)
on 2005-12-21 05:08
(Received via mailing list)
On Wed, 21 Dec 2005 00:24:20 -0000, acechase <acechase@gmail.com> wrote:

> The subject line pretty much sums it up. I'm having trouble finding
> documentation on whether or not webrick supports the http 1.1 PUT
> command. Also, if the answer is yes, is it done in manner similar to
> Apache (with a server side script that handles the actual file copy)?
>

Apparently so (1), and apparently not (2):

===[server.rb]===
require 'webrick'

s = WEBrick::HTTPServer.new(:Port => 8086)

class PutServlet < WEBrick::HTTPServlet::AbstractServlet
   def do_PUT(req, res)

     # do what you like with the data here...

     res['Content-Type'] = "text/html"
     res.body = "Okay guv'nor, #{req.body} is 'put'..."
   end
end

s.mount("/putter", PutServlet)

trap("INT"){ s.shutdown }
s.start
===[END]===



===[putter.rb]==
require 'net/http'

h = Net::HTTP.new('localhost',8086)
r = h.put('/putter','A bit of the old data')
puts "And our server says: #{r.body}"
===[END]===



===[OUTPUT]===
And our server says: Okay guv'nor, A bit of the old data is 'put'...
===[END]===

So it's handled however you want it to be...
This topic is locked and can not be replied to.