Skip to content

Commit

Permalink
class XMLRPC::Client:
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mneumann committed Nov 17, 2003
1 parent c531a61 commit c88ad2a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/xmlrpc/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@
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
Expand Down Expand Up @@ -279,6 +291,10 @@ class Client
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
Expand Down Expand Up @@ -349,6 +365,16 @@ def self.new3(hash={})

# 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)
Expand Down Expand Up @@ -468,12 +494,16 @@ def do_rpc(request, async=false)
"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
Expand All @@ -494,6 +524,8 @@ def do_rpc(request, async=false)
resp = @http.post2(@path, request, header)
end

@http_last_response = resp

data = resp.body

if resp.code == "401"
Expand All @@ -519,6 +551,9 @@ def do_rpc(request, async=false)
raise "Wrong size. Was #{data.size}, should be #{expected}"
end

c = resp["Set-Cookie"]
@cookie = c if c

return data
end

Expand Down

0 comments on commit c88ad2a

Please sign in to comment.