diff options
author | mneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-17 21:30:31 +0000 |
---|---|---|
committer | mneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-17 21:30:31 +0000 |
commit | c88ad2a3871697dbc3edaa0cec8fc2ff8eff8e55 (patch) | |
tree | 27de6144667c559cd4bedfb56f684f0be78d19d9 | |
parent | c531a61f38764e2fd9c42e1e357143ba82b8e9ec (diff) |
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
-rw-r--r-- | lib/xmlrpc/client.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb index 198819ba66..18cf4b0cf3 100644 --- a/lib/xmlrpc/client.rb +++ b/lib/xmlrpc/client.rb @@ -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})). 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 == Synopsis @@ -279,6 +291,10 @@ module XMLRPC def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=nil, timeout=nil) + @http_header_extra = nil + @http_last_response = nil + @cookie = nil + @host = host || "localhost" @path = path || "/RPC2" @proxy_host = proxy_host @@ -349,6 +365,16 @@ module XMLRPC # 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 def timeout=(new_timeout) @@ -468,12 +494,16 @@ module XMLRPC "Connection" => (async ? "close" : "keep-alive") } + header["Cookie"] = @cookie if @cookie + header.update(@http_header_extra) if @http_header_extra + if @auth != nil # add authorization header header["Authorization"] = @auth end resp = nil + @http_last_response = nil if async # use a new HTTP object for each call @@ -494,6 +524,8 @@ module XMLRPC resp = @http.post2(@path, request, header) end + @http_last_response = resp + data = resp.body if resp.code == "401" @@ -519,6 +551,9 @@ module XMLRPC raise "Wrong size. Was #{data.size}, should be #{expected}" end + c = resp["Set-Cookie"] + @cookie = c if c + return data end |