halcyon 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -25,14 +25,14 @@ project = {
25
25
  --exclude "^(_darcs|spec|pkg|.svn)/"
26
26
  ],
27
27
  :dependencies => {
28
- 'json_pure' => '>=1.1.2',
29
- 'rack' => '>=0.3.0',
30
- 'extlib' => '>=0.9.4',
31
- 'merb' => '>=0.9.4',
32
- 'rubigen' => '>=1.2.4'
28
+ 'json_pure' => '>= 1.1.2',
29
+ 'rack' => '>= 0.4.0',
30
+ 'extlib' => '>= 0.9.5',
31
+ 'merb-core' => '>= 0.9.5',
32
+ 'rubigen' => '>= 1.2.4'
33
33
  },
34
34
  :requirements => 'install the json gem to get faster JSON parsing',
35
- :ruby_version_required => '>=1.8.6'
35
+ :ruby_version_required => '>= 1.8.6'
36
36
  }
37
37
 
38
38
  BASEDIR = File.expand_path(File.dirname(__FILE__))
data/lib/halcyon.rb CHANGED
@@ -15,7 +15,7 @@ $:.unshift File.dirname(__FILE__)
15
15
  #
16
16
  module Halcyon
17
17
 
18
- VERSION = [0,5,2] unless defined?(Halcyon::VERSION)
18
+ VERSION = [0,5,3] unless defined?(Halcyon::VERSION)
19
19
 
20
20
  autoload :Application, 'halcyon/application'
21
21
  autoload :Client, 'halcyon/client'
@@ -41,8 +41,8 @@ module Halcyon
41
41
  class Client
42
42
  include Exceptions
43
43
 
44
- USER_AGENT = "JSON/#{JSON::VERSION} Compatible (en-US) Halcyon::Client/#{Halcyon.version}"
45
- CONTENT_TYPE = 'application/json'
44
+ USER_AGENT = "JSON/#{JSON::VERSION} Compatible (en-US) Halcyon::Client/#{Halcyon.version}".freeze
45
+ CONTENT_TYPE = "application/x-www-form-urlencoded".freeze
46
46
  DEFAULT_OPTIONS = {
47
47
  :raise_exceptions => false
48
48
  }
@@ -162,8 +162,9 @@ module Halcyon
162
162
  # exceptions specifically.
163
163
  def request(req, headers={})
164
164
  # set default headers
165
- req["Content-Type"] = CONTENT_TYPE
166
165
  req["User-Agent"] = USER_AGENT
166
+ req["Content-Type"] = CONTENT_TYPE unless req.body.nil?
167
+ req["Content-Length"] = req.body unless req.body.nil?
167
168
 
168
169
  # apply provided headers
169
170
  self.headers.merge(headers).each do |(header, value)|
@@ -193,27 +194,7 @@ module Halcyon
193
194
  # format according to Net::HTTP for sending through as a Hash.
194
195
  def format_body(data)
195
196
  data = {:body => data} unless data.is_a? Hash
196
- data.to_mash
197
- # Hash.to_params (from extlib) doesn't escape keys/values
198
- build_query(data)
199
- end
200
-
201
- # Ported over from Rack::Utils.build_query which has not been released yet
202
- # as of Halcyon 0.5.2's release.
203
- #
204
- # The key difference from this and extlib's Hash.to_params is
205
- # that the keys and values are escaped (which cause many problems).
206
- #
207
- # TODO: Remove when Rack is released with Rack::Utils.build_query included.
208
- #
209
- def build_query(params)
210
- params.map { |k, v|
211
- if v.class == Array
212
- build_query(v.map { |x| [k, x] })
213
- else
214
- Rack::Utils.escape(k) + "=" + Rack::Utils.escape(v)
215
- end
216
- }.join("&")
197
+ Rack::Utils.build_query(data)
217
198
  end
218
199
 
219
200
  end
@@ -62,9 +62,22 @@ describe "Halcyon::Client" do
62
62
 
63
63
  it "should handle ampersands (and others) in POST data correctly" do
64
64
  response = @client.post('/returner', :key => "value1&value2=0")
65
-
66
65
  response[:status].should == 200
67
66
  response[:body].should == {'controller' => 'application', 'action' => 'returner', 'key' => "value1&value2=0"}
67
+
68
+ response = @client.post('/returner', :key => "%todd")
69
+ response[:status].should == 200
70
+ response[:body].should == {'controller' => 'application', 'action' => 'returner', 'key' => "%todd"}
71
+ end
72
+
73
+ it "should not handle percent signs in the URL that are not escaped" do
74
+ should.raise(EOFError){ @client.post('/returner?key=%todd') }
75
+ end
76
+
77
+ it "should handle pre-escaped percent signs in the URLs" do
78
+ response = @client.post('/returner?key=%25todd')
79
+ response[:status].should == 200
80
+ response[:body].should == {'controller' => 'application', 'action' => 'returner', 'key' => "%todd"}
68
81
  end
69
82
 
70
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halcyon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Todd
@@ -9,28 +9,28 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-20 00:00:00 -04:00
12
+ date: 2008-08-28 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rack
16
+ name: merb-core
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.3.0
23
+ version: 0.9.5
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: merb
26
+ name: rack
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.4
33
+ version: 0.4.0
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: extlib
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.9.4
43
+ version: 0.9.5
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: json_pure