excon 0.64.0 → 0.65.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of excon might be problematic. Click here for more details.

Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/data/cacert.pem +108 -2
  3. data/excon.gemspec +7 -2
  4. data/lib/excon.rb +11 -11
  5. data/lib/excon/connection.rb +25 -25
  6. data/lib/excon/response.rb +1 -1
  7. data/lib/excon/version.rb +1 -1
  8. metadata +3 -101
  9. data/.document +0 -5
  10. data/.github/stale.yml +0 -17
  11. data/.gitignore +0 -13
  12. data/.rspec +0 -3
  13. data/.travis.yml +0 -17
  14. data/Gemfile +0 -19
  15. data/Rakefile +0 -41
  16. data/benchmarks/class_vs_lambda.rb +0 -50
  17. data/benchmarks/concat_vs_insert.rb +0 -21
  18. data/benchmarks/concat_vs_interpolate.rb +0 -22
  19. data/benchmarks/cr_lf.rb +0 -21
  20. data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
  21. data/benchmarks/excon.rb +0 -69
  22. data/benchmarks/excon_vs.rb +0 -165
  23. data/benchmarks/for_vs_array_each.rb +0 -27
  24. data/benchmarks/for_vs_hash_each.rb +0 -27
  25. data/benchmarks/has_key-vs-lookup.rb +0 -177
  26. data/benchmarks/headers_case_sensitivity.rb +0 -83
  27. data/benchmarks/headers_split_vs_match.rb +0 -34
  28. data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
  29. data/benchmarks/merging.rb +0 -21
  30. data/benchmarks/single_vs_double_quotes.rb +0 -21
  31. data/benchmarks/string_ranged_index.rb +0 -87
  32. data/benchmarks/strip_newline.rb +0 -115
  33. data/benchmarks/vs_stdlib.rb +0 -82
  34. data/changelog.txt +0 -1113
  35. data/spec/excon/error_spec.rb +0 -139
  36. data/spec/excon/test/server_spec.rb +0 -28
  37. data/spec/excon_spec.rb +0 -7
  38. data/spec/helpers/file_path_helpers.rb +0 -22
  39. data/spec/helpers/warning_helpers.rb +0 -9
  40. data/spec/requests/basic_spec.rb +0 -40
  41. data/spec/requests/eof_requests_spec.rb +0 -36
  42. data/spec/requests/unix_socket_spec.rb +0 -38
  43. data/spec/requests/validation_spec.rb +0 -80
  44. data/spec/spec_helper.rb +0 -26
  45. data/spec/support/shared_contexts/test_server_context.rb +0 -83
  46. data/spec/support/shared_contexts/test_stub_context.rb +0 -11
  47. data/spec/support/shared_examples/shared_example_for_clients.rb +0 -220
  48. data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
  49. data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
  50. data/tests/authorization_header_tests.rb +0 -27
  51. data/tests/bad_tests.rb +0 -69
  52. data/tests/basic_tests.rb +0 -351
  53. data/tests/batch_requests.rb +0 -133
  54. data/tests/complete_responses.rb +0 -31
  55. data/tests/data/127.0.0.1.cert.crt +0 -17
  56. data/tests/data/127.0.0.1.cert.key +0 -28
  57. data/tests/data/excon.cert.crt +0 -17
  58. data/tests/data/excon.cert.key +0 -28
  59. data/tests/data/xs +0 -1
  60. data/tests/error_tests.rb +0 -145
  61. data/tests/header_tests.rb +0 -119
  62. data/tests/instrumentors/logging_instrumentor_tests.rb +0 -28
  63. data/tests/middleware_tests.rb +0 -27
  64. data/tests/middlewares/canned_response_tests.rb +0 -34
  65. data/tests/middlewares/capture_cookies_tests.rb +0 -34
  66. data/tests/middlewares/decompress_tests.rb +0 -157
  67. data/tests/middlewares/escape_path_tests.rb +0 -36
  68. data/tests/middlewares/idempotent_tests.rb +0 -245
  69. data/tests/middlewares/instrumentation_tests.rb +0 -315
  70. data/tests/middlewares/mock_tests.rb +0 -304
  71. data/tests/middlewares/redirect_follower_tests.rb +0 -112
  72. data/tests/pipeline_tests.rb +0 -40
  73. data/tests/proxy_tests.rb +0 -306
  74. data/tests/query_string_tests.rb +0 -87
  75. data/tests/rackups/basic.rb +0 -41
  76. data/tests/rackups/basic.ru +0 -3
  77. data/tests/rackups/basic_auth.ru +0 -14
  78. data/tests/rackups/deflater.ru +0 -4
  79. data/tests/rackups/proxy.ru +0 -18
  80. data/tests/rackups/query_string.ru +0 -13
  81. data/tests/rackups/redirecting.ru +0 -23
  82. data/tests/rackups/redirecting_with_cookie.ru +0 -40
  83. data/tests/rackups/request_headers.ru +0 -15
  84. data/tests/rackups/request_methods.ru +0 -21
  85. data/tests/rackups/response_header.ru +0 -18
  86. data/tests/rackups/ssl.ru +0 -16
  87. data/tests/rackups/ssl_mismatched_cn.ru +0 -15
  88. data/tests/rackups/ssl_verify_peer.ru +0 -16
  89. data/tests/rackups/streaming.ru +0 -30
  90. data/tests/rackups/thread_safety.ru +0 -17
  91. data/tests/rackups/timeout.ru +0 -14
  92. data/tests/rackups/webrick_patch.rb +0 -34
  93. data/tests/request_headers_tests.rb +0 -21
  94. data/tests/request_method_tests.rb +0 -47
  95. data/tests/request_tests.rb +0 -58
  96. data/tests/response_tests.rb +0 -197
  97. data/tests/servers/bad.rb +0 -25
  98. data/tests/servers/eof.rb +0 -17
  99. data/tests/servers/error.rb +0 -20
  100. data/tests/servers/good.rb +0 -342
  101. data/tests/servers/good_ipv4.rb +0 -8
  102. data/tests/servers/good_ipv6.rb +0 -8
  103. data/tests/test_helper.rb +0 -297
  104. data/tests/thread_safety_tests.rb +0 -39
  105. data/tests/timeout_tests.rb +0 -12
  106. data/tests/utils_tests.rb +0 -81
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Excon::Error do
4
- # Regression against e300458f2d9330cb265baeb8973120d08c665d9
5
- describe '#status_errors' do
6
- describe '.keys ' do
7
- expected = [
8
- 100,
9
- 101,
10
- (200..206).to_a,
11
- (300..307).to_a,
12
- (400..417).to_a,
13
- 422,
14
- 429,
15
- (500..504).to_a
16
- ].flatten
17
-
18
- it('returns the pertinent HTTP error numbers') do
19
- expected.flatten == Excon::Error.status_errors.keys
20
- end
21
- end
22
- end
23
-
24
- describe '#new' do
25
- it('returns an Excon::Error') do
26
- expect(Excon::Error.new('bar').class == Excon::Error).to be true
27
- end
28
- it('raises errors for bad URIs') do
29
- expect { Excon.new('foo') }.to raise_error(ArgumentError)
30
- end
31
-
32
- it('raises errors for bad paths') do
33
- expect { Excon.new('http://localhost', path: "foo\r\nbar: baz") }.to raise_error(URI::InvalidURIError)
34
- end
35
- end
36
-
37
- context 'when remaining backwards compatible' do
38
- describe '#new' do
39
- it 'should raise standard error and catch standard error' do
40
- expect { raise Excon::Error::Client, 'foo' }.to raise_error(Excon::Error)
41
- end
42
-
43
- it 'should raise legacy errors and catch legacy errors' do
44
- expect do
45
- raise Excon::Errors::Error, 'bar'
46
- end.to raise_error(Excon::Errors::Error)
47
- end
48
-
49
- it 'should raise standard error and catch legacy errors' do
50
- expect do
51
- raise Excon::Error::NotFound, 'bar'
52
- end.to raise_error(Excon::Errors::Error)
53
- end
54
- end
55
-
56
- describe '#status_error' do
57
- it 'should raise with status_error() and catch with standard error' do
58
- expect do
59
- raise Excon::Error.status_error({ expects: 200 }, status: 400)
60
- end.to raise_error(Excon::Error)
61
- end
62
-
63
- it 'should raise with status_error() and catch with legacy error' do
64
- expect do
65
- raise Excon::Error.status_error({ expects: 200 }, status: 400)
66
- end.to raise_error(Excon::Errors::BadRequest)
67
- end
68
-
69
- it 'should raise with legacy status_error() and catch with standard' do
70
- expect do
71
- raise Excon::Errors.status_error({ expects: 200 }, status: 400)
72
- end.to raise_error(Excon::Error)
73
- end
74
- end
75
- end
76
-
77
- context 'when exceptions are rescued' do
78
- include_context("test server", :exec, 'error.rb', :before => :start, :after => :stop )
79
-
80
- context 'when :debug_request and :debug_response are switched off' do
81
- it('exception message does not include response or response info') do
82
- begin
83
- Excon.get('http://127.0.0.1:9292/error/not_found', expects: 200)
84
- rescue Excon::Errors::HTTPStatusError => err
85
- truth =
86
- err.message.include?('Expected(200) <=> Actual(404 Not Found)') &&
87
- !err.message.include?('excon.error.request') &&
88
- !err.message.include?('excon.error.response')
89
- expect(truth).to be true
90
- end
91
- end
92
- end
93
-
94
- context 'when :debug_request and :debug_response are switched on' do
95
- it 'exception message includes request and response info' do
96
- begin
97
- Excon.get('http://127.0.0.1:9292/error/not_found', expects: 200,
98
- debug_request: true, debug_response: true)
99
- rescue Excon::Errors::HTTPStatusError => err
100
- truth =
101
- err.message.include?('Expected(200) <=> Actual(404 Not Found)') &&
102
- err.message.include?('excon.error.request') &&
103
- err.message.include?('excon.error.response')
104
- expect(truth).to be true
105
- end
106
- end
107
- end
108
-
109
- context 'when only :debug_request is turned on' do
110
- it('exception message includes only request info') do
111
- begin
112
- Excon.get('http://127.0.0.1:9292/error/not_found', expects: 200,
113
- debug_request: true)
114
- rescue Excon::Errors::HTTPStatusError => err
115
- truth =
116
- err.message.include?('Expected(200) <=> Actual(404 Not Found)') &&
117
- err.message.include?('excon.error.request') &&
118
- !err.message.include?('excon.error.response')
119
- expect(truth).to be true
120
- end
121
- end
122
- end
123
-
124
- context 'when only :debug_response is turned on ' do
125
- it('exception message includes only response info') do
126
- begin
127
- Excon.get('http://127.0.0.1:9292/error/not_found', expects: 200,
128
- debug_response: true)
129
- rescue Excon::Errors::HTTPStatusError => err
130
- truth =
131
- err.message.include?('Expected(200) <=> Actual(404 Not Found)') &&
132
- !err.message.include?('excon.error.request') &&
133
- err.message.include?('excon.error.response')
134
- expect(truth).to be true
135
- end
136
- end
137
- end
138
- end
139
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Excon::Test::Server do
4
-
5
- context 'when the web server is webrick' do
6
- it_should_behave_like "a excon test server", :webrick, 'basic.ru'
7
- end
8
-
9
-
10
- context 'when the web server is unicorn' do
11
- context 'bound to a tcp socket' do
12
- it_should_behave_like "a excon test server", :unicorn, 'streaming.ru'
13
- end
14
-
15
- context "bound to a unix socket" do
16
- socket_uri = 'unix:///tmp/unicorn.socket'
17
- it_should_behave_like "a excon test server", :unicorn, 'streaming.ru', socket_uri
18
- end
19
- end
20
-
21
- context 'when the web server is puma' do
22
- it_should_behave_like "a excon test server", :puma, 'streaming.ru'
23
- end
24
-
25
- context 'when the web server is a executable' do
26
- it_should_behave_like "a excon test server", :exec, 'good_ipv4.rb'
27
- end
28
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Excon do
4
- it 'has a version number' do
5
- expect(Excon::VERSION).not_to be nil
6
- end
7
- end
@@ -1,22 +0,0 @@
1
- # Todo: s/tests/specs when migration is complete
2
- def get_abs_path(*parts)
3
- File.join(File.expand_path('../../..', __FILE__), 'tests', *parts)
4
- end
5
-
6
- def data_path(*parts)
7
- get_abs_path('data', *parts)
8
- end
9
-
10
- def rackup_path(*parts)
11
- get_abs_path('rackups', *parts)
12
- end
13
-
14
- def webrick_path(*parts) rackup_path(*parts); end
15
-
16
- def unicorn_path(*parts) rackup_path(*parts); end
17
-
18
- def puma_path(*parts) rackup_path(*parts); end
19
-
20
- def exec_path(*parts)
21
- get_abs_path('servers', *parts)
22
- end
@@ -1,9 +0,0 @@
1
- def silence_warnings
2
- orig_verbose = $VERBOSE
3
- $VERBOSE = nil
4
- Excon.set_raise_on_warnings!(false)
5
- yield
6
- ensure
7
- $VERBOSE = orig_verbose
8
- Excon.set_raise_on_warnings!(true)
9
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Excon::Connection do
4
- include_context('test server', :webrick, 'basic.ru', before: :start, after: :stop)
5
- context 'when an explicit uri is passed' do
6
- let(:conn) do
7
- Excon::Connection.new(host: '127.0.0.1',
8
- hostname: '127.0.0.1',
9
- nonblock: false,
10
- port: 9292,
11
- scheme: 'http',
12
- ssl_verify_peer: false)
13
- end
14
-
15
- describe '.new' do
16
- it 'returns an instance' do
17
- expect(conn).to be_instance_of Excon::Connection
18
- end
19
- end
20
-
21
- context "when :method is :get and :path is /content-length/100" do
22
- describe "#request" do
23
- let(:response) do
24
- response = conn.request(method: :get, path: '/content-length/100')
25
- end
26
- it 'returns an Excon::Response' do
27
- expect(response).to be_instance_of Excon::Response
28
- end
29
- describe Excon::Response do
30
- describe '#status' do
31
- it 'returns 200' do
32
- expect(response.status).to eq 200
33
- end
34
- end
35
- end
36
- end
37
- end
38
- include_examples 'a basic client'
39
- end
40
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Excon do
4
- context "when dispatching requests" do
5
- context('to a server that does not supply response headers') do
6
- include_context("test server", :exec, 'bad.rb', :before => :start, :after => :stop )
7
- before(:all) do
8
- @conn = Excon.new('http://127.0.0.1:9292')
9
- end
10
-
11
- context('when no block is given') do
12
- it 'should rescue from an EOFError and return response' do
13
- body = @conn.request(:method => :get, :path => '/eof/no_content_length_and_no_chunking').body
14
- expect(body).to eq 'hello'
15
- end
16
- end
17
-
18
- context('when a block is given') do
19
- it 'should rescue from EOFError and return response' do
20
- body = ""
21
- response_block = lambda {|chunk, remaining, total| body << chunk }
22
- @conn.request(:method => :get, :path => '/eof/no_content_length_and_no_chunking', :response_block => response_block)
23
- expect(body).to eq 'hello'
24
- end
25
- end
26
- end
27
-
28
- context('to a server that prematurely aborts the request with no response') do
29
- include_context("test server", :exec, 'eof.rb', :before => :start, :after => :stop )
30
-
31
- it 'should raise an EOFError' do
32
- expect { Excon.get('http://127.0.0.1:9292/eof') }.to raise_error(Excon::Errors::SocketError)
33
- end
34
- end
35
- end
36
- end
@@ -1,38 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Excon::Connection do
4
- include_context('stubs')
5
- context "when speaking to a UNIX socket" do
6
- context "Host header handling" do
7
- before do
8
- Excon.stub do |req|
9
- {
10
- body: req[:headers].to_json,
11
- status: 200,
12
- }
13
- end
14
- end
15
- it "sends an empty Host= by default" do
16
- conn = Excon::Connection.new(
17
- scheme: "unix",
18
- socket: "/tmp/x.sock",
19
- )
20
-
21
- headers = JSON.parse(conn.get(path: "/path").body)
22
-
23
- expect(headers["Host"]).to eq("")
24
- end
25
-
26
- it "doesn't overwrite an explicit Host header" do
27
- conn = Excon::Connection.new(
28
- scheme: "unix",
29
- socket: "/tmp/x.sock",
30
- )
31
-
32
- headers = JSON.parse(conn.get(path: "/path", headers: { "Host" => "localhost" }).body)
33
-
34
- expect(headers["Host"]).to eq("localhost")
35
- end
36
- end
37
- end
38
- end
@@ -1,80 +0,0 @@
1
- describe Excon::Connection do
2
- include_context('stubs')
3
- describe 'validating parameters' do
4
- class FooMiddleware < Excon::Middleware::Base
5
- def self.valid_parameter_keys
6
- [:foo]
7
- end
8
- end
9
-
10
- let(:foo_stack) do
11
- Excon.defaults[:middlewares] + [FooMiddleware]
12
- end
13
-
14
- def expect_parameter_warning(validation, key)
15
- expect { yield }.to raise_error(Excon::Error::Warning, "Invalid Excon #{validation} keys: #{key.inspect}")
16
- end
17
-
18
- context 'with default middleware' do
19
- it 'Connection.new warns on invalid parameter keys' do
20
- expect_parameter_warning('connection', :foo) do
21
- Excon.new('http://foo', :foo => :bar)
22
- end
23
- end
24
-
25
- it 'Connection#request warns on invalid parameter keys' do
26
- conn = Excon.new('http://foo')
27
- expect_parameter_warning('request', :foo) do
28
- conn.request(:foo => :bar)
29
- end
30
- end
31
- end
32
-
33
- context 'with custom middleware at instantiation' do
34
- it 'Connection.new accepts parameters that are valid for the provided middleware' do
35
- Excon.new('http://foo', :foo => :bar, :middlewares => foo_stack)
36
- end
37
-
38
- it 'Connection.new warns on parameters that are not valid for the provided middleware' do
39
- expect_parameter_warning('connection', :bar) do
40
- Excon.new('http://foo', :bar => :baz, :middlewares => foo_stack)
41
- end
42
- end
43
-
44
- it 'Connection#request accepts parameters that are valid for the provided middleware' do
45
- Excon.stub({}, {})
46
- conn = Excon.new('http://foo', :middlewares => foo_stack)
47
- conn.request(:foo => :bar)
48
- end
49
-
50
- it 'Connection#request warns on parameters that are not valid for the provided middleware' do
51
- conn = Excon.new('http://foo', :middlewares => foo_stack)
52
- expect_parameter_warning('request', :bar) do
53
- conn.request(:bar => :baz)
54
- end
55
- end
56
- end
57
-
58
- context 'with custom middleware at request time' do
59
- it 'Connection#request accepts parameters that are valid for the provided middleware' do
60
- Excon.stub({}, {})
61
- conn = Excon.new('http://foo')
62
- conn.request(:foo => :bar, :middlewares => foo_stack)
63
- end
64
-
65
- it 'Connection#request warns on parameters that are not valid for the request middleware' do
66
- conn = Excon.new('http://foo')
67
- expect_parameter_warning('request', :bar) do
68
- conn.request(:bar => :baz, :middlewares => foo_stack)
69
- end
70
- end
71
-
72
- it 'Connection#request warns on parameters from instantiation that are not valid for the request middleware' do
73
- conn = Excon.new('http://foo', :foo => :bar, :middlewares => foo_stack)
74
- expect_parameter_warning('connection', :foo) do
75
- conn.request(:middlewares => Excon.defaults[:middlewares])
76
- end
77
- end
78
- end
79
- end
80
- end
@@ -1,26 +0,0 @@
1
- require 'excon'
2
- require 'excon/test/server'
3
- require 'json'
4
-
5
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
6
- RSpec.configure do |config|
7
- config.expect_with :rspec do |expectations|
8
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
- end
10
-
11
- config.mock_with :rspec do |mocks|
12
- mocks.verify_partial_doubles = true
13
- end
14
-
15
- if config.files_to_run.one?
16
- config.default_formatter = 'doc'
17
- end
18
-
19
- Excon.set_raise_on_warnings!(true)
20
- end
21
-
22
- # Load helpers
23
- Dir["./spec/helpers/**/*.rb"].sort.each { |f| require f}
24
-
25
- # Load shared examples and contexts
26
- Dir["./spec/support/**/*.rb"].sort.each { |f| require f}
@@ -1,83 +0,0 @@
1
- # TODO: Clean up this doc and dry up the conditionals
2
- #
3
- # Required params:
4
- # plugin (e.g., webrick, unicorn, etc)
5
- # file (e.g. a rackup )
6
- #
7
- # Optional params:
8
- # optional paramters may given as a hash
9
- # opts may contain a bind argument
10
- # opts may also contain before and after options
11
- #
12
- # In its simplest form:
13
- # { :before => :start, :after => :stop }
14
- #
15
- # With lambdas, which recieve @server as an argument
16
- # { before: lambda {|s| s.start }, after: lambda { |s| s.stop} }
17
- #
18
- # In both the cases above, before defaults to before(:all)
19
- # This can be circumvented with a Hash
20
- # { before: { :context => :start }, after: { :context => :stop } }
21
- # or
22
- # { before: { context: lambda { |s| s.start } }, after: { context: lambda { |s| s.stop } } }
23
-
24
- shared_context "test server" do |plugin, file, opts = {}|
25
- plugin = plugin.to_sym unless plugin.is_a? Symbol
26
- if plugin == :unicorn && RUBY_PLATFORM == "java"
27
- before { skip("until unicorn supports jruby") }
28
- end
29
- abs_file = Object.send("#{plugin}_path", file)
30
- args = { plugin => abs_file}
31
- args[:bind] = opts[:bind] if opts.key? :bind
32
-
33
-
34
- before_hook = opts.key?(:before) && (opts[:before].is_a?(Symbol) || opts[:before].is_a?(Proc) || opts[:before].is_a?(Hash))
35
-
36
- if before_hook && opts[:before].is_a?(Hash)
37
- event = opts[:before].keys.first
38
- before(event) {
39
- @server = Excon::Test::Server.new(args)
40
- if opts[:before][event].is_a? Symbol
41
- @server.send(opts[:before][event])
42
- else
43
- opts[:before][event].call(@server)
44
- end
45
- }
46
- elsif
47
- before(:all) {
48
- @server = Excon::Test::Server.new(args)
49
- before_hook = opts.key?(:before) && (opts[:before].is_a?(Symbol) || opts[:before].is_a?(Proc) || opts[:before].is_a?(Hash))
50
-
51
- if before_hook
52
- if opts[:before].is_a? Symbol
53
- @server.send(opts[:before])
54
- else
55
- opts[:before].call(@server)
56
- end
57
- end
58
- }
59
- end
60
-
61
- after_hook = opts.key?(:after) && (opts[:after].is_a?(Symbol) || opts[:after].is_a?(Proc) || opts[:after].is_a?(Hash))
62
-
63
- if after_hook && opts[:after].is_a?(Hash)
64
- event = opts[:after].keys.first
65
- after(event) {
66
- if opts[:after][event].is_a? Symbol
67
- @server.send(opts[:after][event])
68
- else
69
- opts[:after][event].call(@server)
70
- end
71
- }
72
- elsif after_hook
73
- after(:all) {
74
- if opts[:after].is_a? Symbol
75
- @server.send(opts[:after])
76
- elsif opts[:after].is_a? Hash
77
-
78
- else
79
- opts[:after].call(@server)
80
- end
81
- }
82
- end
83
- end