excon 0.6.2 → 0.6.3

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.

@@ -0,0 +1,69 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9'
2
+ require 'bundler'
3
+
4
+ Bundler.require(:default)
5
+ Bundler.require(:benchmark)
6
+
7
+ require 'sinatra/base'
8
+
9
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon')
10
+
11
+ module Excon
12
+ class Server < Sinatra::Base
13
+
14
+ def self.run
15
+ Rack::Handler::WEBrick.run(
16
+ Excon::Server.new,
17
+ :Port => 9292,
18
+ :AccessLog => [],
19
+ :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR)
20
+ )
21
+ end
22
+
23
+ get '/data/:amount' do |amount|
24
+ 'x' * amount.to_i
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ def with_server(&block)
31
+ pid = Process.fork do
32
+ Excon::Server.run
33
+ end
34
+ loop do
35
+ sleep(1)
36
+ begin
37
+ Excon.get('http://localhost:9292/api/foo')
38
+ break
39
+ rescue
40
+ end
41
+ end
42
+ yield
43
+ ensure
44
+ Process.kill(9, pid)
45
+ end
46
+
47
+ require 'tach'
48
+
49
+ size = 10_000
50
+ path = '/data/' << size.to_s
51
+ url = 'http://localhost:9292' << path
52
+
53
+ times = 1_000
54
+
55
+ with_server do
56
+
57
+ Tach.meter(times) do
58
+
59
+ tach('Excon') do
60
+ Excon.get(url).body
61
+ end
62
+
63
+ excon = Excon.new(url)
64
+ tach('Excon (persistent)') do
65
+ excon.request(:method => 'get').body
66
+ end
67
+
68
+ end
69
+ end
@@ -1,29 +1,3 @@
1
- # require 'benchmark'
2
-
3
- # COUNT = 1_000_000
4
- # data = "Content-Length: 100"
5
- # Benchmark.bmbm(25) do |bench|
6
- # bench.report('regex') do
7
- # COUNT.times do
8
- # header = data.match(/(.*):\s(.*)/)
9
- # end
10
- # end
11
- # bench.report('split') do
12
- # COUNT.times do
13
- # header = data.split(': ')
14
- # end
15
- # end
16
- # end
17
-
18
- # Rehearsal ------------------------------------------------------------
19
- # regex 4.270000 0.010000 4.280000 ( 4.294186)
20
- # split 3.870000 0.000000 3.870000 ( 3.885645)
21
- # --------------------------------------------------- total: 8.150000sec
22
- #
23
- # user system total real
24
- # regex 4.260000 0.010000 4.270000 ( 4.284764)
25
- # split 3.860000 0.010000 3.870000 ( 3.882795)
26
-
27
1
  require 'rubygems'
28
2
  require 'tach'
29
3
 
@@ -34,10 +8,23 @@ Tach.meter(1_000_000) do
34
8
  header = [$1, $2]
35
9
  end
36
10
  tach('split') do
37
- header = data.split(': ')
11
+ header = data.split(': ', 2)
12
+ end
13
+ tach('split regex') do
14
+ header = data.split(/:\s*/, 2)
38
15
  end
39
16
  end
40
17
 
18
+ # +-------------+----------+
19
+ # | tach | total |
20
+ # +-------------+----------+
21
+ # | split regex | 5.940233 |
22
+ # +-------------+----------+
23
+ # | split | 7.327549 |
24
+ # +-------------+----------+
25
+ # | regex | 8.736390 |
26
+ # +-------------+----------+
27
+
41
28
  # +-------+----------+----------+
42
29
  # | tach | average | total |
43
30
  # +-------+----------+----------+
data/excon.gemspec CHANGED
@@ -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.6.2'
17
- s.date = '2011-04-11'
16
+ s.version = '0.6.3'
17
+ s.date = '2011-05-02'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
71
71
  benchmarks/concat_vs_interpolate.rb
72
72
  benchmarks/cr_lf.rb
73
73
  benchmarks/downcase-eq-eq_vs_casecmp.rb
74
+ benchmarks/excon.rb
74
75
  benchmarks/excon_vs.rb
75
76
  benchmarks/for_vs_array_each.rb
76
77
  benchmarks/for_vs_hash_each.rb
@@ -89,11 +90,13 @@ Gem::Specification.new do |s|
89
90
  lib/excon/errors.rb
90
91
  lib/excon/response.rb
91
92
  tests/basic_tests.rb
93
+ tests/header_tests.rb
92
94
  tests/proxy_tests.rb
93
95
  tests/query_string_tests.rb
94
96
  tests/rackups/basic.ru
95
97
  tests/rackups/proxy.ru
96
98
  tests/rackups/query_string.ru
99
+ tests/rackups/response_header.ru
97
100
  tests/rackups/thread_safety.ru
98
101
  tests/stub_tests.rb
99
102
  tests/test_helper.rb
data/lib/excon.rb CHANGED
@@ -13,7 +13,7 @@ require 'excon/response'
13
13
 
14
14
  module Excon
15
15
  unless const_defined?(:VERSION)
16
- VERSION = '0.6.2'
16
+ VERSION = '0.6.3'
17
17
  end
18
18
 
19
19
  unless const_defined?(:CHUNK_SIZE)
@@ -146,6 +146,7 @@ module Excon
146
146
 
147
147
  # write out the request, sans body
148
148
  socket.write(request)
149
+ socket.flush
149
150
 
150
151
  # write out the body
151
152
  if params[:body]
@@ -185,6 +186,9 @@ module Excon
185
186
  retries_remaining ||= 4
186
187
  retries_remaining -= 1
187
188
  if retries_remaining > 0
189
+ if params[:body].respond_to?(:pos=)
190
+ params[:body].pos = 0
191
+ end
188
192
  retry
189
193
  else
190
194
  raise(request_error)
@@ -254,7 +258,7 @@ module Excon
254
258
  new_socket.post_connection_check(@connection[:host])
255
259
  new_socket
256
260
  end
257
-
261
+
258
262
  def open_socket
259
263
  if @proxy
260
264
  socket = TCPSocket.open(@proxy[:host], @proxy[:port])
@@ -23,7 +23,7 @@ module Excon
23
23
  block_given = block_given?
24
24
 
25
25
  until ((data = socket.readline).chop!).empty?
26
- key, value = data.split(': ', 2)
26
+ key, value = data.split(/:\s*/, 2)
27
27
  response.headers[key] = ([*response.headers[key]] << value).compact.join(', ')
28
28
  if key.casecmp('Content-Length') == 0
29
29
  content_length = value.to_i
@@ -78,6 +78,17 @@ module Excon
78
78
 
79
79
  response
80
80
  end
81
+
82
+ # Retrieve a specific header value. Header names are treated case-insensitively.
83
+ # @param [String] name Header name
84
+ def get_header(name)
85
+ headers.each do |key,value|
86
+ if key.casecmp(name) == 0
87
+ return value
88
+ end
89
+ end
90
+ nil
91
+ end
81
92
 
82
93
  end # class Response
83
94
  end # module Excon
@@ -0,0 +1,49 @@
1
+ Shindo.tests('Excon response header support') do
2
+
3
+ with_rackup('response_header.ru') do
4
+
5
+ tests('Response#get_header') do
6
+ connection = Excon.new('http://foo.com:8080', :proxy => 'http://localhost:9292')
7
+ response = connection.request(:method => :get, :path => '/foo')
8
+
9
+ tests('with variable header capitalization') do
10
+
11
+ tests('response.get_header("content-type")').returns('text/html') do
12
+ response.get_header("content-type")
13
+ end
14
+
15
+ tests('response.get_header("custom-header")').returns('foo') do
16
+ response.get_header("custom-header")
17
+ end
18
+
19
+ tests('response.get_header("lowercase-header")').returns('bar') do
20
+ response.get_header("lowercase-header")
21
+ end
22
+
23
+ end
24
+
25
+ tests('when provided key capitalization varies') do
26
+
27
+ tests('response.get_header("CONTENT-TYPE")').returns('text/html') do
28
+ response.get_header("CONTENT-TYPE")
29
+ end
30
+
31
+ tests('response.get_header("CoNtEnT-TyPe")').returns('text/html') do
32
+ response.get_header("CoNtEnT-TyPe")
33
+ end
34
+
35
+ end
36
+
37
+ tests('when header is unavailable') do
38
+
39
+ tests('response.get_header("missing")').returns(nil) do
40
+ response.get_header("missing")
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,14 @@
1
+ require 'sinatra'
2
+
3
+ class App < Sinatra::Base
4
+ get('/foo') do
5
+ headers(
6
+ "Content-Type" => 'text/html',
7
+ "CUSTOM-HEADER" => 'foo',
8
+ "lowercase-header" => 'bar'
9
+ )
10
+ 'primary content'
11
+ end
12
+ end
13
+
14
+ run App
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - geemus (Wesley Beary)
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-11 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-05-02 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: open4
@@ -93,6 +92,7 @@ files:
93
92
  - benchmarks/concat_vs_interpolate.rb
94
93
  - benchmarks/cr_lf.rb
95
94
  - benchmarks/downcase-eq-eq_vs_casecmp.rb
95
+ - benchmarks/excon.rb
96
96
  - benchmarks/excon_vs.rb
97
97
  - benchmarks/for_vs_array_each.rb
98
98
  - benchmarks/for_vs_hash_each.rb
@@ -111,16 +111,17 @@ files:
111
111
  - lib/excon/errors.rb
112
112
  - lib/excon/response.rb
113
113
  - tests/basic_tests.rb
114
+ - tests/header_tests.rb
114
115
  - tests/proxy_tests.rb
115
116
  - tests/query_string_tests.rb
116
117
  - tests/rackups/basic.ru
117
118
  - tests/rackups/proxy.ru
118
119
  - tests/rackups/query_string.ru
120
+ - tests/rackups/response_header.ru
119
121
  - tests/rackups/thread_safety.ru
120
122
  - tests/stub_tests.rb
121
123
  - tests/test_helper.rb
122
124
  - tests/thread_safety_tests.rb
123
- has_rdoc: true
124
125
  homepage: https://github.com/geemus/excon
125
126
  licenses: []
126
127
 
@@ -150,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  requirements: []
151
152
 
152
153
  rubyforge_project: excon
153
- rubygems_version: 1.4.2
154
+ rubygems_version: 1.7.2
154
155
  signing_key:
155
156
  specification_version: 2
156
157
  summary: speed, persistence, http(s)