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
@@ -1,34 +0,0 @@
1
- Shindo.tests("Excon support for middlewares that return canned responses") do
2
- the_body = "canned"
3
-
4
- canned_response_middleware = Class.new(Excon::Middleware::Base) do
5
- define_method :request_call do |params|
6
- params[:response] = {
7
- :body => the_body,
8
- :headers => {},
9
- :status => 200
10
- }
11
- super(params)
12
- end
13
- end
14
-
15
- tests('does not mutate the canned response body').returns(the_body) do
16
- Excon.get(
17
- 'http://some-host.com/some-path',
18
- :middlewares => [canned_response_middleware] + Excon.defaults[:middlewares]
19
- ).body
20
- end
21
-
22
- tests('yields non-mutated body to response_block').returns(the_body) do
23
- body = ''
24
- response_block = lambda { |chunk, _, _| body << chunk }
25
- Excon.get(
26
- 'http://some-host.com/some-path',
27
- :middlewares => [canned_response_middleware] + Excon.defaults[:middlewares],
28
- :response_block => response_block
29
- )
30
- body
31
- end
32
-
33
- end
34
-
@@ -1,34 +0,0 @@
1
- Shindo.tests("Excon redirecting with cookie preserved") do
2
- env_init
3
-
4
- with_rackup('redirecting_with_cookie.ru') do
5
- tests('second request will send cookies set by the first').returns('ok') do
6
- Excon.get(
7
- 'http://127.0.0.1:9292',
8
- :path => '/sets_cookie',
9
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::CaptureCookies, Excon::Middleware::RedirectFollower]
10
- ).body
11
- end
12
-
13
- tests('second request will send multiple cookies set by the first').returns('ok') do
14
- Excon.get(
15
- 'http://127.0.0.1:9292',
16
- :path => '/sets_multi_cookie',
17
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::CaptureCookies, Excon::Middleware::RedirectFollower]
18
- ).body
19
- end
20
- end
21
-
22
- with_rackup('redirecting.ru') do
23
- tests("runs normally when there are no cookies set").returns('ok') do
24
- Excon.post(
25
- 'http://127.0.0.1:9292',
26
- :path => '/first',
27
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::CaptureCookies, Excon::Middleware::RedirectFollower],
28
- :body => "a=Some_content"
29
- ).body
30
- end
31
- end
32
-
33
- env_restore
34
- end
@@ -1,157 +0,0 @@
1
- Shindo.tests('Excon Decompress Middleware') do
2
- env_init
3
-
4
- with_server('good') do
5
-
6
- before do
7
- @connection ||= Excon.new(
8
- 'http://127.0.0.1:9292/echo/content-encoded',
9
- :method => :post,
10
- :body => 'hello world',
11
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::Decompress]
12
- )
13
- end
14
-
15
- tests('gzip') do
16
- resp = nil
17
-
18
- tests('response body decompressed').returns('hello world') do
19
- resp = @connection.request(
20
- :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0' }
21
- )
22
- resp[:body]
23
- end
24
-
25
- tests('server sent content-encoding').returns('gzip') do
26
- resp[:headers]['Content-Encoding-Sent']
27
- end
28
-
29
- tests('removes processed encoding from header').returns('') do
30
- resp[:headers]['Content-Encoding']
31
- end
32
-
33
- tests('empty response body').returns('') do
34
- resp = @connection.request(:body => '')
35
- resp[:body]
36
- end
37
- end
38
-
39
- tests('deflate') do
40
- resp = nil
41
-
42
- tests('response body decompressed').returns('hello world') do
43
- resp = @connection.request(
44
- :headers => { 'Accept-Encoding' => 'gzip;q=0, deflate' }
45
- )
46
- resp[:body]
47
- end
48
-
49
- tests('server sent content-encoding').returns('deflate') do
50
- resp[:headers]['Content-Encoding-Sent']
51
- end
52
-
53
- tests('removes processed encoding from header').returns('') do
54
- resp[:headers]['Content-Encoding']
55
- end
56
- end
57
-
58
- tests('with pre-encoding') do
59
- resp = nil
60
-
61
- tests('server sent content-encoding').returns('other, gzip') do
62
- resp = @connection.request(
63
- :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0',
64
- 'Content-Encoding-Pre' => 'other' }
65
- )
66
- resp[:headers]['Content-Encoding-Sent']
67
- end
68
-
69
- tests('processed encoding removed from header').returns('other') do
70
- resp[:headers]['Content-Encoding']
71
- end
72
-
73
- tests('response body decompressed').returns('hello world') do
74
- resp[:body]
75
- end
76
-
77
- end
78
-
79
- tests('with post-encoding') do
80
- resp = nil
81
-
82
- tests('server sent content-encoding').returns('gzip, other') do
83
- resp = @connection.request(
84
- :headers => { 'Accept-Encoding' => 'gzip, deflate;q=0',
85
- 'Content-Encoding-Post' => 'other' }
86
- )
87
- resp[:headers]['Content-Encoding-Sent']
88
- end
89
-
90
- tests('unprocessed since last applied is unknown').returns('gzip, other') do
91
- resp[:headers]['Content-Encoding']
92
- end
93
-
94
- tests('response body still compressed').returns('hello world') do
95
- Zlib::GzipReader.new(StringIO.new(resp[:body])).read
96
- end
97
-
98
- end
99
-
100
- tests('with a :response_block') do
101
- captures = nil
102
- resp = nil
103
-
104
- tests('server sent content-encoding').returns('gzip') do
105
- captures = capture_response_block do |block|
106
- resp = @connection.request(
107
- :headers => { 'Accept-Encoding' => 'gzip'},
108
- :response_block => block
109
- )
110
- end
111
- resp[:headers]['Content-Encoding-Sent']
112
- end
113
-
114
- tests('unprocessed since :response_block was used').returns('gzip') do
115
- resp[:headers]['Content-Encoding']
116
- end
117
-
118
- tests(':response_block passed unprocessed data').returns('hello world') do
119
- body = captures.map {|capture| capture[0] }.join
120
- Zlib::GzipReader.new(StringIO.new(body)).read
121
- end
122
-
123
- end
124
-
125
- tests('adds Accept-Encoding if needed') do
126
-
127
- tests('without a :response_block').returns('deflate, gzip') do
128
- resp = Excon.post(
129
- 'http://127.0.0.1:9292/echo/request',
130
- :body => 'hello world',
131
- :middlewares => Excon.defaults[:middlewares] +
132
- [Excon::Middleware::Decompress]
133
- )
134
- request = Marshal.load(resp.body)
135
- request[:headers]['Accept-Encoding']
136
- end
137
-
138
- tests('with a :response_block').returns(nil) do
139
- captures = capture_response_block do |block|
140
- Excon.post(
141
- 'http://127.0.0.1:9292/echo/request',
142
- :body => 'hello world',
143
- :response_block => block,
144
- :middlewares => Excon.defaults[:middlewares] +
145
- [Excon::Middleware::Decompress]
146
- )
147
- end
148
- request = Marshal.load(captures.map {|capture| capture[0] }.join)
149
- request[:headers]['Accept-Encoding']
150
- end
151
-
152
- end
153
-
154
- end
155
-
156
- env_restore
157
- end
@@ -1,36 +0,0 @@
1
- Shindo.tests('Excon Decompress Middleware') do
2
- env_init
3
- with_rackup('basic.ru') do
4
- tests('encoded uri passed to connection') do
5
- tests('GET /echo%20dirty').returns(200) do
6
- connection = Excon::Connection.new({
7
- :host => '127.0.0.1',
8
- :hostname => '127.0.0.1',
9
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::EscapePath],
10
- :nonblock => false,
11
- :port => 9292,
12
- :scheme => 'http',
13
- :ssl_verify_peer => false
14
- })
15
- response = connection.request(:method => :get, :path => '/echo%20dirty')
16
- response[:status]
17
- end
18
- end
19
-
20
- tests('unencoded uri passed to connection') do
21
- tests('GET /echo dirty').returns(200) do
22
- connection = Excon::Connection.new({
23
- :host => '127.0.0.1',
24
- :hostname => '127.0.0.1',
25
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::EscapePath],
26
- :nonblock => false,
27
- :port => 9292,
28
- :scheme => 'http',
29
- :ssl_verify_peer => false
30
- })
31
- response = connection.request(:method => :get, :path => '/echo dirty')
32
- response[:status]
33
- end
34
- end
35
- end
36
- end
@@ -1,206 +0,0 @@
1
- Shindo.tests('Excon request idempotencey') do
2
-
3
- before do
4
- @connection = Excon.new('http://127.0.0.1:9292', :mock => true)
5
- end
6
-
7
- after do
8
- # flush any existing stubs after each test
9
- Excon.stubs.clear
10
- end
11
-
12
- tests("Non-idempotent call with an erroring socket").raises(Excon::Errors::SocketError) do
13
- run_count = 0
14
- Excon.stub({:method => :get}) { |params|
15
- run_count += 1
16
- if run_count <= 3 # First 3 calls fail.
17
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
18
- else
19
- {:body => params[:body], :headers => params[:headers], :status => 200}
20
- end
21
- }
22
-
23
- @connection.request(:method => :get, :path => '/some-path')
24
- end
25
-
26
- tests("Idempotent request with socket erroring first 3 times").returns(200) do
27
- run_count = 0
28
- Excon.stub({:method => :get}) { |params|
29
- run_count += 1
30
- if run_count <= 3 # First 3 calls fail.
31
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
32
- else
33
- {:body => params[:body], :headers => params[:headers], :status => 200}
34
- end
35
- }
36
-
37
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
38
- response.status
39
- end
40
-
41
- tests("Idempotent request with socket erroring first 5 times").raises(Excon::Errors::SocketError) do
42
- run_count = 0
43
- Excon.stub({:method => :get}) { |params|
44
- run_count += 1
45
- if run_count <= 5 # First 5 calls fail.
46
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
47
- else
48
- {:body => params[:body], :headers => params[:headers], :status => 200}
49
- end
50
- }
51
-
52
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
53
- response.status
54
- end
55
-
56
- tests("Lowered retry limit with socket erroring first time").returns(200) do
57
- run_count = 0
58
- Excon.stub({:method => :get}) { |params|
59
- run_count += 1
60
- if run_count <= 1 # First call fails.
61
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
62
- else
63
- {:body => params[:body], :headers => params[:headers], :status => 200}
64
- end
65
- }
66
-
67
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
68
- response.status
69
- end
70
-
71
- tests("Lowered retry limit with socket erroring first 3 times").raises(Excon::Errors::SocketError) do
72
- run_count = 0
73
- Excon.stub({:method => :get}) { |params|
74
- run_count += 1
75
- if run_count <= 3 # First 3 calls fail.
76
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
77
- else
78
- {:body => params[:body], :headers => params[:headers], :status => 200}
79
- end
80
- }
81
-
82
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
83
- response.status
84
- end
85
-
86
- tests("Raised retry limit with socket erroring first 5 times").returns(200) do
87
- run_count = 0
88
- Excon.stub({:method => :get}) { |params|
89
- run_count += 1
90
- if run_count <= 5 # First 5 calls fail.
91
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
92
- else
93
- {:body => params[:body], :headers => params[:headers], :status => 200}
94
- end
95
- }
96
-
97
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
98
- response.status
99
- end
100
-
101
- tests("Raised retry limit with socket erroring first 9 times").raises(Excon::Errors::SocketError) do
102
- run_count = 0
103
- Excon.stub({:method => :get}) { |params|
104
- run_count += 1
105
- if run_count <= 9 # First 9 calls fail.
106
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
107
- else
108
- {:body => params[:body], :headers => params[:headers], :status => 200}
109
- end
110
- }
111
-
112
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
113
- response.status
114
- end
115
-
116
- tests("Retry limit in constructor with socket erroring first 5 times").returns(200) do
117
- run_count = 0
118
- Excon.stub({:method => :get}) { |params|
119
- run_count += 1
120
- if run_count <= 5 # First 5 calls fail.
121
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
122
- else
123
- {:body => params[:body], :headers => params[:headers], :status => 200}
124
- end
125
- }
126
-
127
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 6)
128
- response.status
129
- end
130
-
131
- tests("Retry limit and sleep in constructor with socket erroring first 2 times").returns(200) do
132
- run_count = 0
133
- Excon.stub({:method => :get}) { |params|
134
- run_count += 1
135
- if run_count <= 2 # First 5 calls fail.
136
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
137
- else
138
- {:body => params[:body], :headers => params[:headers], :status => 200}
139
- end
140
- }
141
-
142
-
143
- # NOTE: A short :retry_interval will avoid slowing down the tests.
144
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 3, :retry_interval => 0.1)
145
- response.status
146
- end
147
-
148
- tests("Retry limit and sleep in constructor with socket erroring first 2 times").raises(Excon::Errors::SocketError) do
149
- run_count = 0
150
- Excon.stub({:method => :get}) { |params|
151
- run_count += 1
152
- if run_count <= 2 # First 5 calls fail.
153
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
154
- else
155
- {:body => params[:body], :headers => params[:headers], :status => 200}
156
- end
157
- }
158
-
159
- # NOTE: A short :retry_interval will avoid slowing down the tests.
160
- response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2, :retry_interval => 0.1)
161
- response.status
162
- end
163
-
164
- class Block
165
- attr_reader :rewound
166
- def initialize
167
- @rewound = false
168
- end
169
- def call(_)
170
- end
171
- def rewind
172
- @rewound = true
173
- end
174
- end
175
-
176
- tests("request_block rewound").returns(true) do
177
- run_count = 0
178
- Excon.stub({:method => :get}) { |params|
179
- run_count += 1
180
- if run_count <= 1 # First call fails.
181
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
182
- else
183
- {:body => params[:body], :headers => params[:headers], :status => 200}
184
- end
185
- }
186
- request_block = Block.new
187
- @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :request_block => request_block, :retry_limit => 2, :retry_interval => 0.1)
188
- request_block.rewound
189
- end
190
-
191
- tests("response_block rewound").returns(true) do
192
- run_count = 0
193
- Excon.stub({:method => :get}) { |params|
194
- run_count += 1
195
- if run_count <= 1 # First call fails.
196
- raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
197
- else
198
- {:body => params[:body], :headers => params[:headers], :status => 200}
199
- end
200
- }
201
- response_block = Block.new
202
- @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :response_block => response_block, :retry_limit => 2, :retry_interval => 0.1)
203
- response_block.rewound
204
- end
205
-
206
- end