patron 0.4.16 → 0.4.17

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.
@@ -38,11 +38,14 @@ module Patron
38
38
 
39
39
  @charset = determine_charset(header_data, body) || default_charset
40
40
 
41
- [url, header_data, body].each do |attr|
41
+ [url, header_data].each do |attr|
42
42
  convert_to_default_encoding!(attr)
43
43
  end
44
44
 
45
45
  parse_headers(header_data)
46
+ if @headers["Content-Type"] && @headers["Content-Type"][0, 5] == "text/"
47
+ convert_to_default_encoding!(@body)
48
+ end
46
49
  end
47
50
 
48
51
  attr_reader :url, :status, :status_line, :redirect_count, :body, :headers, :charset
@@ -78,11 +78,10 @@ module Patron
78
78
  # Default encoding of responses. Used if no charset is provided by the host.
79
79
  attr_accessor :default_response_charset
80
80
 
81
- private :ext_initialize, :handle_request, :enable_cookie_session, :set_debug_file
81
+ private :handle_request, :enable_cookie_session, :set_debug_file
82
82
 
83
83
  # Create a new Session object.
84
84
  def initialize
85
- ext_initialize
86
85
  @headers = {}
87
86
  @timeout = 5
88
87
  @connect_timeout = 1
@@ -222,11 +221,5 @@ module Patron
222
221
  handle_request(req)
223
222
  end
224
223
 
225
- private
226
-
227
- def urlencode(str)
228
- str.gsub(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0].ord) }
229
- end
230
-
231
224
  end
232
225
  end
@@ -1,3 +1,3 @@
1
1
  module Patron
2
- VERSION = "0.4.16"
2
+ VERSION = "0.4.17"
3
3
  end
data/patron.gemspec CHANGED
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "patron"
16
16
 
17
17
  s.add_development_dependency "bundler", ">= 1.0.0"
18
- s.add_development_dependency "rake-compiler", "~> 0.7.5"
19
- s.add_development_dependency "rspec", "~> 2.3.0"
20
- s.add_development_dependency "rcov", "~> 0.9.9"
18
+ s.add_development_dependency "rake-compiler", ">= 0.7.5"
19
+ s.add_development_dependency "rspec", ">= 2.3.0"
20
+ s.add_development_dependency "rcov", ">= 0.9.9"
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
23
23
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
data/pic.png ADDED
Binary file
data/script/test_server CHANGED
@@ -23,116 +23,8 @@
23
23
  ## THE SOFTWARE.
24
24
  ##
25
25
  ## -------------------------------------------------------------------
26
- require 'yaml'
27
- require 'webrick'
28
- include WEBrick
29
26
 
30
- # This ugly little hack is necessary to make the specs pass when running
31
- # the test_server script under Ruby 1.9. URI::Parser#to_yaml generates
32
- # regexp representations that YAML.parse cannot parse.
33
- class URI::Parser
34
- def to_yaml(opts = {})
35
- {}.to_yaml(opts)
36
- end
37
- end
27
+ root = File.expand_path('../..', __FILE__)
28
+ require File.join(root, %w[spec support test_server.rb])
38
29
 
39
- module RespondWith
40
- def respond_with(method, req, res)
41
- res.body = req.to_yaml
42
- res['Content-Type'] = "text/plain"
43
- end
44
- end
45
-
46
- class TestServlet < HTTPServlet::AbstractServlet
47
-
48
- include RespondWith
49
-
50
- def do_GET(req,res)
51
- respond_with(:GET, req, res)
52
- end
53
-
54
- def do_POST(req,res)
55
- respond_with(:POST, req, res)
56
- end
57
-
58
- def do_PUT(req,res)
59
- respond_with(:PUT, req, res)
60
- end
61
-
62
- def do_DELETE(req,res)
63
- respond_with(:DELETE, req, res)
64
- end
65
-
66
- def do_COPY(req,res)
67
- respond_with(:COPY, req, res)
68
- end
69
- end
70
-
71
- class TimeoutServlet < HTTPServlet::AbstractServlet
72
- def do_GET(req,res)
73
- sleep(1.1)
74
- end
75
- end
76
-
77
- class RedirectServlet < HTTPServlet::AbstractServlet
78
- def do_GET(req,res)
79
- res['Location'] = "http://localhost:9001/test"
80
- res.status = 301
81
- end
82
- end
83
-
84
-
85
- class TestPostBodyServlet < HTTPServlet::AbstractServlet
86
- include RespondWith
87
- def do_POST(req, res)
88
- respond_with(:POST, {'body' => req.body, 'content_type' => req.content_type}, res)
89
- end
90
- end
91
-
92
-
93
-
94
- class SetCookieServlet < HTTPServlet::AbstractServlet
95
- def do_GET(req, res)
96
- res['Set-Cookie'] = "session_id=foo123"
97
- res['Location'] = "http://localhost:9001/test"
98
- res.status = 301
99
- end
100
- end
101
-
102
- class RepetitiveHeaderServlet < HTTPServlet::AbstractServlet
103
- def do_GET(req, res)
104
- # the only way to get webrick to output two headers with the same name is using cookies, so that's what we'll do:
105
- res.cookies << Cookie.new('a', '1')
106
- res.cookies << Cookie.new('b', '2')
107
- res['Content-Type'] = "text/plain"
108
- res.body = "Hi."
109
- end
110
- end
111
-
112
- class WrongContentLengthServlet < HTTPServlet::AbstractServlet
113
- def do_GET(req, res)
114
- res.keep_alive = false
115
- res.content_length = 1024
116
- res.body = "Hello."
117
- end
118
- end
119
-
120
- server = WEBrick::HTTPServer.new :Port => 9001
121
- server.mount("/test", TestServlet)
122
- server.mount("/testpost", TestPostBodyServlet)
123
- server.mount("/timeout", TimeoutServlet)
124
- server.mount("/redirect", RedirectServlet)
125
- server.mount("/setcookie", SetCookieServlet)
126
- server.mount("/repetitiveheader", RepetitiveHeaderServlet)
127
- server.mount("/wrongcontentlength", WrongContentLengthServlet)
128
-
129
- exit_code = lambda do
130
- begin
131
- server.shutdown unless server.nil?
132
- rescue Object => e
133
- puts "Error #{__FILE__}:#{__LINE__}\n#{e.message}"
134
- end
135
- end
136
-
137
- trap("INT"){exit_code.call}
138
- server.start
30
+ PatronTestServer.start($stderr).join
@@ -43,6 +43,12 @@ describe Patron::Response do
43
43
  response.headers['Set-Cookie'].should == ["a=1","b=2"]
44
44
  end
45
45
 
46
+ it "should works with non-text files" do
47
+ response = @session.get("/picture")
48
+ response.headers['Content-Type'].should == 'image/png'
49
+ response.body.encoding.should == Encoding::ASCII_8BIT
50
+ end
51
+
46
52
  it "should not allow a default charset to be nil" do
47
53
  Encoding.stub(:default_internal).and_return("UTF-8")
48
54
  expect {
data/spec/session_spec.rb CHANGED
@@ -171,7 +171,7 @@ describe Patron::Session do
171
171
  response = @session.post("/testpost", data)
172
172
  body = YAML::load(response.body)
173
173
  body['content_type'].should == "application/x-www-form-urlencoded"
174
- body['body'].should match(/baz=%2b%2bhello%20world%2b%2b/)
174
+ body['body'].should match(/baz=%2B%2Bhello%20world%2B%2B/)
175
175
  body['body'].should match(/foo=123/)
176
176
  end
177
177
 
@@ -286,4 +286,17 @@ describe Patron::Session do
286
286
  "Basic " + Base64.encode64("#{user}:#{passwd}").strip
287
287
  end
288
288
 
289
+ # ------------------------------------------------------------------------
290
+ describe 'when debug is enabled' do
291
+ it 'it should not clobber stderr' do
292
+ rdev = STDERR.stat.rdev
293
+
294
+ @session.enable_debug
295
+ STDERR.stat.rdev.should be == rdev
296
+
297
+ @session.enable_debug
298
+ STDERR.stat.rdev.should be == rdev
299
+ end
300
+ end
301
+
289
302
  end
data/spec/spec_helper.rb CHANGED
@@ -26,3 +26,7 @@ require 'rspec'
26
26
  $:.unshift(File.dirname(__FILE__) + '/../lib')
27
27
  $:.unshift(File.dirname(__FILE__) + '/../ext')
28
28
  require 'patron'
29
+
30
+ Dir['./spec/support/**/*.rb'].each { |fn| require fn }
31
+
32
+ PatronTestServer.start if RUBY_VERSION >= '1.9'
@@ -0,0 +1,175 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Patron HTTP Client: HTTP test server for integration tests
4
+ ## Copyright (c) 2008 The Hive http://www.thehive.com/
5
+ ##
6
+ ## Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ ## of this software and associated documentation files (the "Software"), to deal
8
+ ## in the Software without restriction, including without limitation the rights
9
+ ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ ## copies of the Software, and to permit persons to whom the Software is
11
+ ## furnished to do so, subject to the following conditions:
12
+ ##
13
+ ## The above copyright notice and this permission notice shall be included in
14
+ ## all copies or substantial portions of the Software.
15
+ ##
16
+ ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ ## THE SOFTWARE.
23
+ ##
24
+ ## -------------------------------------------------------------------
25
+ require 'yaml'
26
+ require 'webrick'
27
+ include WEBrick
28
+
29
+ # This ugly little hack is necessary to make the specs pass when running
30
+ # the test_server script under Ruby 1.9. URI::Parser#to_yaml generates
31
+ # regexp representations that YAML.parse cannot parse.
32
+ class URI::Parser
33
+ def to_yaml(opts = {})
34
+ {}.to_yaml(opts)
35
+ end
36
+ end
37
+
38
+ module RespondWith
39
+ def respond_with(method, req, res)
40
+ res.body = req.to_yaml
41
+ res['Content-Type'] = "text/plain"
42
+ end
43
+ end
44
+
45
+ class TestServlet < HTTPServlet::AbstractServlet
46
+
47
+ include RespondWith
48
+
49
+ def do_GET(req,res)
50
+ respond_with(:GET, req, res)
51
+ end
52
+
53
+ def do_POST(req,res)
54
+ respond_with(:POST, req, res)
55
+ end
56
+
57
+ def do_PUT(req,res)
58
+ respond_with(:PUT, req, res)
59
+ end
60
+
61
+ def do_DELETE(req,res)
62
+ respond_with(:DELETE, req, res)
63
+ end
64
+
65
+ def do_COPY(req,res)
66
+ respond_with(:COPY, req, res)
67
+ end
68
+ end
69
+
70
+ class TimeoutServlet < HTTPServlet::AbstractServlet
71
+ def do_GET(req,res)
72
+ sleep(1.1)
73
+ end
74
+ end
75
+
76
+ class RedirectServlet < HTTPServlet::AbstractServlet
77
+ def do_GET(req,res)
78
+ res['Location'] = "http://localhost:9001/test"
79
+ res.status = 301
80
+ end
81
+ end
82
+
83
+
84
+ class TestPostBodyServlet < HTTPServlet::AbstractServlet
85
+ include RespondWith
86
+ def do_POST(req, res)
87
+ respond_with(:POST, {'body' => req.body, 'content_type' => req.content_type}, res)
88
+ end
89
+ end
90
+
91
+
92
+
93
+ class SetCookieServlet < HTTPServlet::AbstractServlet
94
+ def do_GET(req, res)
95
+ res['Set-Cookie'] = "session_id=foo123"
96
+ res['Location'] = "http://localhost:9001/test"
97
+ res.status = 301
98
+ end
99
+ end
100
+
101
+ class RepetitiveHeaderServlet < HTTPServlet::AbstractServlet
102
+ def do_GET(req, res)
103
+ # the only way to get webrick to output two headers with the same name is using cookies, so that's what we'll do:
104
+ res.cookies << Cookie.new('a', '1')
105
+ res.cookies << Cookie.new('b', '2')
106
+ res['Content-Type'] = "text/plain"
107
+ res.body = "Hi."
108
+ end
109
+ end
110
+
111
+ class PictureServlet < HTTPServlet::AbstractServlet
112
+ def do_GET(req, res)
113
+ res['Content-Type'] = "image/png"
114
+ res.body = File.read("./pic.png")
115
+ end
116
+ end
117
+
118
+ class WrongContentLengthServlet < HTTPServlet::AbstractServlet
119
+ def do_GET(req, res)
120
+ res.keep_alive = false
121
+ res.content_length = 1024
122
+ res.body = "Hello."
123
+ end
124
+ end
125
+
126
+ class PatronTestServer
127
+
128
+ def self.start( log_file = nil )
129
+ new(log_file).start
130
+ end
131
+
132
+ def initialize( log_file = nil )
133
+ log_file ||= StringIO.new
134
+ log = WEBrick::Log.new(log_file)
135
+
136
+ @server = WEBrick::HTTPServer.new(
137
+ :Port => 9001,
138
+ :Logger => log,
139
+ :AccessLog => [
140
+ [ log, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
141
+ [ log, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
142
+ ]
143
+ )
144
+ @server.mount("/test", TestServlet)
145
+ @server.mount("/testpost", TestPostBodyServlet)
146
+ @server.mount("/timeout", TimeoutServlet)
147
+ @server.mount("/redirect", RedirectServlet)
148
+ @server.mount("/picture", PictureServlet)
149
+ @server.mount("/setcookie", SetCookieServlet)
150
+ @server.mount("/repetitiveheader", RepetitiveHeaderServlet)
151
+ @server.mount("/wrongcontentlength", WrongContentLengthServlet)
152
+ end
153
+
154
+ def start
155
+ trap('INT') {
156
+ begin
157
+ @server.shutdown unless @server.nil?
158
+ rescue Object => e
159
+ $stderr.puts "Error #{__FILE__}:#{__LINE__}\n#{e.message}"
160
+ end
161
+ }
162
+
163
+ @thread = Thread.new { @server.start }
164
+ Thread.pass
165
+ self
166
+ end
167
+
168
+ def join
169
+ if defined? @thread and @thread
170
+ @thread.join
171
+ end
172
+ self
173
+ end
174
+ end
175
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.16
4
+ version: 0.4.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-07 00:00:00.000000000Z
12
+ date: 2012-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &2156478240 !ruby/object:Gem::Requirement
16
+ requirement: &70199940489140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,40 +21,40 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156478240
24
+ version_requirements: *70199940489140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake-compiler
27
- requirement: &2156477780 !ruby/object:Gem::Requirement
27
+ requirement: &70199940488660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ~>
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.7.5
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156477780
35
+ version_requirements: *70199940488660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2156477320 !ruby/object:Gem::Requirement
38
+ requirement: &70199940488200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: 2.3.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156477320
46
+ version_requirements: *70199940488200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &2156476860 !ruby/object:Gem::Requirement
49
+ requirement: &70199940487740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ~>
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.9.9
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2156476860
57
+ version_requirements: *70199940487740
58
58
  description: Ruby HTTP client library based on libcurl
59
59
  email:
60
60
  - phil.toland@gmail.com
@@ -73,7 +73,10 @@ files:
73
73
  - Rakefile
74
74
  - ext/patron/.gitignore
75
75
  - ext/patron/extconf.rb
76
+ - ext/patron/membuffer.c
77
+ - ext/patron/membuffer.h
76
78
  - ext/patron/session_ext.c
79
+ - ext/patron/sglib.h
77
80
  - lib/patron.rb
78
81
  - lib/patron/error.rb
79
82
  - lib/patron/proxy_type.rb
@@ -83,6 +86,7 @@ files:
83
86
  - lib/patron/util.rb
84
87
  - lib/patron/version.rb
85
88
  - patron.gemspec
89
+ - pic.png
86
90
  - script/console
87
91
  - script/test_server
88
92
  - spec/patron_spec.rb
@@ -90,6 +94,7 @@ files:
90
94
  - spec/response_spec.rb
91
95
  - spec/session_spec.rb
92
96
  - spec/spec_helper.rb
97
+ - spec/support/test_server.rb
93
98
  - spec/util_spec.rb
94
99
  homepage: https://github.com/toland/patron
95
100
  licenses: []