excon 0.62.0 → 0.85.0

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.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.md +1 -1
  3. data/README.md +6 -5
  4. data/data/cacert.pem +939 -1720
  5. data/excon.gemspec +17 -2
  6. data/lib/excon.rb +25 -17
  7. data/lib/excon/connection.rb +206 -139
  8. data/lib/excon/constants.rb +38 -13
  9. data/lib/excon/error.rb +15 -0
  10. data/lib/excon/headers.rb +4 -3
  11. data/lib/excon/instrumentors/logging_instrumentor.rb +4 -15
  12. data/lib/excon/instrumentors/standard_instrumentor.rb +2 -9
  13. data/lib/excon/middlewares/base.rb +6 -0
  14. data/lib/excon/middlewares/capture_cookies.rb +1 -1
  15. data/lib/excon/middlewares/decompress.rb +2 -2
  16. data/lib/excon/middlewares/expects.rb +7 -1
  17. data/lib/excon/middlewares/idempotent.rb +20 -3
  18. data/lib/excon/middlewares/instrumentor.rb +8 -0
  19. data/lib/excon/middlewares/mock.rb +12 -3
  20. data/lib/excon/middlewares/redirect_follower.rb +25 -3
  21. data/lib/excon/middlewares/response_parser.rb +3 -0
  22. data/lib/excon/pretty_printer.rb +1 -8
  23. data/lib/excon/response.rb +12 -9
  24. data/lib/excon/socket.rb +51 -33
  25. data/lib/excon/ssl_socket.rb +33 -13
  26. data/lib/excon/test/plugin/server/exec.rb +2 -2
  27. data/lib/excon/test/server.rb +1 -1
  28. data/lib/excon/unix_socket.rb +1 -0
  29. data/lib/excon/utils.rb +58 -5
  30. data/lib/excon/version.rb +1 -1
  31. metadata +27 -98
  32. data/.document +0 -5
  33. data/.gitignore +0 -13
  34. data/.rspec +0 -3
  35. data/.travis.yml +0 -29
  36. data/Gemfile +0 -19
  37. data/Rakefile +0 -41
  38. data/benchmarks/class_vs_lambda.rb +0 -50
  39. data/benchmarks/concat_vs_insert.rb +0 -21
  40. data/benchmarks/concat_vs_interpolate.rb +0 -22
  41. data/benchmarks/cr_lf.rb +0 -21
  42. data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
  43. data/benchmarks/excon.rb +0 -69
  44. data/benchmarks/excon_vs.rb +0 -165
  45. data/benchmarks/for_vs_array_each.rb +0 -27
  46. data/benchmarks/for_vs_hash_each.rb +0 -27
  47. data/benchmarks/has_key-vs-lookup.rb +0 -177
  48. data/benchmarks/headers_case_sensitivity.rb +0 -83
  49. data/benchmarks/headers_split_vs_match.rb +0 -34
  50. data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
  51. data/benchmarks/merging.rb +0 -21
  52. data/benchmarks/single_vs_double_quotes.rb +0 -21
  53. data/benchmarks/string_ranged_index.rb +0 -87
  54. data/benchmarks/strip_newline.rb +0 -115
  55. data/benchmarks/vs_stdlib.rb +0 -82
  56. data/changelog.txt +0 -1083
  57. data/spec/excon/error_spec.rb +0 -139
  58. data/spec/excon/test/server_spec.rb +0 -28
  59. data/spec/excon_spec.rb +0 -7
  60. data/spec/helpers/file_path_helpers.rb +0 -22
  61. data/spec/requests/basic_spec.rb +0 -40
  62. data/spec/requests/eof_requests_spec.rb +0 -36
  63. data/spec/requests/unix_socket_spec.rb +0 -46
  64. data/spec/spec_helper.rb +0 -24
  65. data/spec/support/shared_contexts/test_server_context.rb +0 -83
  66. data/spec/support/shared_examples/shared_example_for_clients.rb +0 -218
  67. data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
  68. data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
  69. data/tests/authorization_header_tests.rb +0 -29
  70. data/tests/bad_tests.rb +0 -47
  71. data/tests/basic_tests.rb +0 -351
  72. data/tests/batch_requests.rb +0 -133
  73. data/tests/complete_responses.rb +0 -31
  74. data/tests/data/127.0.0.1.cert.crt +0 -20
  75. data/tests/data/127.0.0.1.cert.key +0 -27
  76. data/tests/data/excon.cert.crt +0 -20
  77. data/tests/data/excon.cert.key +0 -27
  78. data/tests/data/xs +0 -1
  79. data/tests/error_tests.rb +0 -145
  80. data/tests/header_tests.rb +0 -119
  81. data/tests/middlewares/canned_response_tests.rb +0 -34
  82. data/tests/middlewares/capture_cookies_tests.rb +0 -34
  83. data/tests/middlewares/decompress_tests.rb +0 -157
  84. data/tests/middlewares/escape_path_tests.rb +0 -36
  85. data/tests/middlewares/idempotent_tests.rb +0 -206
  86. data/tests/middlewares/instrumentation_tests.rb +0 -315
  87. data/tests/middlewares/mock_tests.rb +0 -304
  88. data/tests/middlewares/redirect_follower_tests.rb +0 -112
  89. data/tests/pipeline_tests.rb +0 -40
  90. data/tests/proxy_tests.rb +0 -306
  91. data/tests/query_string_tests.rb +0 -87
  92. data/tests/rackups/basic.rb +0 -41
  93. data/tests/rackups/basic.ru +0 -3
  94. data/tests/rackups/basic_auth.ru +0 -14
  95. data/tests/rackups/deflater.ru +0 -4
  96. data/tests/rackups/proxy.ru +0 -18
  97. data/tests/rackups/query_string.ru +0 -13
  98. data/tests/rackups/redirecting.ru +0 -23
  99. data/tests/rackups/redirecting_with_cookie.ru +0 -40
  100. data/tests/rackups/request_headers.ru +0 -15
  101. data/tests/rackups/request_methods.ru +0 -21
  102. data/tests/rackups/response_header.ru +0 -18
  103. data/tests/rackups/ssl.ru +0 -16
  104. data/tests/rackups/ssl_mismatched_cn.ru +0 -15
  105. data/tests/rackups/ssl_verify_peer.ru +0 -16
  106. data/tests/rackups/streaming.ru +0 -30
  107. data/tests/rackups/thread_safety.ru +0 -17
  108. data/tests/rackups/timeout.ru +0 -14
  109. data/tests/rackups/webrick_patch.rb +0 -34
  110. data/tests/request_headers_tests.rb +0 -21
  111. data/tests/request_method_tests.rb +0 -47
  112. data/tests/request_tests.rb +0 -59
  113. data/tests/response_tests.rb +0 -197
  114. data/tests/servers/bad.rb +0 -20
  115. data/tests/servers/eof.rb +0 -17
  116. data/tests/servers/error.rb +0 -20
  117. data/tests/servers/good.rb +0 -350
  118. data/tests/test_helper.rb +0 -306
  119. data/tests/thread_safety_tests.rb +0 -39
  120. data/tests/timeout_tests.rb +0 -12
  121. data/tests/utils_tests.rb +0 -81
data/benchmarks/excon.rb DELETED
@@ -1,69 +0,0 @@
1
- require 'rubygems' if RUBY_VERSION < '1.9'
2
- require 'bundler'
3
-
4
- Bundler.require(:default)
5
- Bundler.require(:benchmark)
6
-
7
- require 'sinatra/base'
8
-
9
- require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon')
10
-
11
- module Excon
12
- class Server < Sinatra::Base
13
-
14
- def self.run
15
- Rack::Handler::WEBrick.run(
16
- Excon::Server.new,
17
- :Port => 9292,
18
- :AccessLog => [],
19
- :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR)
20
- )
21
- end
22
-
23
- get '/data/:amount' do |amount|
24
- 'x' * amount.to_i
25
- end
26
-
27
- end
28
- end
29
-
30
- def with_server(&block)
31
- pid = Process.fork do
32
- Excon::Server.run
33
- end
34
- loop do
35
- sleep(1)
36
- begin
37
- Excon.get('http://localhost:9292/api/foo')
38
- break
39
- rescue
40
- end
41
- end
42
- yield
43
- ensure
44
- Process.kill(9, pid)
45
- end
46
-
47
- require 'tach'
48
-
49
- size = 10_000
50
- path = '/data/' << size.to_s
51
- url = 'http://localhost:9292' << path
52
-
53
- times = 1_000
54
-
55
- with_server do
56
-
57
- Tach.meter(times) do
58
-
59
- tach('Excon') do
60
- Excon.get(url).body
61
- end
62
-
63
- excon = Excon.new(url)
64
- tach('Excon (persistent)') do
65
- excon.request(:method => 'get').body
66
- end
67
-
68
- end
69
- end
@@ -1,165 +0,0 @@
1
- require 'rubygems' if RUBY_VERSION < '1.9'
2
- require 'bundler'
3
-
4
- Bundler.require(:default)
5
- Bundler.require(:benchmark)
6
-
7
- require 'sinatra/base'
8
-
9
- require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon')
10
-
11
- module Excon
12
- class Server < Sinatra::Base
13
-
14
- def self.run
15
- Rack::Handler::WEBrick.run(
16
- Excon::Server.new,
17
- :Port => 9292,
18
- :AccessLog => [],
19
- :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR)
20
- )
21
- end
22
-
23
- get '/data/:amount' do |amount|
24
- 'x' * amount.to_i
25
- end
26
-
27
- end
28
- end
29
-
30
- def with_server(&block)
31
- pid = Process.fork do
32
- Excon::Server.run
33
- end
34
- loop do
35
- sleep(1)
36
- begin
37
- Excon.get('http://localhost:9292/api/foo')
38
- break
39
- rescue
40
- end
41
- end
42
- yield
43
- ensure
44
- Process.kill(9, pid)
45
- end
46
-
47
- require 'em-http-request'
48
- require 'httparty'
49
- require 'net/http'
50
- require 'open-uri'
51
- require 'rest_client'
52
- require 'tach'
53
- require 'typhoeus'
54
-
55
- size = 10_000
56
- path = '/data/' << size.to_s
57
- url = 'http://localhost:9292' << path
58
-
59
- times = 1_000
60
-
61
- with_server do
62
-
63
- Tach.meter(times) do
64
-
65
- tach('curb (persistent)') do |n|
66
- curb = Curl::Easy.new
67
-
68
- n.times do
69
- curb.url = url
70
- curb.http_get
71
- curb.body_str
72
- end
73
- end
74
-
75
- tach('em-http-request') do |n|
76
- EventMachine.run {
77
- count = 0
78
-
79
- n.times do
80
- http = EventMachine::HttpRequest.new(url).get
81
-
82
- http.callback {
83
- http.response
84
- count += 1
85
- EM.stop if count == n
86
- }
87
-
88
- http.errback {
89
- http.response
90
- count += 1
91
- EM.stop if count == n
92
- }
93
- end
94
- }
95
- end
96
-
97
- tach('Excon') do
98
- Excon.get(url).body
99
- end
100
-
101
- excon = Excon.new(url)
102
- tach('Excon (persistent)') do
103
- excon.request(:method => 'get').body
104
- end
105
-
106
- tach('HTTParty') do
107
- HTTParty.get(url).body
108
- end
109
-
110
- tach('Net::HTTP') do
111
- # Net::HTTP.get('localhost', path, 9292)
112
- Net::HTTP.start('localhost', 9292) {|http| http.get(path).body }
113
- end
114
-
115
- Net::HTTP.start('localhost', 9292) do |http|
116
- tach('Net::HTTP (persistent)') do
117
- http.get(path).body
118
- end
119
- end
120
-
121
- tach('open-uri') do
122
- open(url).read
123
- end
124
-
125
- tach('RestClient') do
126
- RestClient.get(url)
127
- end
128
-
129
- streamly = StreamlyFFI::Connection.new
130
- tach('StreamlyFFI (persistent)') do
131
- streamly.get(url)
132
- end
133
-
134
- tach('Typhoeus') do
135
- Typhoeus::Request.get(url).body
136
- end
137
-
138
- end
139
- end
140
-
141
- # +--------------------------+----------+
142
- # | tach | total |
143
- # +--------------------------+----------+
144
- # | Excon (persistent) | 1.529095 |
145
- # +--------------------------+----------+
146
- # | curb (persistent) | 1.740387 |
147
- # +--------------------------+----------+
148
- # | Typhoeus | 1.876236 |
149
- # +--------------------------+----------+
150
- # | Excon | 2.001858 |
151
- # +--------------------------+----------+
152
- # | StreamlyFFI (persistent) | 2.200701 |
153
- # +--------------------------+----------+
154
- # | Net::HTTP | 2.395704 |
155
- # +--------------------------+----------+
156
- # | Net::HTTP (persistent) | 2.418099 |
157
- # +--------------------------+----------+
158
- # | HTTParty | 2.659317 |
159
- # +--------------------------+----------+
160
- # | RestClient | 2.958159 |
161
- # +--------------------------+----------+
162
- # | open-uri | 2.987051 |
163
- # +--------------------------+----------+
164
- # | em-http-request | 4.123798 |
165
- # +--------------------------+----------+
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- data = ["some", "var", "goes", "in", :here, 0]
5
- Tach.meter(1_000_000) do
6
- tach('for') do
7
- for element in data
8
- element == nil
9
- end
10
- end
11
- tach('each') do
12
- data.each do |element|
13
- element == nil
14
- end
15
- end
16
- end
17
-
18
- # ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
19
- #
20
- # +------+----------+
21
- # | tach | total |
22
- # +------+----------+
23
- # | for | 2.958672 |
24
- # +------+----------+
25
- # | each | 2.983550 |
26
- # +------+----------+
27
- #
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- data = {"some" => "var", "goes" => "in", :here => 0}
5
- Tach.meter(1_000_000) do
6
- tach('for') do
7
- for key, values in data
8
- key == values
9
- end
10
- end
11
- tach('each') do
12
- data.each do |key, values|
13
- key == values
14
- end
15
- end
16
- end
17
-
18
- # ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
19
- #
20
- # +------+----------+
21
- # | tach | total |
22
- # +------+----------+
23
- # | each | 2.748909 |
24
- # +------+----------+
25
- # | for | 2.949512 |
26
- # +------+----------+
27
- #
@@ -1,177 +0,0 @@
1
- # Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell
2
-
3
- require 'benchmark'
4
-
5
- iters = 1000000
6
- hash = {
7
- 'some_key' => 'some_val',
8
- 'nil_key' => nil
9
- }
10
-
11
- puts 'Hash#has_key vs. Hash#[]'
12
- Benchmark.bmbm do |x|
13
- x.report('Hash#has_key') do
14
- iters.times.each do
15
- hash.has_key? 'some_key'
16
- end
17
- end
18
-
19
- x.report('Hash#has_key (if statement)') do
20
- iters.times.each do
21
- if hash.has_key?('other_key')
22
- "hooray!"
23
- end
24
- end
25
- end
26
-
27
- x.report('Hash#has_key (non-existant)') do
28
- iters.times.each do
29
- hash.has_key? 'other_key'
30
- end
31
- end
32
-
33
- x.report('Hash#[]') do
34
- iters.times.each do
35
- hash['some_key']
36
- end
37
- end
38
-
39
- x.report('Hash#[] (if statement)') do
40
- iters.times.each do
41
- if hash['some_key']
42
- "hooray!"
43
- end
44
- end
45
- end
46
-
47
- x.report('Hash#[] (non-existant)') do
48
- iters.times.each do
49
- hash['other_key']
50
- end
51
- end
52
-
53
- x.report('Hash#has_key (if statement) explicit nil check') do
54
- iters.times.each do
55
- if hash.has_key?('nil_key') && !hash['nil_key'].nil?
56
- "hooray!"
57
- end
58
- end
59
- end
60
-
61
-
62
- x.report('Hash#has_key (if statement) implicit nil check') do
63
- iters.times.each do
64
- if hash.has_key?('nil_key') && hash['nil_key']
65
- "hooray!"
66
- end
67
- end
68
- end
69
-
70
- x.report('Hash#[] (if statement with nil)') do
71
- iters.times.each do
72
- if hash['nil_key']
73
- "hooray!"
74
- end
75
- end
76
- end
77
- end
78
-
79
- =begin
80
-
81
- $ rvm exec bash -c 'echo $RUBY_VERSION && ruby has_key-vs-hash\[key\].rb'
82
-
83
- jruby-1.5.6
84
- Hash#has_key vs. Hash#[]
85
- Rehearsal ---------------------------------------------------------------
86
- Hash#has_key 0.410000 0.000000 0.410000 ( 0.341000)
87
- Hash#has_key (if statement) 0.145000 0.000000 0.145000 ( 0.145000)
88
- Hash#has_key (non-existant) 0.116000 0.000000 0.116000 ( 0.116000)
89
- Hash#[] 0.189000 0.000000 0.189000 ( 0.189000)
90
- Hash#[] (if statement) 0.176000 0.000000 0.176000 ( 0.176000)
91
- Hash#[] (non-existant) 0.302000 0.000000 0.302000 ( 0.302000)
92
- ------------------------------------------------------ total: 1.338000sec
93
-
94
- user system total real
95
- Hash#has_key 0.128000 0.000000 0.128000 ( 0.128000)
96
- Hash#has_key (if statement) 0.128000 0.000000 0.128000 ( 0.128000)
97
- Hash#has_key (non-existant) 0.153000 0.000000 0.153000 ( 0.153000)
98
- Hash#[] 0.206000 0.000000 0.206000 ( 0.206000)
99
- Hash#[] (if statement) 0.182000 0.000000 0.182000 ( 0.182000)
100
- Hash#[] (non-existant) 0.252000 0.000000 0.252000 ( 0.252000)
101
-
102
- macruby-0.7.1
103
- Hash#has_key vs. Hash#[]
104
- Rehearsal ---------------------------------------------------------------
105
- Hash#has_key 2.530000 0.050000 2.580000 ( 1.917643)
106
- Hash#has_key (if statement) 2.590000 0.050000 2.640000 ( 1.935221)
107
- Hash#has_key (non-existant) 2.580000 0.050000 2.630000 ( 1.964230)
108
- Hash#[] 2.240000 0.040000 2.280000 ( 1.640999)
109
- Hash#[] (if statement) 3.620000 0.070000 3.690000 ( 2.530248)
110
- Hash#[] (non-existant) 2.060000 0.040000 2.100000 ( 1.473487)
111
- ----------------------------------------------------- total: 15.920000sec
112
-
113
- user system total real
114
- Hash#has_key 2.230000 0.030000 2.260000 ( 1.661843)
115
- Hash#has_key (if statement) 2.180000 0.040000 2.220000 ( 1.605644)
116
- Hash#has_key (non-existant) 2.160000 0.040000 2.200000 ( 1.582561)
117
- Hash#[] 2.160000 0.030000 2.190000 ( 1.581448)
118
- Hash#[] (if statement) 3.440000 0.070000 3.510000 ( 2.393421)
119
- Hash#[] (non-existant) 2.330000 0.040000 2.370000 ( 1.699338)
120
-
121
- rbx-head
122
- Hash#has_key vs. Hash#[]
123
- Rehearsal ---------------------------------------------------------------
124
- Hash#has_key 0.660584 0.004932 0.665516 ( 0.508601)
125
- Hash#has_key (if statement) 0.261708 0.000532 0.262240 ( 0.263021)
126
- Hash#has_key (non-existant) 0.265908 0.000827 0.266735 ( 0.259509)
127
- Hash#[] 0.396607 0.001189 0.397796 ( 0.372997)
128
- Hash#[] (if statement) 0.553003 0.001589 0.554592 ( 0.543859)
129
- Hash#[] (non-existant) 0.323748 0.000884 0.324632 ( 0.319055)
130
- ------------------------------------------------------ total: 2.471511sec
131
-
132
- user system total real
133
- Hash#has_key 0.332239 0.000819 0.333058 ( 0.333809)
134
- Hash#has_key (if statement) 0.284344 0.000521 0.284865 ( 0.285330)
135
- Hash#has_key (non-existant) 0.339695 0.001301 0.340996 ( 0.324259)
136
- Hash#[] 0.298555 0.000368 0.298923 ( 0.299557)
137
- Hash#[] (if statement) 0.392755 0.000773 0.393528 ( 0.395473)
138
- Hash#[] (non-existant) 0.277721 0.000464 0.278185 ( 0.278540)
139
-
140
- ruby-1.8.7-p330
141
- Hash#has_key vs. Hash#[]
142
- Rehearsal ---------------------------------------------------------------
143
- Hash#has_key 0.450000 0.000000 0.450000 ( 0.450143)
144
- Hash#has_key (if statement) 0.440000 0.000000 0.440000 ( 0.448278)
145
- Hash#has_key (non-existant) 0.420000 0.000000 0.420000 ( 0.416959)
146
- Hash#[] 0.450000 0.000000 0.450000 ( 0.450727)
147
- Hash#[] (if statement) 0.550000 0.000000 0.550000 ( 0.555043)
148
- Hash#[] (non-existant) 0.530000 0.000000 0.530000 ( 0.527189)
149
- ------------------------------------------------------ total: 2.840000sec
150
-
151
- user system total real
152
- Hash#has_key 0.440000 0.000000 0.440000 ( 0.447746)
153
- Hash#has_key (if statement) 0.450000 0.000000 0.450000 ( 0.450331)
154
- Hash#has_key (non-existant) 0.420000 0.000000 0.420000 ( 0.419157)
155
- Hash#[] 0.450000 0.000000 0.450000 ( 0.454438)
156
- Hash#[] (if statement) 0.570000 0.000000 0.570000 ( 0.563948)
157
- Hash#[] (non-existant) 0.520000 0.000000 0.520000 ( 0.527866)
158
-
159
- ruby-1.9.2-p136
160
- Hash#has_key vs. Hash#[]
161
- Rehearsal ---------------------------------------------------------------
162
- Hash#has_key 0.690000 0.000000 0.690000 ( 0.691657)
163
- Hash#has_key (if statement) 0.630000 0.000000 0.630000 ( 0.638418)
164
- Hash#has_key (non-existant) 0.640000 0.000000 0.640000 ( 0.637510)
165
- Hash#[] 0.580000 0.000000 0.580000 ( 0.584500)
166
- Hash#[] (if statement) 0.840000 0.010000 0.850000 ( 0.837541)
167
- Hash#[] (non-existant) 0.810000 0.000000 0.810000 ( 0.811598)
168
- ------------------------------------------------------ total: 4.200000sec
169
-
170
- user system total real
171
- Hash#has_key 0.690000 0.000000 0.690000 ( 0.694192)
172
- Hash#has_key (if statement) 0.640000 0.000000 0.640000 ( 0.641729)
173
- Hash#has_key (non-existant) 0.630000 0.000000 0.630000 ( 0.634470)
174
- Hash#[] 0.580000 0.000000 0.580000 ( 0.587844)
175
- Hash#[] (if statement) 0.830000 0.000000 0.830000 ( 0.832323)
176
- Hash#[] (non-existant) 0.790000 0.010000 0.800000 ( 0.791689)
177
- =end