mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
class XMLRPC::Client:
* added attr_accessor :http_header_extra that can be used to add extra lines in HTTP header. * added attr_accessor :cookie - shortcut for setting/getting cookies * added attr_accressor :http_last_response that holds the last HTTP response. Usefull when needed to extract information from HTTP header (e.g. cookies, keep alive...) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c531a61f38
commit
c88ad2a387
1 changed files with 35 additions and 0 deletions
|
@ -208,6 +208,18 @@ call on the remote-side and of course the parameters for the remote procedure.
|
||||||
Should be an instance of a class from module (({XMLRPC::XMLParser})).
|
Should be an instance of a class from module (({XMLRPC::XMLParser})).
|
||||||
If this method is not called, then (({XMLRPC::Config::DEFAULT_PARSER})) is used.
|
If this method is not called, then (({XMLRPC::Config::DEFAULT_PARSER})) is used.
|
||||||
|
|
||||||
|
--- XMLRPC::Client#cookie
|
||||||
|
--- XMLRPC::Client#cookie= (cookieString)
|
||||||
|
Get and set the HTTP Cookie header.
|
||||||
|
|
||||||
|
--- XMLRPC::Client#http_header_extra= (additionalHeaders)
|
||||||
|
Set extra HTTP headers that are included in the request.
|
||||||
|
|
||||||
|
--- XMLRPC::Client#http_header_extra
|
||||||
|
Access the via ((<XMLRPC::Client#http_header_extra=>)) assigned header.
|
||||||
|
|
||||||
|
--- XMLRPC::Client#http_last_response
|
||||||
|
Returns the (({Net::HTTPResponse})) object of the last RPC.
|
||||||
|
|
||||||
= XMLRPC::Client::Proxy
|
= XMLRPC::Client::Proxy
|
||||||
== Synopsis
|
== Synopsis
|
||||||
|
@ -279,6 +291,10 @@ module XMLRPC
|
||||||
def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
|
def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
|
||||||
user=nil, password=nil, use_ssl=nil, timeout=nil)
|
user=nil, password=nil, use_ssl=nil, timeout=nil)
|
||||||
|
|
||||||
|
@http_header_extra = nil
|
||||||
|
@http_last_response = nil
|
||||||
|
@cookie = nil
|
||||||
|
|
||||||
@host = host || "localhost"
|
@host = host || "localhost"
|
||||||
@path = path || "/RPC2"
|
@path = path || "/RPC2"
|
||||||
@proxy_host = proxy_host
|
@proxy_host = proxy_host
|
||||||
|
@ -349,6 +365,16 @@ module XMLRPC
|
||||||
|
|
||||||
# Attribute Accessors -------------------------------------------------------------------
|
# Attribute Accessors -------------------------------------------------------------------
|
||||||
|
|
||||||
|
# add additional HTTP headers to the request
|
||||||
|
attr_accessor :http_header_extra
|
||||||
|
|
||||||
|
# makes last HTTP response accessible
|
||||||
|
attr_reader :http_last_response
|
||||||
|
|
||||||
|
# Cookie support
|
||||||
|
attr_accessor :cookie
|
||||||
|
|
||||||
|
|
||||||
attr_reader :timeout, :user, :password
|
attr_reader :timeout, :user, :password
|
||||||
|
|
||||||
def timeout=(new_timeout)
|
def timeout=(new_timeout)
|
||||||
|
@ -468,12 +494,16 @@ module XMLRPC
|
||||||
"Connection" => (async ? "close" : "keep-alive")
|
"Connection" => (async ? "close" : "keep-alive")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header["Cookie"] = @cookie if @cookie
|
||||||
|
header.update(@http_header_extra) if @http_header_extra
|
||||||
|
|
||||||
if @auth != nil
|
if @auth != nil
|
||||||
# add authorization header
|
# add authorization header
|
||||||
header["Authorization"] = @auth
|
header["Authorization"] = @auth
|
||||||
end
|
end
|
||||||
|
|
||||||
resp = nil
|
resp = nil
|
||||||
|
@http_last_response = nil
|
||||||
|
|
||||||
if async
|
if async
|
||||||
# use a new HTTP object for each call
|
# use a new HTTP object for each call
|
||||||
|
@ -494,6 +524,8 @@ module XMLRPC
|
||||||
resp = @http.post2(@path, request, header)
|
resp = @http.post2(@path, request, header)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@http_last_response = resp
|
||||||
|
|
||||||
data = resp.body
|
data = resp.body
|
||||||
|
|
||||||
if resp.code == "401"
|
if resp.code == "401"
|
||||||
|
@ -519,6 +551,9 @@ module XMLRPC
|
||||||
raise "Wrong size. Was #{data.size}, should be #{expected}"
|
raise "Wrong size. Was #{data.size}, should be #{expected}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
c = resp["Set-Cookie"]
|
||||||
|
@cookie = c if c
|
||||||
|
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue