httpclient 2.2.4 → 2.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +614 -0
- data/lib/hexdump.rb +15 -1
- data/lib/httpclient.rb +8 -8
- data/lib/httpclient/http.rb +13 -6
- data/lib/httpclient/session.rb +7 -2
- data/lib/httpclient/ssl_config.rb +39 -2
- data/lib/httpclient/version.rb +1 -1
- data/test/ca-chain.cert +44 -0
- data/test/helper.rb +27 -0
- data/test/test_auth.rb +5 -2
- data/test/test_hexdump.rb +14 -0
- data/test/test_http-access2.rb +24 -17
- data/test/test_httpclient.rb +100 -53
- data/test/test_ssl.rb +12 -1
- metadata +12 -3
data/test/test_httpclient.rb
CHANGED
@@ -76,10 +76,10 @@ class TestHTTPClient < Test::Unit::TestCase
|
|
76
76
|
assert_equal("= Request", lines[0])
|
77
77
|
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
78
78
|
assert_equal("GET /hello HTTP/0.9", lines[3])
|
79
|
-
assert_equal("Connection: close", lines[
|
80
|
-
assert_equal("= Response", lines[
|
81
|
-
assert_match(/^hello$/, lines[
|
82
|
-
assert_match(/^world$/, lines[
|
79
|
+
assert_equal("Connection: close", lines[6])
|
80
|
+
assert_equal("= Response", lines[7])
|
81
|
+
assert_match(/^hello$/, lines[8])
|
82
|
+
assert_match(/^world$/, lines[9])
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_protocol_version_http10
|
@@ -93,8 +93,24 @@ class TestHTTPClient < Test::Unit::TestCase
|
|
93
93
|
assert_equal("= Request", lines[0])
|
94
94
|
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
95
95
|
assert_equal("GET /hello HTTP/1.0", lines[3])
|
96
|
-
assert_equal("Connection: close", lines[
|
97
|
-
assert_equal("= Response", lines[
|
96
|
+
assert_equal("Connection: close", lines[6])
|
97
|
+
assert_equal("= Response", lines[7])
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_header_accept_by_default
|
101
|
+
str = ""
|
102
|
+
@client.debug_dev = str
|
103
|
+
@client.get(serverurl)
|
104
|
+
lines = str.split(/(?:\r?\n)+/)
|
105
|
+
assert_equal("Accept: */*", lines[4])
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_header_accept
|
109
|
+
str = ""
|
110
|
+
@client.debug_dev = str
|
111
|
+
@client.get(serverurl, :header => {:Accept => 'text/html'})
|
112
|
+
lines = str.split(/(?:\r?\n)+/)
|
113
|
+
assert_equal("Accept: text/html", lines[4])
|
98
114
|
end
|
99
115
|
|
100
116
|
def test_host_given
|
@@ -105,7 +121,7 @@ class TestHTTPClient < Test::Unit::TestCase
|
|
105
121
|
assert_equal("= Request", lines[0])
|
106
122
|
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
107
123
|
assert_equal("GET / HTTP/1.1", lines[3])
|
108
|
-
assert_equal("Host: localhost:#{serverport}", lines[
|
124
|
+
assert_equal("Host: localhost:#{serverport}", lines[6])
|
109
125
|
#
|
110
126
|
@client.reset_all
|
111
127
|
str = ""
|
@@ -127,7 +143,7 @@ class TestHTTPClient < Test::Unit::TestCase
|
|
127
143
|
assert_equal("= Request", lines[0])
|
128
144
|
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
129
145
|
assert_equal("GET / HTTP/1.1", lines[3])
|
130
|
-
assert_equal("Host: localhost:#{serverport}", lines[
|
146
|
+
assert_equal("Host: localhost:#{serverport}", lines[6])
|
131
147
|
@client.protocol_version = 'HTTP/1.1'
|
132
148
|
assert_equal('HTTP/1.1', @client.protocol_version)
|
133
149
|
str = ""
|
@@ -416,7 +432,9 @@ EOS
|
|
416
432
|
|
417
433
|
def test_redirect_relative
|
418
434
|
@client.test_loopback_http_response << "HTTP/1.0 302 OK\nLocation: hello\n\n"
|
419
|
-
|
435
|
+
silent do
|
436
|
+
assert_equal('hello', @client.get_content(serverurl + 'redirect1'))
|
437
|
+
end
|
420
438
|
#
|
421
439
|
@client.reset_all
|
422
440
|
@client.redirect_uri_callback = @client.method(:strict_redirect_uri_callback)
|
@@ -437,7 +455,9 @@ EOS
|
|
437
455
|
https_url.scheme = 'https'
|
438
456
|
@client.test_loopback_http_response << "HTTP/1.0 302 OK\nLocation: /foo\n\n"
|
439
457
|
@client.test_loopback_http_response << "HTTP/1.0 200 OK\n\nhello"
|
440
|
-
|
458
|
+
silent do
|
459
|
+
assert_equal('hello', @client.get_content(https_url))
|
460
|
+
end
|
441
461
|
end
|
442
462
|
|
443
463
|
def test_no_content
|
@@ -538,26 +558,29 @@ EOS
|
|
538
558
|
|
539
559
|
def test_head
|
540
560
|
assert_equal("head", @client.head(serverurl + 'servlet').header["x-head"][0])
|
541
|
-
|
542
|
-
|
561
|
+
param = {'1'=>'2', '3'=>'4'}
|
562
|
+
res = @client.head(serverurl + 'servlet', param)
|
563
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
543
564
|
end
|
544
565
|
|
545
566
|
def test_head_async
|
546
|
-
|
567
|
+
param = {'1'=>'2', '3'=>'4'}
|
568
|
+
conn = @client.head_async(serverurl + 'servlet', param)
|
547
569
|
Thread.pass while !conn.finished?
|
548
570
|
res = conn.pop
|
549
|
-
assert_equal(
|
571
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
550
572
|
end
|
551
573
|
|
552
574
|
def test_get
|
553
575
|
assert_equal("get", @client.get(serverurl + 'servlet').content)
|
554
|
-
|
555
|
-
|
576
|
+
param = {'1'=>'2', '3'=>'4'}
|
577
|
+
res = @client.get(serverurl + 'servlet', param)
|
578
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
556
579
|
assert_nil(res.contenttype)
|
557
580
|
#
|
558
581
|
url = serverurl.to_s + 'servlet?5=6&7=8'
|
559
|
-
res = @client.get(url,
|
560
|
-
assert_equal(
|
582
|
+
res = @client.get(url, param)
|
583
|
+
assert_equal(param.merge("5"=>"6", "7"=>"8"), params(res.header["x-query"][0]))
|
561
584
|
assert_nil(res.contenttype)
|
562
585
|
end
|
563
586
|
|
@@ -568,10 +591,11 @@ EOS
|
|
568
591
|
end
|
569
592
|
|
570
593
|
def test_get_async
|
571
|
-
|
594
|
+
param = {'1'=>'2', '3'=>'4'}
|
595
|
+
conn = @client.get_async(serverurl + 'servlet', param)
|
572
596
|
Thread.pass while !conn.finished?
|
573
597
|
res = conn.pop
|
574
|
-
assert_equal(
|
598
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
575
599
|
end
|
576
600
|
|
577
601
|
def test_get_async_for_largebody
|
@@ -603,8 +627,9 @@ EOS
|
|
603
627
|
|
604
628
|
def test_post
|
605
629
|
assert_equal("post", @client.post(serverurl + 'servlet').content[0, 4])
|
606
|
-
|
607
|
-
|
630
|
+
param = {'1'=>'2', '3'=>'4'}
|
631
|
+
res = @client.post(serverurl + 'servlet', param)
|
632
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
608
633
|
end
|
609
634
|
|
610
635
|
def test_post_follow_redirect
|
@@ -614,20 +639,21 @@ EOS
|
|
614
639
|
end
|
615
640
|
|
616
641
|
def test_post_with_content_type
|
642
|
+
param = [['1', '2'], ['3', '4']]
|
617
643
|
ext = {'content-type' => 'application/x-www-form-urlencoded', 'hello' => 'world'}
|
618
644
|
assert_equal("post", @client.post(serverurl + 'servlet').content[0, 4], ext)
|
619
|
-
res = @client.post(serverurl + 'servlet',
|
620
|
-
assert_equal(
|
645
|
+
res = @client.post(serverurl + 'servlet', param, ext)
|
646
|
+
assert_equal(Hash[param], params(res.header["x-query"][0]))
|
621
647
|
#
|
622
648
|
ext = [['content-type', 'multipart/form-data'], ['hello', 'world']]
|
623
649
|
assert_equal("post", @client.post(serverurl + 'servlet').content[0, 4], ext)
|
624
|
-
res = @client.post(serverurl + 'servlet',
|
650
|
+
res = @client.post(serverurl + 'servlet', param, ext)
|
625
651
|
assert_match(/Content-Disposition: form-data; name="1"/, res.content)
|
626
652
|
assert_match(/Content-Disposition: form-data; name="3"/, res.content)
|
627
653
|
#
|
628
654
|
ext = {'content-type' => 'multipart/form-data; boundary=hello'}
|
629
655
|
assert_equal("post", @client.post(serverurl + 'servlet').content[0, 4], ext)
|
630
|
-
res = @client.post(serverurl + 'servlet',
|
656
|
+
res = @client.post(serverurl + 'servlet', param, ext)
|
631
657
|
assert_match(/Content-Disposition: form-data; name="1"/, res.content)
|
632
658
|
assert_match(/Content-Disposition: form-data; name="3"/, res.content)
|
633
659
|
assert_equal("post,--hello\r\nContent-Disposition: form-data; name=\"1\"\r\n\r\n2\r\n--hello\r\nContent-Disposition: form-data; name=\"3\"\r\n\r\n4\r\n--hello--\r\n\r\n", res.content)
|
@@ -643,6 +669,19 @@ EOS
|
|
643
669
|
end
|
644
670
|
end
|
645
671
|
|
672
|
+
def test_post_with_file_without_size
|
673
|
+
STDOUT.sync = true
|
674
|
+
File.open(__FILE__) do |file|
|
675
|
+
def file.size
|
676
|
+
# Simulates some strange Windows behaviour
|
677
|
+
raise SystemCallError.new "Unknown Error (20047)"
|
678
|
+
end
|
679
|
+
assert_nothing_raised do
|
680
|
+
@client.post(serverurl + 'servlet', {1=>2, 3=>file})
|
681
|
+
end
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
646
685
|
def test_post_with_io # streaming, but not chunked
|
647
686
|
myio = StringIO.new("X" * (HTTP::Message::Body::DEFAULT_CHUNK_SIZE + 1))
|
648
687
|
def myio.read(*args)
|
@@ -677,10 +716,11 @@ EOS
|
|
677
716
|
end
|
678
717
|
|
679
718
|
def test_post_async
|
680
|
-
|
719
|
+
param = {'1'=>'2', '3'=>'4'}
|
720
|
+
conn = @client.post_async(serverurl + 'servlet', param)
|
681
721
|
Thread.pass while !conn.finished?
|
682
722
|
res = conn.pop
|
683
|
-
assert_equal(
|
723
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
684
724
|
end
|
685
725
|
|
686
726
|
def test_post_with_block
|
@@ -693,7 +733,8 @@ EOS
|
|
693
733
|
assert_nil(res.content)
|
694
734
|
#
|
695
735
|
called = false
|
696
|
-
|
736
|
+
param = [['1', '2'], ['3', '4']]
|
737
|
+
res = @client.post(serverurl + 'servlet', param) { |str|
|
697
738
|
assert_equal('post,1=2&3=4', str)
|
698
739
|
called = true
|
699
740
|
}
|
@@ -735,8 +776,9 @@ EOS
|
|
735
776
|
|
736
777
|
def test_put
|
737
778
|
assert_equal("put", @client.put(serverurl + 'servlet').content)
|
738
|
-
|
739
|
-
|
779
|
+
param = {'1'=>'2', '3'=>'4'}
|
780
|
+
res = @client.put(serverurl + 'servlet', param)
|
781
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
740
782
|
end
|
741
783
|
|
742
784
|
def test_put_bytesize
|
@@ -746,10 +788,11 @@ EOS
|
|
746
788
|
end
|
747
789
|
|
748
790
|
def test_put_async
|
749
|
-
|
791
|
+
param = {'1'=>'2', '3'=>'4'}
|
792
|
+
conn = @client.put_async(serverurl + 'servlet', param)
|
750
793
|
Thread.pass while !conn.finished?
|
751
794
|
res = conn.pop
|
752
|
-
assert_equal(
|
795
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
753
796
|
end
|
754
797
|
|
755
798
|
def test_delete
|
@@ -787,30 +830,34 @@ EOS
|
|
787
830
|
|
788
831
|
def test_proppatch
|
789
832
|
assert_equal("proppatch", @client.proppatch(serverurl + 'servlet').content)
|
790
|
-
|
833
|
+
param = {'1'=>'2', '3'=>'4'}
|
834
|
+
res = @client.proppatch(serverurl + 'servlet', param)
|
791
835
|
assert_equal('proppatch', res.content)
|
792
|
-
assert_equal(
|
836
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
793
837
|
end
|
794
838
|
|
795
839
|
def test_proppatch_async
|
796
|
-
|
840
|
+
param = {'1'=>'2', '3'=>'4'}
|
841
|
+
conn = @client.proppatch_async(serverurl + 'servlet', param)
|
797
842
|
Thread.pass while !conn.finished?
|
798
843
|
res = conn.pop
|
799
844
|
assert_equal('proppatch', res.content.read)
|
800
|
-
assert_equal(
|
845
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
801
846
|
end
|
802
847
|
|
803
848
|
def test_trace
|
804
849
|
assert_equal("trace", @client.trace(serverurl + 'servlet').content)
|
805
|
-
|
806
|
-
|
850
|
+
param = {'1'=>'2', '3'=>'4'}
|
851
|
+
res = @client.trace(serverurl + 'servlet', param)
|
852
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
807
853
|
end
|
808
854
|
|
809
855
|
def test_trace_async
|
810
|
-
|
856
|
+
param = {'1'=>'2', '3'=>'4'}
|
857
|
+
conn = @client.trace_async(serverurl + 'servlet', param)
|
811
858
|
Thread.pass while !conn.finished?
|
812
859
|
res = conn.pop
|
813
|
-
assert_equal(
|
860
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
814
861
|
end
|
815
862
|
|
816
863
|
def test_chunked
|
@@ -874,6 +921,13 @@ EOS
|
|
874
921
|
assert_match("ABC: DEF", lines[5])
|
875
922
|
end
|
876
923
|
|
924
|
+
def test_http_custom_date_header
|
925
|
+
@client.debug_dev = (str = "")
|
926
|
+
res = @client.get(serverurl + 'hello', :header => {'Date' => 'foo'})
|
927
|
+
lines = str.split(/(?:\r?\n)+/)
|
928
|
+
assert_equal('Date: foo', lines[4])
|
929
|
+
end
|
930
|
+
|
877
931
|
def test_timeout
|
878
932
|
assert_equal(60, @client.connect_timeout)
|
879
933
|
assert_equal(120, @client.send_timeout)
|
@@ -1357,12 +1411,14 @@ EOS
|
|
1357
1411
|
end
|
1358
1412
|
|
1359
1413
|
def test_socket_local
|
1360
|
-
@client.socket_local.host = '
|
1414
|
+
@client.socket_local.host = '127.0.0.1'
|
1361
1415
|
assert_equal('hello', @client.get_content(serverurl + 'hello'))
|
1362
1416
|
@client.reset_all
|
1363
1417
|
@client.socket_local.port = serverport
|
1364
|
-
|
1365
|
-
|
1418
|
+
begin
|
1419
|
+
@client.get_content(serverurl + 'hello')
|
1420
|
+
rescue Errno::EADDRINUSE, SocketError
|
1421
|
+
assert(true)
|
1366
1422
|
end
|
1367
1423
|
end
|
1368
1424
|
|
@@ -1412,15 +1468,6 @@ private
|
|
1412
1468
|
@server_thread = start_server_thread(@server)
|
1413
1469
|
end
|
1414
1470
|
|
1415
|
-
def escape_env
|
1416
|
-
env = {}
|
1417
|
-
env.update(ENV)
|
1418
|
-
yield
|
1419
|
-
ensure
|
1420
|
-
ENV.clear
|
1421
|
-
ENV.update(env)
|
1422
|
-
end
|
1423
|
-
|
1424
1471
|
def escape_noproxy
|
1425
1472
|
backup = HTTPClient::NO_PROXY_HOSTS.dup
|
1426
1473
|
HTTPClient::NO_PROXY_HOSTS.clear
|
data/test/test_ssl.rb
CHANGED
@@ -34,7 +34,7 @@ class TestSSL < Test::Unit::TestCase
|
|
34
34
|
assert_nil(cfg.verify_callback)
|
35
35
|
assert_nil(cfg.timeout)
|
36
36
|
assert_equal(OpenSSL::SSL::OP_ALL | OpenSSL::SSL::OP_NO_SSLv2, cfg.options)
|
37
|
-
assert_equal("ALL:!
|
37
|
+
assert_equal("ALL:!aNULL:!eNULL:!SSLv2", cfg.ciphers)
|
38
38
|
assert_instance_of(OpenSSL::X509::Store, cfg.cert_store)
|
39
39
|
end
|
40
40
|
|
@@ -155,6 +155,17 @@ end
|
|
155
155
|
assert_equal("hello", @client.get_content(@url))
|
156
156
|
end
|
157
157
|
|
158
|
+
def test_set_default_paths
|
159
|
+
assert_raise(OpenSSL::SSL::SSLError) do
|
160
|
+
@client.get(@url)
|
161
|
+
end
|
162
|
+
escape_env do
|
163
|
+
ENV['SSL_CERT_FILE'] = File.join(DIR, 'ca-chain.cert')
|
164
|
+
@client.ssl_config.set_default_paths
|
165
|
+
@client.get(@url)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
158
169
|
private
|
159
170
|
|
160
171
|
def cert(filename)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: nahi@ruby-lang.org
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- test/server.cert
|
58
58
|
- test/htdigest
|
59
59
|
- test/test_ssl.rb
|
60
|
+
- test/test_hexdump.rb
|
60
61
|
- test/test_cookie.rb
|
61
62
|
- test/runner.rb
|
62
63
|
- test/htpasswd
|
@@ -66,8 +67,10 @@ files:
|
|
66
67
|
- test/ca.cert
|
67
68
|
- test/sslsvr.rb
|
68
69
|
- test/subca.cert
|
70
|
+
- test/ca-chain.cert
|
69
71
|
- test/server.key
|
70
72
|
- test/test_httpclient.rb
|
73
|
+
- README.txt
|
71
74
|
homepage: http://github.com/nahi/httpclient
|
72
75
|
licenses: []
|
73
76
|
post_install_message:
|
@@ -80,15 +83,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
83
|
- - ! '>='
|
81
84
|
- !ruby/object:Gem::Version
|
82
85
|
version: '0'
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
hash: -3213102379838367907
|
83
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
90
|
none: false
|
85
91
|
requirements:
|
86
92
|
- - ! '>='
|
87
93
|
- !ruby/object:Gem::Version
|
88
94
|
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: -3213102379838367907
|
89
98
|
requirements: []
|
90
99
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.23
|
92
101
|
signing_key:
|
93
102
|
specification_version: 3
|
94
103
|
summary: gives something like the functionality of libwww-perl (LWP) in Ruby
|