phprpc 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/phprpc/client.rb +19 -20
- metadata +2 -2
data/lib/phprpc/client.rb
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
#
|
26
26
|
# Copyright (C) 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
|
27
27
|
# Version: 3.0
|
28
|
-
# LastModified:
|
28
|
+
# LastModified: Oct 6, 2008
|
29
29
|
# This library is free. You can redistribute it and/or modify it.
|
30
30
|
|
31
31
|
require "net/http"
|
@@ -50,6 +50,7 @@ module PHPRPC
|
|
50
50
|
Net::HTTP.version_1_2
|
51
51
|
@httpclient = nil
|
52
52
|
@http = Net::HTTP
|
53
|
+
@uri = nil
|
53
54
|
if url then
|
54
55
|
@uri = URI.parse(url)
|
55
56
|
end
|
@@ -62,35 +63,32 @@ module PHPRPC
|
|
62
63
|
@cookie = ''
|
63
64
|
@cookies = {}
|
64
65
|
@charset = 'utf-8'
|
65
|
-
@username = nil
|
66
|
-
@password = nil
|
67
66
|
@server_version = nil
|
68
67
|
end
|
69
68
|
|
70
|
-
def use_service(url, username = nil, password = nil)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
def use_service(url = nil, username = nil, password = nil)
|
70
|
+
if url then
|
71
|
+
close
|
72
|
+
@uri = URI.parse(url)
|
73
|
+
@key = nil
|
74
|
+
@keylength = 128
|
75
|
+
@encryptmode = 0
|
76
|
+
@cookie = ''
|
77
|
+
@cookies = {}
|
78
|
+
@charset = 'utf-8'
|
79
|
+
@uri.user = username unless username.nil?
|
80
|
+
@uri.password = password unless password.nil?
|
81
|
+
end
|
82
82
|
Proxy.new(self)
|
83
83
|
end
|
84
84
|
|
85
85
|
def set_proxy(p_addr, p_port = nil, p_user = nil, p_pass = nil)
|
86
86
|
close
|
87
|
-
@httpclient = nil
|
88
87
|
@http = Net::HTTP::Proxy(p_addr, p_port, p_user, p_pass)
|
89
88
|
end
|
90
89
|
|
91
90
|
def proxy=(proxy)
|
92
91
|
close
|
93
|
-
@httpclient = nil
|
94
92
|
@http = case proxy
|
95
93
|
when Net::HTTP then
|
96
94
|
proxy
|
@@ -124,7 +122,7 @@ module PHPRPC
|
|
124
122
|
request = "phprpc_func=#{methodname}"
|
125
123
|
request << '&phprpc_args=' << [_encrypt(PHP::Formator.serialize(args), 1)].pack('m').delete!("\n").gsub('+', '%2B') if args.size > 0
|
126
124
|
request << "&phprpc_encrypt=#{@encryptmode}"
|
127
|
-
request << '&phprpc_ref=false'
|
125
|
+
request << '&phprpc_ref=false' unless byref
|
128
126
|
result = _post(request)
|
129
127
|
if result.key?('phprpc_errstr') and result.key?('phprpc_errno') then
|
130
128
|
@warning = PHPRPC::Error.new(result['phprpc_errstr'].unpack('m')[0])
|
@@ -161,6 +159,7 @@ module PHPRPC
|
|
161
159
|
|
162
160
|
def close
|
163
161
|
@httpclient.finish if (not @httpclient.nil?) and @httpclient.started?
|
162
|
+
@httpclient = nil
|
164
163
|
end
|
165
164
|
|
166
165
|
private
|
@@ -178,14 +177,14 @@ module PHPRPC
|
|
178
177
|
@httpclient.start
|
179
178
|
end
|
180
179
|
headers = {
|
181
|
-
'Cookie' => @cookie,
|
182
180
|
'User-Agent' => "PHPRPC 3.0 Client for Ruby (#{RUBY_VERSION})",
|
183
181
|
'Cache-Control' => 'no-cache',
|
184
182
|
'Content-Type' => "application/x-www-form-urlencoded; charset=#{@charset}",
|
185
183
|
'Content-Length' => req.size.to_s,
|
186
184
|
'Connection' => 'keep-alive',
|
187
185
|
}
|
188
|
-
headers
|
186
|
+
headers['Cookie'] = @cookie unless @cookie.empty?
|
187
|
+
headers['Authorization'] = 'Basic ' << ["#{@uri.user}:#{@uri.password}"].pack('m').delete!("\n") unless @uri.user.nil? or @uri.password.nil?
|
189
188
|
resp, data = @httpclient.request_post(@uri.path, req, headers)
|
190
189
|
if resp.code == '200' then
|
191
190
|
if resp.key?('x-powered-by') then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phprpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MA Bingyao ( andot )
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-06 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|