excon 0.93.1 → 0.94.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3211fd54e5e026f3be23a2177c02a8c868e643306724f05cc654b5ec5c5fced
4
- data.tar.gz: 6ad596f7c44528b3a6655c5461d86de5161c8a7e55c1fdecc49d0cca88700921
3
+ metadata.gz: d70a84195cac612e187bcd007f341f4fbac5486f19cfd74b2389a166fa45837a
4
+ data.tar.gz: '05950bcb9e7cc752aeff9dc15201e5abee70636ed75f703fdfc2b28bdd97b68d'
5
5
  SHA512:
6
- metadata.gz: 3813a14810ae26ba1b7331ac3b6b3b8a96de0aa69b476b10bc063cd4f85169ffd44fd3f90182cf62a0795ea8959239fa1c8aa6974b41aec57805cf170b8ee687
7
- data.tar.gz: c4fc25ce76d8c4304ef6f73b44d1a21179ab3b825d3ca2927fff3bc98082416d0acaa9e7dbe310bd9ebefd2513165eb4158c3ca330c11588092ea708e2e35484
6
+ metadata.gz: 83711465351dcf3bd976aef38208b27d4704d2cfb35d67f4be0f0d732cd4ee4e164bfab1c3a0f8ac5f6db6fe14179c7c7a932431392a6fe56c87b3f89814a6e6
7
+ data.tar.gz: d28d63ee0decef91a3ac94d6919a66db17d4dbf64687cfb8ecb4a52a420511e9d97e9e7929f01bb5e6624abf7d6aef874ffce2736ae25cb0e038c5f4f8e577d7
data/lib/excon/socket.rb CHANGED
@@ -40,12 +40,14 @@ module Excon
40
40
 
41
41
  def_delegators(:@socket, :close)
42
42
 
43
+
43
44
  def initialize(data = {})
44
45
  @data = data
45
46
  @nonblock = data[:nonblock]
46
47
  @port ||= @data[:port] || 80
47
48
  @read_buffer = String.new
48
49
  @eof = false
50
+ @backend_eof = false
49
51
  connect
50
52
  end
51
53
 
@@ -61,9 +63,22 @@ module Excon
61
63
 
62
64
  def readline
63
65
  if @nonblock && RUBY_VERSION.to_f > 1.8_7
64
- buffer = String.new
65
- buffer << (read_nonblock(1) || raise(EOFError)) while buffer[-1] != "\n"
66
- buffer
66
+ result = String.new
67
+ block = @read_buffer
68
+ @read_buffer = String.new
69
+
70
+ loop do
71
+ idx = block.index("\n")
72
+ if idx.nil?
73
+ result << block
74
+ else
75
+ add_to_read_buffer(block.slice!(idx+1, block.length))
76
+ result << block
77
+ break
78
+ end
79
+ block = read_nonblock(@data[:chunk_size]) || raise(EOFError)
80
+ end
81
+ result
67
82
  else # nonblock/legacy
68
83
  begin
69
84
  Timeout.timeout(@data[:read_timeout]) do
@@ -172,20 +187,21 @@ module Excon
172
187
  end
173
188
  end
174
189
 
190
+ def add_to_read_buffer(str)
191
+ @read_buffer << str
192
+ @eof = false
193
+ end
194
+
175
195
  def read_nonblock(max_length)
176
196
  begin
177
- if max_length
178
- until @read_buffer.length >= max_length
179
- @read_buffer << @socket.read_nonblock(max_length - @read_buffer.length)
180
- end
181
- else
182
- loop do
183
- @read_buffer << @socket.read_nonblock(@data[:chunk_size])
184
- end
197
+ while !@backend_eof && (!max_length || @read_buffer.length < max_length)
198
+ @read_buffer << @socket.read_nonblock(@data[:chunk_size])
185
199
  end
186
200
  rescue OpenSSL::SSL::SSLError => error
187
201
  if error.message == 'read would block'
188
- select_with_timeout(@socket, :read) && retry
202
+ if @read_buffer.empty?
203
+ select_with_timeout(@socket, :read) && retry
204
+ end
189
205
  else
190
206
  raise(error)
191
207
  end
@@ -195,10 +211,10 @@ module Excon
195
211
  select_with_timeout(@socket, :read) && retry
196
212
  end
197
213
  rescue EOFError
198
- @eof = true
214
+ @backend_eof = true
199
215
  end
200
216
 
201
- if max_length
217
+ ret = if max_length
202
218
  if @read_buffer.empty?
203
219
  nil # EOF met at beginning
204
220
  else
@@ -208,6 +224,8 @@ module Excon
208
224
  # read until EOFError, so return everything
209
225
  @read_buffer.slice!(0, @read_buffer.length)
210
226
  end
227
+ @eof = @backend_eof && @read_buffer.empty?
228
+ ret
211
229
  end
212
230
 
213
231
  def read_block(max_length)
@@ -219,9 +237,7 @@ module Excon
219
237
  raise(error)
220
238
  end
221
239
  rescue *READ_RETRY_EXCEPTION_CLASSES
222
- if @read_buffer.empty?
223
- select_with_timeout(@socket, :read) && retry
224
- end
240
+ select_with_timeout(@socket, :read) && retry
225
241
  rescue EOFError
226
242
  @eof = true
227
243
  end
data/lib/excon/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Excon
3
- VERSION = '0.93.1'
3
+ VERSION = '0.94.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.93.1
4
+ version: 0.94.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dpiddy (Dan Peterson)
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-10-20 00:00:00.000000000 Z
13
+ date: 2022-11-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec