Patches: Browse | Submit New | Admin

[#6321] Make open-uri capable of handling HTTP methods other than GET

Date:
2006-10-25 23:03
Priority:
3
Submitted By:
Leonard Richardson (leonardr)
Assigned To:
Akinori MUSHA (knu)
Category:
Network / Comm / Protocols
State:
Open
Summary:
Make open-uri capable of handling HTTP methods other than GET

Detailed description
When writing clients for REST web services, I want to use the simple interface of open-uri.rb to make HTTP requests
that use POST, PUT, DELETE, etc. Currently only GET requests are supported. A simple change (2 new options) gives support
for all HTTP methods without breaking the old interface. I have patches for both Ruby 1.8 and 1.9. Let me know if you
have questions or need anything else from me.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2011-03-12 02:26
Sender: Joan Marquez

I think this patch is really useful, why was never appplied?
Date: 2006-11-14 18:42
Sender: Ivan Todoroski

Or even worse ;)

# get all classes in Net::HTTP inherited from HTTPRequest
method_classes = Net::HTTP.constants.map {|m|
  Net::HTTP.const_get(m)
}.select {|c|
  c.is_a? Class and c.ancestors.include? Net::HTTPRequest
}

# map them to their shortened lower case names
Methods = Hash[*method_classes.inject([]) {|a,m|
  a.push m.to_s.split("::").last.downcase.to_sym, m
}]
Date: 2006-11-14 17:28
Sender: Ivan Todoroski

This is a nice patch, very useful for me, thanks. Hope it's accepted
in Ruby soon.

As for you comment about Methods initialization, there are ways
to shorten it, but I'm not sure if the cure is worse than the
disease :)

methods = %w(copy delete get head lock mkcol options post propfind
proppatch put trace unlock)

Methods = Hash[*methods.inject([]) {|a,m| a.push m.to_sym,
eval("Net::HTTP::#{m.capitalize}")}]

Attached Files:

Name Description Download
diff-1.9 Diff against Ruby 1.9 Download
diff-1.8 Diff against Ruby 1.8 Download

Changes:

Field Old Value Date By
assigned_tonone2007-06-13 06:30zenspider
category_idMisc / Other Standard Library2007-05-30 04:12zenspider
category_idDB / File Formats2007-05-30 03:50zenspider
artifact_group_idNone2007-05-30 03:41zenspider
File Added890: diff-1.82006-10-25 23:04leonardr
File Added889: diff-1.92006-10-25 23:03leonardr