Does webrick support the http PUT command?


#1

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


#2

On Wed, 21 Dec 2005 00:24:20 -0000, acechase removed_email_address@domain.invalid 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…