httpclient 2.6.0.1 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -290,8 +290,8 @@ EOF
290
290
  def test_load_cookies_escaped
291
291
  uri = urify('http://example.org/')
292
292
  f = Tempfile.new('test_cookie')
293
- File.open(f.path, 'w') do |f|
294
- f.write <<EOF
293
+ File.open(f.path, 'w') do |out|
294
+ out.write <<EOF
295
295
  http://example.org/ key1 "value" 0 .example.org / 13 0
296
296
  http://example.org/ key2 "" 0 .example.org / 13 0
297
297
  http://example.org/ key3 0 .example.org / 13 0
@@ -568,7 +568,7 @@ EOS
568
568
  end
569
569
 
570
570
  def test_get_content_with_base_url
571
- @client = HTTPClient.new(:base_url => serverurl[0..-1])
571
+ @client = HTTPClient.new(:base_url => serverurl)
572
572
  assert_equal('hello', @client.get_content('/hello'))
573
573
  assert_equal('hello', @client.get_content('/redirect1'))
574
574
  assert_equal('hello', @client.get_content('/redirect2'))
@@ -591,8 +591,10 @@ EOS
591
591
 
592
592
  GZIP_CONTENT = "\x1f\x8b\x08\x00\x1a\x96\xe0\x4c\x00\x03\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36\x05\x00\x00\x00"
593
593
  DEFLATE_CONTENT = "\x78\x9c\xcb\x48\xcd\xc9\xc9\x07\x00\x06\x2c\x02\x15"
594
- GZIP_CONTENT.force_encoding('BINARY') if GZIP_CONTENT.respond_to?(:force_encoding)
595
- DEFLATE_CONTENT.force_encoding('BINARY') if DEFLATE_CONTENT.respond_to?(:force_encoding)
594
+ DEFLATE_NOHEADER_CONTENT = "x\x9C\xCBH\xCD\xC9\xC9\a\x00\x06,\x02\x15"
595
+ [GZIP_CONTENT, DEFLATE_CONTENT, DEFLATE_NOHEADER_CONTENT].each do |content|
596
+ content.force_encoding('BINARY') if content.respond_to?(:force_encoding)
597
+ end
596
598
  def test_get_gzipped_content
597
599
  @client.transparent_gzip_decompression = false
598
600
  content = @client.get_content(serverurl + 'compressed?enc=gzip')
@@ -601,6 +603,7 @@ EOS
601
603
  @client.transparent_gzip_decompression = true
602
604
  assert_equal('hello', @client.get_content(serverurl + 'compressed?enc=gzip'))
603
605
  assert_equal('hello', @client.get_content(serverurl + 'compressed?enc=deflate'))
606
+ assert_equal('hello', @client.get_content(serverurl + 'compressed?enc=deflate_noheader'))
604
607
  @client.transparent_gzip_decompression = false
605
608
  end
606
609
 
@@ -676,14 +679,14 @@ EOS
676
679
  end
677
680
 
678
681
  def test_get_with_base_url
679
- @client = HTTPClient.new(:base_url => serverurl[0..-1])
682
+ @client = HTTPClient.new(:base_url => serverurl)
680
683
  assert_equal("get", @client.get('/servlet').content)
681
684
  param = {'1'=>'2', '3'=>'4'}
682
685
  res = @client.get('/servlet', param)
683
686
  assert_equal(param, params(res.header["x-query"][0]))
684
687
  assert_nil(res.contenttype)
685
688
  #
686
- @client.base_url = serverurl[0..-1] + '/servlet'
689
+ @client.base_url = serverurl[0...-1] + '/servlet'
687
690
  url = '?5=6&7=8'
688
691
  res = @client.get(url, param)
689
692
  assert_equal(param.merge("5"=>"6", "7"=>"8"), params(res.header["x-query"][0]))
@@ -691,7 +694,7 @@ EOS
691
694
  end
692
695
 
693
696
  def test_get_with_default_header
694
- @client = HTTPClient.new(:base_url => serverurl[0..-1], :default_header => {'x-header' => 'custom'})
697
+ @client = HTTPClient.new(:base_url => serverurl, :default_header => {'x-header' => 'custom'})
695
698
  assert_equal('custom', @client.get('/servlet').headers['X-Header'])
696
699
  @client.default_header = {'x-header' => 'custom2'}
697
700
  assert_equal('custom2', @client.get('/servlet').headers['X-Header'])
@@ -767,8 +770,8 @@ EOS
767
770
 
768
771
  def test_get_with_block_arity_2
769
772
  called = false
770
- res = @client.get(serverurl + 'servlet') { |res, str|
771
- assert_equal(200, res.status)
773
+ res = @client.get(serverurl + 'servlet') { |blk_res, str|
774
+ assert_equal(200, blk_res.status)
772
775
  assert_equal('get', str)
773
776
  called = true
774
777
  }
@@ -780,7 +783,7 @@ EOS
780
783
  def test_get_with_block_string_recycle
781
784
  @client.read_block_size = 2
782
785
  body = []
783
- res = @client.get(serverurl + 'servlet') { |str|
786
+ _res = @client.get(serverurl + 'servlet') { |str|
784
787
  body << str
785
788
  }
786
789
  assert_equal(2, body.size)
@@ -797,7 +800,7 @@ EOS
797
800
  url = "http://localhost:#{server.addr[1]}/"
798
801
  body = []
799
802
  begin
800
- res = @client.get(url + 'chunked') { |str|
803
+ _res = @client.get(url + 'chunked') { |str|
801
804
  body << str
802
805
  }
803
806
  ensure
@@ -952,7 +955,7 @@ EOS
952
955
  1
953
956
  end
954
957
  @client.debug_dev = str = StringIO.new
955
- res = @client.post(serverurl + 'servlet', { :file => myio })
958
+ _res = @client.post(serverurl + 'servlet', { :file => myio })
956
959
  assert_match(/\r\n4\r\n/, str.string, 'should send "4" not "45"')
957
960
  end
958
961
 
@@ -969,7 +972,7 @@ EOS
969
972
  end
970
973
  end
971
974
  @client.debug_dev = str = StringIO.new
972
- res = @client.post(serverurl + 'servlet', { :file1 => myio1, :file2 => myio2 })
975
+ _res = @client.post(serverurl + 'servlet', { :file1 => myio1, :file2 => myio2 })
973
976
  assert_match(/\r\n45\r\n/, str.string)
974
977
  end
975
978
 
@@ -1032,6 +1035,36 @@ EOS
1032
1035
  end
1033
1036
  end
1034
1037
 
1038
+ def test_patch
1039
+ assert_equal("patch", @client.patch(serverurl + 'servlet', '').content)
1040
+ param = {'1'=>'2', '3'=>'4'}
1041
+ @client.debug_dev = str = ''
1042
+ res = @client.patch(serverurl + 'servlet', param)
1043
+ assert_equal(param, params(res.header["x-query"][0]))
1044
+ assert_equal('Content-Type: application/x-www-form-urlencoded', str.split(/\r?\n/)[5])
1045
+ end
1046
+
1047
+ def test_patch_with_query_and_body
1048
+ res = @client.patch(serverurl + 'servlet', :query => {:query => 'query'}, :body => {:body => 'body'})
1049
+ assert_equal("patch", res.content)
1050
+ assert_equal("body=body", res.headers["X-Query"])
1051
+ assert_equal("query=query", res.headers["X-Request-Query"])
1052
+ end
1053
+
1054
+ def test_patch_bytesize
1055
+ res = @client.patch(serverurl + 'servlet', 'txt' => 'あいうえお')
1056
+ assert_equal('txt=%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A', res.header["x-query"][0])
1057
+ assert_equal('15', res.header["x-size"][0])
1058
+ end
1059
+
1060
+ def test_patch_async
1061
+ param = {'1'=>'2', '3'=>'4'}
1062
+ conn = @client.patch_async(serverurl + 'servlet', param)
1063
+ Thread.pass while !conn.finished?
1064
+ res = conn.pop
1065
+ assert_equal(param, params(res.header["x-query"][0]))
1066
+ end
1067
+
1035
1068
  def test_put
1036
1069
  assert_equal("put", @client.put(serverurl + 'servlet', '').content)
1037
1070
  param = {'1'=>'2', '3'=>'4'}
@@ -1240,7 +1273,7 @@ EOS
1240
1273
 
1241
1274
  def test_http_custom_date_header
1242
1275
  @client.debug_dev = (str = "")
1243
- res = @client.get(serverurl + 'hello', :header => {'Date' => 'foo'})
1276
+ _res = @client.get(serverurl + 'hello', :header => {'Date' => 'foo'})
1244
1277
  lines = str.split(/(?:\r?\n)+/)
1245
1278
  assert_equal('Date: foo', lines[4])
1246
1279
  end
@@ -1840,14 +1873,6 @@ private
1840
1873
  @server_thread = start_server_thread(@server)
1841
1874
  end
1842
1875
 
1843
- def escape_noproxy
1844
- backup = HTTPClient::NO_PROXY_HOSTS.dup
1845
- HTTPClient::NO_PROXY_HOSTS.clear
1846
- yield
1847
- ensure
1848
- HTTPClient::NO_PROXY_HOSTS.replace(backup)
1849
- end
1850
-
1851
1876
  def add_query_string(req)
1852
1877
  if req.query_string
1853
1878
  '?' + req.query_string
@@ -1922,6 +1947,9 @@ private
1922
1947
  elsif req.query['enc'] == 'deflate'
1923
1948
  res['content-encoding'] = 'deflate'
1924
1949
  res.body = DEFLATE_CONTENT
1950
+ elsif req.query['enc'] == 'deflate_noheader'
1951
+ res['content-encoding'] = 'deflate'
1952
+ res.body = DEFLATE_NOHEADER_CONTENT
1925
1953
  end
1926
1954
  end
1927
1955
 
@@ -1966,6 +1994,14 @@ private
1966
1994
  res["x-request-query"] = req.query_string
1967
1995
  end
1968
1996
 
1997
+ def do_PATCH(req, res)
1998
+ res["x-query"] = body_response(req)
1999
+ param = WEBrick::HTTPUtils.parse_query(req.body) || {}
2000
+ res["x-size"] = (param['txt'] || '').size
2001
+ res.body = param['txt'] || 'patch'
2002
+ res["x-request-query"] = req.query_string
2003
+ end
2004
+
1969
2005
  def do_PUT(req, res)
1970
2006
  res["x-query"] = body_response(req)
1971
2007
  param = WEBrick::HTTPUtils.parse_query(req.body) || {}
@@ -4,6 +4,7 @@ require 'webrick/https'
4
4
 
5
5
  class TestSSL < Test::Unit::TestCase
6
6
  include Helper
7
+
7
8
  DIR = File.dirname(File.expand_path(__FILE__))
8
9
 
9
10
  def setup
@@ -25,6 +26,20 @@ class TestSSL < Test::Unit::TestCase
25
26
  File.expand_path(filename, DIR)
26
27
  end
27
28
 
29
+ def test_proxy_ssl
30
+ setup_proxyserver
31
+ escape_noproxy do
32
+ @client.proxy = proxyurl
33
+ @client.ssl_config.set_client_cert_file(path('client.cert'), path('client.key'))
34
+ @client.ssl_config.add_trust_ca(path('ca.cert'))
35
+ @client.ssl_config.add_trust_ca(path('subca.cert'))
36
+ @client.debug_dev = str = ""
37
+ assert_equal(200, @client.get(@url).status)
38
+ assert(/accept/ =~ @proxyio.string, 'proxy is not used')
39
+ assert(/Host: localhost:#{serverport}/ =~ str)
40
+ end
41
+ end
42
+
28
43
  def test_options
29
44
  cfg = @client.ssl_config
30
45
  assert_nil(cfg.client_cert)
@@ -41,6 +56,8 @@ class TestSSL < Test::Unit::TestCase
41
56
  assert_instance_of(OpenSSL::X509::Store, cfg.cert_store)
42
57
  end
43
58
 
59
+ unless defined?(HTTPClient::JRubySSLSocket)
60
+ # JRubySSLSocket does not support sync mode.
44
61
  def test_sync
45
62
  cfg = @client.ssl_config
46
63
  cfg.set_client_cert_file(path('client.cert'), path('client.key'))
@@ -52,12 +69,13 @@ class TestSSL < Test::Unit::TestCase
52
69
  @client.reset_all
53
70
  assert_equal("hello", @client.get_content(@url))
54
71
  end
72
+ end
55
73
 
56
74
  def test_debug_dev
57
75
  str = @client.debug_dev = ''
58
76
  cfg = @client.ssl_config
59
- cfg.client_cert = cert("client.cert")
60
- cfg.client_key = key("client.key")
77
+ cfg.client_cert = path("client.cert")
78
+ cfg.client_key = path("client.key")
61
79
  cfg.add_trust_ca(path('ca.cert'))
62
80
  cfg.add_trust_ca(path('subca.cert'))
63
81
  assert_equal("hello", @client.get_content(@url))
@@ -72,18 +90,18 @@ class TestSSL < Test::Unit::TestCase
72
90
  @client.get(@url)
73
91
  assert(false)
74
92
  rescue OpenSSL::SSL::SSLError => ssle
75
- assert_match(/certificate verify failed/, ssle.message)
93
+ assert_match(/(certificate verify failed|unable to find valid certification path to requested target)/, ssle.message)
76
94
  assert(@verify_callback_called)
77
95
  end
78
96
  #
79
- cfg.client_cert = cert("client.cert")
80
- cfg.client_key = key("client.key")
97
+ cfg.client_cert = path("client.cert")
98
+ cfg.client_key = path("client.key")
81
99
  @verify_callback_called = false
82
100
  begin
83
101
  @client.get(@url)
84
102
  assert(false)
85
103
  rescue OpenSSL::SSL::SSLError => ssle
86
- assert_match(/certificate verify failed/, ssle.message)
104
+ assert_match(/(certificate verify failed|unable to find valid certification path to requested target)/, ssle.message)
87
105
  assert(@verify_callback_called)
88
106
  end
89
107
  #
@@ -93,7 +111,7 @@ class TestSSL < Test::Unit::TestCase
93
111
  @client.get(@url)
94
112
  assert(false)
95
113
  rescue OpenSSL::SSL::SSLError => ssle
96
- assert_match(/certificate verify failed/, ssle.message)
114
+ assert_match(/(certificate verify failed|unable to find valid certification path to requested target)/, ssle.message)
97
115
  assert(@verify_callback_called)
98
116
  end
99
117
  #
@@ -102,16 +120,16 @@ class TestSSL < Test::Unit::TestCase
102
120
  assert_equal("hello", @client.get_content(@url))
103
121
  assert(@verify_callback_called)
104
122
  #
105
- unless ENV['TRAVIS']
106
- # On travis environment, verify_depth seems to not work properly.
107
- # Ubuntu 10.04 + OpenSSL 0.9.8k issue?
123
+ if false
124
+ # JRubySSLSocket does not support depth.
125
+ # Also on travis environment, verify_depth seems to not work properly.
108
126
  cfg.verify_depth = 1 # 2 required: root-sub
109
127
  @verify_callback_called = false
110
128
  begin
111
129
  @client.get(@url)
112
130
  assert(false, "verify_depth is not supported? #{OpenSSL::OPENSSL_VERSION}")
113
131
  rescue OpenSSL::SSL::SSLError => ssle
114
- assert_match(/certificate verify failed/, ssle.message)
132
+ assert_match(/(certificate verify failed|unable to find valid certification path to requested target)/, ssle.message)
115
133
  assert(@verify_callback_called)
116
134
  end
117
135
  #
@@ -128,13 +146,39 @@ end
128
146
  @client.get_content(@url)
129
147
  assert(false)
130
148
  rescue OpenSSL::SSL::SSLError => ssle
131
- assert_match(/certificate verify failed/, ssle.message)
149
+ assert_match(/(certificate verify failed|unable to find valid certification path to requested target)/, ssle.message)
132
150
  end
133
151
  #
134
152
  cfg.verify_mode = nil
135
153
  assert_equal("hello", @client.get_content(@url))
136
154
  end
137
155
 
156
+ if defined?(HTTPClient::JRubySSLSocket)
157
+ def test_ciphers
158
+ cfg = @client.ssl_config
159
+ cfg.set_client_cert_file(path('client.cert'), path('client-pass.key'), 'pass4key')
160
+ cfg.add_trust_ca(path('ca.cert'))
161
+ cfg.add_trust_ca(path('subca.cert'))
162
+ cfg.timeout = 123
163
+ assert_equal("hello", @client.get_content(@url))
164
+ #
165
+ cfg.ciphers = []
166
+ begin
167
+ @client.get(@url)
168
+ assert(false)
169
+ rescue OpenSSL::SSL::SSLError => ssle
170
+ assert_match(/No appropriate protocol/, ssle.message)
171
+ end
172
+ #
173
+ cfg.ciphers = %w(TLS_RSA_WITH_AES_128_CBC_SHA)
174
+ assert_equal("hello", @client.get_content(@url))
175
+ #
176
+ cfg.ciphers = HTTPClient::SSLConfig::CIPHERS_DEFAULT
177
+ assert_equal("hello", @client.get_content(@url))
178
+ end
179
+
180
+ else
181
+
138
182
  def test_ciphers
139
183
  cfg = @client.ssl_config
140
184
  cfg.set_client_cert_file(path('client.cert'), path('client-pass.key'), 'pass4key')
@@ -157,15 +201,20 @@ end
157
201
  cfg.ciphers = "DEFAULT"
158
202
  assert_equal("hello", @client.get_content(@url))
159
203
  end
204
+ end
160
205
 
161
- def test_set_default_paths
162
- assert_raise(OpenSSL::SSL::SSLError) do
163
- @client.get(@url)
164
- end
165
- escape_env do
166
- ENV['SSL_CERT_FILE'] = File.join(DIR, 'ca-chain.cert')
167
- @client.ssl_config.set_default_paths
168
- @client.get(@url)
206
+ # SSL_CERT_FILE does not work with recent jruby-openssl.
207
+ # You should not depend on SSL_CERT_FILE on JRuby
208
+ if !defined?(JRUBY_VERSION)
209
+ def test_set_default_paths
210
+ assert_raise(OpenSSL::SSL::SSLError) do
211
+ @client.get(@url)
212
+ end
213
+ escape_env do
214
+ ENV['SSL_CERT_FILE'] = File.join(DIR, 'ca-chain.pem')
215
+ @client.ssl_config.set_default_paths
216
+ @client.get(@url)
217
+ end
169
218
  end
170
219
  end
171
220
 
@@ -180,7 +229,7 @@ end
180
229
 
181
230
  def test_allow_tlsv1
182
231
  teardown_server
183
- setup_server#_with_ssl_version(:TLSv1)
232
+ setup_server_with_ssl_version(:TLSv1)
184
233
  assert_nothing_raised do
185
234
  @client.ssl_config.verify_mode = nil
186
235
  @client.get("https://localhost:#{serverport}/hello")
@@ -440,8 +440,8 @@ EOF
440
440
  def test_load_cookies_escaped
441
441
  uri = urify('http://example.org/')
442
442
  f = Tempfile.new('test_cookie')
443
- File.open(f.path, 'w') do |f|
444
- f.write <<EOF
443
+ File.open(f.path, 'w') do |out|
444
+ out.write <<EOF
445
445
  http://example.org/ key "value" 0 .example.org / 13 0
446
446
  http://example.org/ key "" .example.org / 13 0
447
447
  http://example.org/ key .example.org / 13 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0.1
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: nahi@ruby-lang.org
@@ -17,25 +17,29 @@ executables:
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - README.md
20
21
  - bin/httpclient
21
22
  - bin/jsonclient
22
23
  - lib/hexdump.rb
24
+ - lib/http-access2.rb
23
25
  - lib/http-access2/cookie.rb
24
26
  - lib/http-access2/http.rb
25
- - lib/http-access2.rb
27
+ - lib/httpclient.rb
26
28
  - lib/httpclient/auth.rb
27
- - lib/httpclient/cacert.p7s
29
+ - lib/httpclient/cacert.pem
30
+ - lib/httpclient/cacert1024.pem
28
31
  - lib/httpclient/connection.rb
29
32
  - lib/httpclient/cookie.rb
30
33
  - lib/httpclient/http.rb
31
34
  - lib/httpclient/include_client.rb
35
+ - lib/httpclient/jruby_ssl_socket.rb
32
36
  - lib/httpclient/session.rb
33
37
  - lib/httpclient/ssl_config.rb
38
+ - lib/httpclient/ssl_socket.rb
34
39
  - lib/httpclient/timeout.rb
35
40
  - lib/httpclient/util.rb
36
41
  - lib/httpclient/version.rb
37
42
  - lib/httpclient/webagent-cookie.rb
38
- - lib/httpclient.rb
39
43
  - lib/jsonclient.rb
40
44
  - lib/oauthclient.rb
41
45
  - sample/async.rb
@@ -57,7 +61,7 @@ files:
57
61
  - sample/stream.rb
58
62
  - sample/thread.rb
59
63
  - sample/wcat.rb
60
- - test/ca-chain.cert
64
+ - test/ca-chain.pem
61
65
  - test/ca.cert
62
66
  - test/client-pass.key
63
67
  - test/client.cert
@@ -79,7 +83,6 @@ files:
79
83
  - test/test_jsonclient.rb
80
84
  - test/test_ssl.rb
81
85
  - test/test_webagent-cookie.rb
82
- - README.md
83
86
  homepage: https://github.com/nahi/httpclient
84
87
  licenses:
85
88
  - ruby
@@ -90,17 +93,17 @@ require_paths:
90
93
  - lib
91
94
  required_ruby_version: !ruby/object:Gem::Requirement
92
95
  requirements:
93
- - - '>='
96
+ - - ">="
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
99
  required_rubygems_version: !ruby/object:Gem::Requirement
97
100
  requirements:
98
- - - '>='
101
+ - - ">="
99
102
  - !ruby/object:Gem::Version
100
103
  version: '0'
101
104
  requirements: []
102
105
  rubyforge_project:
103
- rubygems_version: 2.0.14
106
+ rubygems_version: 2.4.5.1
104
107
  signing_key:
105
108
  specification_version: 4
106
109
  summary: gives something like the functionality of libwww-perl (LWP) in Ruby