excon 0.62.0 → 0.92.3

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 (125) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +0 -1
  3. data/LICENSE.md +1 -1
  4. data/README.md +7 -6
  5. data/data/cacert.pem +1220 -1828
  6. data/excon.gemspec +19 -3
  7. data/lib/excon/connection.rb +216 -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 +5 -16
  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 +11 -4
  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 +59 -42
  25. data/lib/excon/ssl_socket.rb +37 -15
  26. data/lib/excon/test/plugin/server/exec.rb +5 -2
  27. data/lib/excon/test/plugin/server/puma.rb +4 -1
  28. data/lib/excon/test/plugin/server/unicorn.rb +5 -0
  29. data/lib/excon/test/plugin/server/webrick.rb +4 -1
  30. data/lib/excon/test/server.rb +1 -1
  31. data/lib/excon/unix_socket.rb +1 -0
  32. data/lib/excon/utils.rb +59 -5
  33. data/lib/excon/version.rb +1 -1
  34. data/lib/excon.rb +25 -17
  35. metadata +27 -98
  36. data/.document +0 -5
  37. data/.gitignore +0 -13
  38. data/.rspec +0 -3
  39. data/.travis.yml +0 -29
  40. data/Gemfile +0 -19
  41. data/Rakefile +0 -41
  42. data/benchmarks/class_vs_lambda.rb +0 -50
  43. data/benchmarks/concat_vs_insert.rb +0 -21
  44. data/benchmarks/concat_vs_interpolate.rb +0 -22
  45. data/benchmarks/cr_lf.rb +0 -21
  46. data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
  47. data/benchmarks/excon.rb +0 -69
  48. data/benchmarks/excon_vs.rb +0 -165
  49. data/benchmarks/for_vs_array_each.rb +0 -27
  50. data/benchmarks/for_vs_hash_each.rb +0 -27
  51. data/benchmarks/has_key-vs-lookup.rb +0 -177
  52. data/benchmarks/headers_case_sensitivity.rb +0 -83
  53. data/benchmarks/headers_split_vs_match.rb +0 -34
  54. data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
  55. data/benchmarks/merging.rb +0 -21
  56. data/benchmarks/single_vs_double_quotes.rb +0 -21
  57. data/benchmarks/string_ranged_index.rb +0 -87
  58. data/benchmarks/strip_newline.rb +0 -115
  59. data/benchmarks/vs_stdlib.rb +0 -82
  60. data/changelog.txt +0 -1083
  61. data/spec/excon/error_spec.rb +0 -139
  62. data/spec/excon/test/server_spec.rb +0 -28
  63. data/spec/excon_spec.rb +0 -7
  64. data/spec/helpers/file_path_helpers.rb +0 -22
  65. data/spec/requests/basic_spec.rb +0 -40
  66. data/spec/requests/eof_requests_spec.rb +0 -36
  67. data/spec/requests/unix_socket_spec.rb +0 -46
  68. data/spec/spec_helper.rb +0 -24
  69. data/spec/support/shared_contexts/test_server_context.rb +0 -83
  70. data/spec/support/shared_examples/shared_example_for_clients.rb +0 -218
  71. data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
  72. data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
  73. data/tests/authorization_header_tests.rb +0 -29
  74. data/tests/bad_tests.rb +0 -47
  75. data/tests/basic_tests.rb +0 -351
  76. data/tests/batch_requests.rb +0 -133
  77. data/tests/complete_responses.rb +0 -31
  78. data/tests/data/127.0.0.1.cert.crt +0 -20
  79. data/tests/data/127.0.0.1.cert.key +0 -27
  80. data/tests/data/excon.cert.crt +0 -20
  81. data/tests/data/excon.cert.key +0 -27
  82. data/tests/data/xs +0 -1
  83. data/tests/error_tests.rb +0 -145
  84. data/tests/header_tests.rb +0 -119
  85. data/tests/middlewares/canned_response_tests.rb +0 -34
  86. data/tests/middlewares/capture_cookies_tests.rb +0 -34
  87. data/tests/middlewares/decompress_tests.rb +0 -157
  88. data/tests/middlewares/escape_path_tests.rb +0 -36
  89. data/tests/middlewares/idempotent_tests.rb +0 -206
  90. data/tests/middlewares/instrumentation_tests.rb +0 -315
  91. data/tests/middlewares/mock_tests.rb +0 -304
  92. data/tests/middlewares/redirect_follower_tests.rb +0 -112
  93. data/tests/pipeline_tests.rb +0 -40
  94. data/tests/proxy_tests.rb +0 -306
  95. data/tests/query_string_tests.rb +0 -87
  96. data/tests/rackups/basic.rb +0 -41
  97. data/tests/rackups/basic.ru +0 -3
  98. data/tests/rackups/basic_auth.ru +0 -14
  99. data/tests/rackups/deflater.ru +0 -4
  100. data/tests/rackups/proxy.ru +0 -18
  101. data/tests/rackups/query_string.ru +0 -13
  102. data/tests/rackups/redirecting.ru +0 -23
  103. data/tests/rackups/redirecting_with_cookie.ru +0 -40
  104. data/tests/rackups/request_headers.ru +0 -15
  105. data/tests/rackups/request_methods.ru +0 -21
  106. data/tests/rackups/response_header.ru +0 -18
  107. data/tests/rackups/ssl.ru +0 -16
  108. data/tests/rackups/ssl_mismatched_cn.ru +0 -15
  109. data/tests/rackups/ssl_verify_peer.ru +0 -16
  110. data/tests/rackups/streaming.ru +0 -30
  111. data/tests/rackups/thread_safety.ru +0 -17
  112. data/tests/rackups/timeout.ru +0 -14
  113. data/tests/rackups/webrick_patch.rb +0 -34
  114. data/tests/request_headers_tests.rb +0 -21
  115. data/tests/request_method_tests.rb +0 -47
  116. data/tests/request_tests.rb +0 -59
  117. data/tests/response_tests.rb +0 -197
  118. data/tests/servers/bad.rb +0 -20
  119. data/tests/servers/eof.rb +0 -17
  120. data/tests/servers/error.rb +0 -20
  121. data/tests/servers/good.rb +0 -350
  122. data/tests/test_helper.rb +0 -306
  123. data/tests/thread_safety_tests.rb +0 -39
  124. data/tests/timeout_tests.rb +0 -12
  125. 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.rb'
27
- end
28
- end
data/spec/excon_spec.rb DELETED
@@ -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,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,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Excon::Connection do
4
- context "when speaking to a UNIX socket" do
5
- context "Host header handling" do
6
- before do
7
- responder = ->(req) do
8
- {
9
- body: req[:headers].to_json,
10
- status: 200,
11
- }
12
- end
13
-
14
- @original_mock = Excon.defaults[:mock]
15
- Excon.defaults[:mock] = true
16
- Excon.stub({}, responder)
17
- end
18
-
19
- after do
20
- Excon.defaults[:mock] = @original_mock
21
- end
22
-
23
- it "sends an empty Host= by default" do
24
- conn = Excon::Connection.new(
25
- scheme: "unix",
26
- socket: "/tmp/x.sock",
27
- )
28
-
29
- headers = JSON.parse(conn.get(path: "/path").body)
30
-
31
- expect(headers["Host"]).to eq("")
32
- end
33
-
34
- it "doesn't overwrite an explicit Host header" do
35
- conn = Excon::Connection.new(
36
- scheme: "unix",
37
- socket: "/tmp/x.sock",
38
- )
39
-
40
- headers = JSON.parse(conn.get(path: "/path", headers: { "Host" => "localhost" }).body)
41
-
42
- expect(headers["Host"]).to eq("localhost")
43
- end
44
- end
45
- end
46
- end
data/spec/spec_helper.rb DELETED
@@ -1,24 +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
- end
19
-
20
- # Load helpers
21
- Dir["./spec/helpers/**/*.rb"].sort.each { |f| require f}
22
-
23
- # Load shared examples and contexts
24
- 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
@@ -1,218 +0,0 @@
1
- require 'time'
2
-
3
- shared_examples_for 'a basic client' do |url = 'http://127.0.0.1:9292', opts = {}|
4
- # TODO: Ditch iterator and manually write a context for each set of options
5
- ([true, false] * 2).combination(2).to_a.uniq.each do |nonblock, persistent|
6
- context "when nonblock is #{nonblock} and persistent is #{persistent}" do
7
- opts = opts.merge(ssl_verify_peer: false, nonblock: nonblock, persistent: persistent)
8
-
9
- let(:conn) { Excon.new(url, opts) }
10
-
11
- context 'when :method is get and :path is /content-length/100' do
12
- describe '#request' do
13
- let(:response) do
14
- conn.request(method: :get, path: '/content-length/100')
15
- end
16
-
17
- it 'returns an Excon::Response' do
18
- expect(response).to be_instance_of Excon::Response
19
- end
20
- describe Excon::Response do
21
- describe '#status' do
22
- it 'returns 200' do
23
- expect(response.status).to eq 200
24
- end
25
-
26
- it '#status returns 200' do
27
- expect(response[:status]).to eq 200
28
- end
29
- end
30
- describe '#headers' do
31
- it '["Content-Length"] returns 100' do
32
- expect(response.headers['Content-Length']).to eq '100'
33
- end
34
- it '["Content-Type"] returns "text/html;charset=utf-8"' do
35
- expect(response.headers['Content-Type']).to eq 'text/html;charset=utf-8'
36
- end
37
-
38
- it "['Date'] returns a valid date" do
39
- if RUBY_PLATFORM == 'java' && conn.data[:scheme] == Excon::UNIX
40
- skip('until puma responds with a date header')
41
- else
42
- time = Time.parse(response.headers['Date'])
43
- expect(time.is_a?(Time)).to be true
44
- end
45
- end
46
-
47
- it "['Server'] matches /^WEBrick/" do
48
- pending('until unix_socket response has server header') if conn.data[:scheme] == Excon::UNIX
49
- expect(!!(response.headers['Server'] =~ /^WEBrick/)).to be true
50
- end
51
-
52
- it "['Custom'] returns Foo: bar" do
53
- expect(response.headers['Custom']).to eq 'Foo: bar'
54
- end
55
- end
56
- describe '#remote_ip' do
57
- it 'returns 127.0.0.1' do
58
- pending('until pigs can fly') if conn.data[:scheme] == Excon::UNIX
59
- expect(response.remote_ip).to eq '127.0.0.1'
60
- end
61
- end
62
- end
63
-
64
- context('when tcp_nodelay is true') do
65
- describe '#request' do
66
- response = nil
67
- options = opts.merge(ssl_verify_peer: false, nonblock: nonblock, tcp_nodelay: true)
68
- connection = Excon.new(url, options)
69
-
70
- it 'returns an Excon::Response' do
71
- expect do
72
- response = connection.request(method: :get, path: '/content-length/100')
73
- end.to_not raise_error
74
- end
75
-
76
- describe Excon::Response do
77
- describe '#body' do
78
- describe '.status' do
79
- it '#returns 200' do
80
- expect(response.status).to eq 200
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
88
-
89
- context 'when utilizing deprecated block usage' do
90
- describe '#request' do
91
- data = []
92
- it 'yields with a chunk, remaining length, and total length' do
93
- expect do
94
- conn.request(method: :get, path: '/content-length/100') do |chunk, remaining_length, total_length|
95
- data = [chunk, remaining_length, total_length]
96
- end
97
- end.to_not raise_error
98
- end
99
- it 'completes with expected data' do
100
- expect(data).to eq ['x' * 100, 0, 100]
101
- end
102
- end
103
- end
104
-
105
- context 'when utilizing response_block usage' do
106
- describe '#request' do
107
- data = []
108
- it 'yields a chunk, remaining length, and total_length' do
109
- response_block = lambda do |chunk, remaining_length, total_length|
110
- data = [chunk, remaining_length, total_length]
111
- end
112
- expect do
113
- conn.request(method: :get, path: '/content-length/100', response_block: response_block)
114
- end.to_not raise_error
115
- end
116
- it 'completes with expected data' do
117
- expect(data).to eq ['x' * 100, 0, 100]
118
- end
119
- end
120
- end
121
- context 'when method is :post' do
122
- context 'when :path is /body-sink' do
123
- context 'when a body parameter is supplied' do
124
- response = nil
125
- it 'returns an Excon::Response' do
126
- response = conn.request(method: :post, path: '/body-sink', headers: { 'Content-Type' => 'text/plain' }, body: 'x' * 5_000_000)
127
- expect(response).to be_instance_of Excon::Response
128
- end
129
- describe Excon::Response do
130
- describe '#body' do
131
- it 'equals "5000000"' do
132
- expect(response.body).to eq '5000000'
133
- end
134
- end
135
- end
136
- end
137
- context 'when the body parameter is an empty string' do
138
- response = nil
139
-
140
- it 'returns an Excon::Response' do
141
- response = conn.request(method: :post, path: '/body-sink', headers: { 'Content-Type' => 'text/plain' }, body: '')
142
- expect(response).to be_instance_of Excon::Response
143
- end
144
- describe Excon::Response do
145
- describe '#body' do
146
- it 'equals "0"' do
147
- expect(response.body).to eq '0'
148
- end
149
- end
150
- end
151
- end
152
- end
153
-
154
- context 'when :path is /echo' do
155
- context('when a file handle is the body paramter') do
156
- describe Excon::Response do
157
- it '#body equals "x" * 100 + "\n"' do
158
- file_path = data_path('xs')
159
- response = conn.request(method: :post, path: '/echo', body: File.open(file_path))
160
- expect(response.body).to eq 'x' * 100 + "\n"
161
- end
162
- end
163
- end
164
-
165
- context 'when a string is the body paramter' do
166
- it 'does not change the econding of the body' do
167
- skip unless RUBY_VERSION >= '1.9'
168
-
169
- string_body = '¥£€'
170
- expect do
171
- conn.request(method: :post, path: '/echo', body: string_body)
172
- end.to_not change { string_body.encoding }
173
- end
174
-
175
- context 'without request_block' do
176
- describe Excon::Response do
177
- it "#body equals 'x' * 100)" do
178
- response = conn.request(method: :post, path: '/echo', body: 'x' * 100)
179
- expect(response.body).to eq 'x' * 100
180
- end
181
- end
182
- end
183
-
184
- context 'when a request_block paramter is supplied' do
185
- describe Excon::Response do
186
- it "#body equals'x' * 100" do
187
- data = ['x'] * 100
188
- request_block = lambda do
189
- data.shift.to_s
190
- end
191
- response = conn.request(method: :post, path: '/echo', request_block: request_block)
192
- expect(response.body).to eq 'x' * 100
193
- end
194
- end
195
- end
196
-
197
- context('when a multi-byte string is the body paramter') do
198
- body = "\xC3\xBC" * 100
199
- headers = { 'Custom' => body.dup }
200
- if RUBY_VERSION >= '1.9'
201
- body.force_encoding('BINARY')
202
- headers['Custom'].force_encoding('UTF-8')
203
- end
204
- describe Excon::Response do
205
- it '#body properly concatenates request+headers and body' do
206
- response = conn.request(method: :post, path: '/echo',
207
- headers: headers, body: body)
208
- expect(response.body).to eq body
209
- end
210
- end
211
- end
212
- end
213
- end
214
- end
215
- end
216
- end
217
- end
218
- end
@@ -1,20 +0,0 @@
1
- shared_examples_for 'a streaming client' do |endpoint, timeout|
2
- ret = []
3
- timing = 'response times ok'
4
- start = Time.now
5
- block = lambda do |c,r,t|
6
- # add the response
7
- ret.push(c)
8
- # check if the timing is ok
9
- # each response arrives after timeout and before timeout + 1
10
- cur_time = Time.now - start
11
- if cur_time < ret.length * timeout or cur_time > (ret.length+1) * timeout
12
- timing = 'response time not ok!'
13
- end
14
- end
15
- it "gets a response in less than or equal to #{(timeout*3).round(2)} seconds" do
16
- Excon.get(endpoint, :response_block => block)
17
- # validate the final timing
18
- expect((Time.now - start <= timeout*3) == true && timing == 'response times not ok!').to be false
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- shared_examples_for "a excon test server" do |plugin, file|
2
-
3
- include_context("test server", plugin, file)
4
-
5
- it "returns an instance" do
6
- expect(@server).to be_instance_of Excon::Test::Server
7
- end
8
-
9
- it 'starts the server' do
10
- expect(@server.start).to be true
11
- end
12
-
13
- it 'stops the server' do
14
- expect(@server.stop).to be true
15
- end
16
- end