excon 0.35.0 → 0.36.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.

checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjBhZDU0MzQxYTIxMjM5OGMzNWEzOTA0YjBlNWU5OTUyNTQ2MmQ5Ng==
4
+ NDU5NjFhMTVjODUyOTk3NWI0NzRmNjI4YTlkY2U4ZGU4M2JlZDNlNQ==
5
5
  data.tar.gz: !binary |-
6
- NTAzN2ZjNGRhZjMxMWM3NjAxNzMzYjk2ZGZmNzdmMjUwNWY3ZmNmYg==
6
+ M2ExNjg1NjdjZDFjMGMxNmMwNzQwM2NmOWEwMTBmN2U4ZWUxY2NjZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWYxYzdmZTU1YzY0ZTk5MjZhMDQ4OTVhNmVmMzZmYmYyNTc0YWFjOGFjNmRj
10
- NDM2ZjllM2MzZmVjYmZmYjdmMGQzOWJkMGVmYTlmNDM0ZGY3OWQ4NTU2NmEz
11
- MmU3NTczMWU1ZWExMGQ1ZWJkODYyNTU5YWFkMTc4OWJhZTg3ODc=
9
+ YWViOTA0NjQ1N2E5ZWY0ZTlmNGJiZTE0ZmUzMTg2YmFhOTQ0NDBhYTRlMWVk
10
+ MzM2OWI2YzE3MjQzMzA2ZTY3ZWUxYWUzMzI2ZGJlYWRkNjMyODYzODhhYTBj
11
+ M2Q1NDZjYzA2N2UwYmY3YmM4YzU3NzI0M2YxYjY4YzZiNzU4ZTc=
12
12
  data.tar.gz: !binary |-
13
- ODFkZWNlNTY3Nzk3MWQxYWY4OTQ3ZmMwZTllMDBmZjBjYjUxZTcxYzlkNGUy
14
- ZWVmZTQ2MTlmOGYxNDU0NTYyMGZkOWQ5YTU3NmQwNWI5MjZiMmU0YzVkMDU3
15
- YzY4Y2MwMGNjZmMxNzA1OWFhNTQ1Y2YyNWY5ZGEyMzcxNzI1NTU=
13
+ MTM2ZTExOTYxMzFlZjlkY2E3M2Q3YjVjMDRkOGQzOTc3NTUxMGVlYzMwMzAy
14
+ NWU0OTFjZWM4NDRmZjEzYTIzY2M1ZjJhYmRkYmY3MzhiNTllMDlkYWJiYWRk
15
+ NjM1M2YwNmU2OTU5MDVhMjQxMTQwMTFkYTY1ZDllN2VkMTY1ZTE=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- excon (0.35.0)
4
+ excon (0.36.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,4 +1,9 @@
1
- 0.34.0 06/03/2014
1
+ 0.36.0 06/04/2014
2
+ =================
3
+
4
+ fix to reconcile streaming changes for chunked encoding
5
+
6
+ 0.35.0 06/03/2014
2
7
  =================
3
8
 
4
9
  fix for responses with content_length
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'excon'
16
- s.version = '0.35.0'
17
- s.date = '2014-06-03'
16
+ s.version = '0.36.0'
17
+ s.date = '2014-06-04'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
 
3
- VERSION = '0.35.0'
3
+ VERSION = '0.36.0'
4
4
 
5
5
  CR_NL = "\r\n"
6
6
 
@@ -76,14 +76,23 @@ module Excon
76
76
  end
77
77
 
78
78
  if transfer_encoding_chunked
79
- # 2 == "\r\n".length
80
79
  if response_block
81
80
  while (chunk_size = socket.readline.chop!.to_i(16)) > 0
82
- response_block.call(socket.read(chunk_size + 2).chop!, nil, nil)
81
+ chunk_size += 2 # 2 == "\r\n".length
82
+ while chunk_size > 0
83
+ chunk = socket.read(chunk_size)
84
+ chunk_size -= chunk.length
85
+ response_block.call(chunk.chop!, nil, nil)
86
+ end
83
87
  end
84
88
  else
85
89
  while (chunk_size = socket.readline.chop!.to_i(16)) > 0
86
- datum[:response][:body] << socket.read(chunk_size + 2).chop!
90
+ chunk_size += 2 # 2 == "\r\n".length
91
+ while chunk_size > 0
92
+ chunk = socket.read(chunk_size)
93
+ chunk_size -= chunk.length
94
+ datum[:response][:body] << chunk.chop!
95
+ end
87
96
  end
88
97
  end
89
98
  parse_headers(socket, datum) # merge trailers into headers
@@ -38,21 +38,34 @@ Shindo.tests('Excon streaming basics') do
38
38
  end
39
39
  end
40
40
 
41
+ # expect the full response as a string and expect it to
42
+ # take a (timeout * pieces) seconds (with fixed Content-Length header)
43
+ tests('simple blocking request on streaming endpoint with fixed length').returns([res.join(''),'response time ok']) do
44
+ start = Time.now
45
+ ret = Excon.get('http://127.0.0.1:9292/streamed/fixed_length').body
46
+
47
+ if Time.now - start <= timeout*3
48
+ [ret, 'streaming response came too quickly']
49
+ else
50
+ [ret, 'response time ok']
51
+ end
52
+ end
53
+
41
54
  # expect each response piece to arrive to the body right away
42
55
  # and wait for timeout until next one arrives
43
- tests('simple request with response_block on streaming endpoint').returns([res,'response times ok']) do
56
+ def timed_streaming_test(endpoint, timeout)
44
57
  ret = []
45
58
  timing = 'response times ok'
46
59
  start = Time.now
47
- Excon.get('http://127.0.0.1:9292/streamed/simple', :response_block => lambda do |c,r,t|
60
+ Excon.get(endpoint, :response_block => lambda do |c,r,t|
61
+ # add the response
62
+ ret.push(c)
48
63
  # check if the timing is ok
49
64
  # each response arrives after timeout and before timeout + 1
50
65
  cur_time = Time.now - start
51
66
  if cur_time < ret.length * timeout or cur_time > (ret.length+1) * timeout
52
67
  timing = 'response time not ok!'
53
68
  end
54
- # add the response
55
- ret.push(c)
56
69
  end)
57
70
  # validate the final timing
58
71
  if Time.now - start <= timeout*3
@@ -60,6 +73,15 @@ Shindo.tests('Excon streaming basics') do
60
73
  end
61
74
  [ret, timing]
62
75
  end
76
+
77
+ tests('simple request with response_block on streaming endpoint').returns([res,'response times ok']) do
78
+ timed_streaming_test('http://127.0.0.1:9292/streamed/simple', timeout)
79
+ end
80
+
81
+ tests('simple request with response_block on streaming endpoint with fixed length').returns([res,'response times ok']) do
82
+ timed_streaming_test('http://127.0.0.1:9292/streamed/fixed_length', timeout)
83
+ end
84
+
63
85
  end
64
86
  end
65
87
 
@@ -1,14 +1,24 @@
1
1
  use Rack::ContentType, "text/plain"
2
2
 
3
3
  app = lambda do |env|
4
+ # streamed pieces to be sent
5
+ pieces = %w{Hello streamy world}
6
+
4
7
  response_headers = {}
8
+
9
+ # set a fixed content length in the header if requested
10
+ if env['REQUEST_PATH'] == '/streamed/fixed_length'
11
+ response_headers['Content-Length'] = pieces.join.length.to_s
12
+ end
13
+
5
14
  response_headers["rack.hijack"] = lambda do |io|
6
15
  # Write directly to IO of the response
7
16
  begin
8
- ['Hello','streamy','world'].each do |x|
17
+ # return the response in pieces
18
+ pieces.each do |x|
19
+ sleep 1
9
20
  io.write(x)
10
21
  io.flush
11
- sleep 1
12
22
  end
13
23
  ensure
14
24
  io.close
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.35.0
4
+ version: 0.36.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: 2014-06-03 00:00:00.000000000 Z
13
+ date: 2014-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport