1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/net/http.rb: adding support to rfc5789 patch verb.

Added a Net::HTTP::Patch class which expects a message body
  and response body. It recycles the post method into a patch one,
  that will send the encoded representation to the server.
  Summarizing, a new class has been created, the post method
  extracted into send_entity, including a new argument,
  which defines which class to use (Post or Patch) and
  finally a patch method was created. [ruby-core:30426]
  Patched by Guilherme Silveira
  <guilherme.silveira AT caelum.com.br>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-06-01 12:30:52 +00:00
parent b64083376e
commit ab70e53ac3
4 changed files with 70 additions and 10 deletions

View file

@ -1,3 +1,16 @@
Tue Jun 1 21:29:39 2010 NARUSE, Yui <naruse@ruby-lang.org>
* lib/net/http.rb: adding support to rfc5789 patch verb.
Added a Net::HTTP::Patch class which expects a message body
and response body. It recycles the post method into a patch one,
that will send the encoded representation to the server.
Summarizing, a new class has been created, the post method
extracted into send_entity, including a new argument,
which defines which class to use (Post or Patch) and
finally a patch method was created. [ruby-core:30426]
Patched by Guilherme Silveira
<guilherme.silveira AT caelum.com.br>
Tue Jun 1 03:46:08 2010 NARUSE, Yui <naruse@ruby-lang.org>
* ext/readline/extconf.rb: reject GPLv3 readline. [ruby-dev:39172]

View file

@ -966,16 +966,13 @@ module Net #:nodoc:
# "application/x-www-form-urlencoded" by default.
#
def post(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
res = nil
request(Post.new(path, initheader), data) {|r|
r.read_body dest, &block
res = r
}
unless @newimpl
res.value
return res, res.body
end
res
send_entity(path, data, initheader, dest, Post, &block)
end
# Sends a PATCH request to the +path+ and gets a response,
# as an HTTPResponse object.
def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
send_entity(path, data, initheader, dest, Patch, &block)
end
def put(path, data, initheader = nil) #:nodoc:
@ -1176,6 +1173,21 @@ module Net #:nodoc:
private
# Executes a request which uses a representation
# and returns its body.
def send_entity(path, data, initheader, dest, type, &block)
res = nil
request(type.new(path, initheader), data) {|r|
r.read_body dest, &block
res = r
}
unless @newimpl
res.value
return res, res.body
end
res
end
def transport_request(req)
begin_transport req
req.exec @socket, @curr_http_version, edit_path(req.path)
@ -1831,6 +1843,16 @@ module Net #:nodoc:
RESPONSE_HAS_BODY = true
end
#
# PATCH method --- RFC5789
#
class Patch < HTTPRequest
METHOD = 'PATCH'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
#
# WebDAV methods --- RFC2518
#

View file

@ -169,6 +169,25 @@ module TestNetHTTP_version_1_1_methods
assert_equal ["a=x1", "a=x2", "b=y"], res.body.split(/[;&]/).sort
end
def test_patch
start {|http|
_test_patch__base http
}
end
def _test_patch__base(http)
uheader = {}
uheader['Accept'] = 'application/octet-stream'
data = 'patch data'
res, body = http.patch('/', data)
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, body
assert_kind_of String, res.body
assert_equal data, body
assert_equal data, res.body
assert_equal data, res.entity
end
end

View file

@ -92,6 +92,12 @@ module TestNetHTTPUtils
res.body = req.body
res.chunked = @chunked
end
def do_PATCH(req, res)
res['Content-Type'] = req['Content-Type']
res.body = req.body
res.chunked = @chunked
end
end
class NullWriter