public
Rubygem
Description: JSON Web App Framework
Homepage: http://halcyon.rubyforge.org/
Clone URL: git://github.com/mtodd/halcyon.git
Click here to lend your support to: halcyon and make a donation at www.pledgie.com !
Clients now include the Accept header field, set to prefer application/json but 
will fail to anything. [#62 state:resolved]
mtodd (author)
Thu Sep 18 23:19:27 -0700 2008
commit  e32e2c11efd76730ddffd1749326310781d29238
tree    d0f744f5565c33c57a3540b7bac384b39a3ec48c
parent  6ab98d687d760e932b2063a2579292066c0b64c5
...
43
44
45
 
 
46
47
48
...
183
184
185
 
186
187
188
...
43
44
45
46
47
48
49
50
...
185
186
187
188
189
190
191
0
@@ -43,6 +43,8 @@ module Halcyon
0
     
0
     USER_AGENT = "JSON/#{JSON::VERSION} Compatible (en-US) Halcyon::Client/#{Halcyon.version}".freeze
0
     CONTENT_TYPE = "application/x-www-form-urlencoded".freeze
0
+    ACCEPT = "application/json, */*".freeze
0
+    
0
     DEFAULT_OPTIONS = {
0
       :raise_exceptions => false,
0
       :encode_post_body_as_json => false
0
@@ -183,6 +185,7 @@ module Halcyon
0
     def request(req, headers={})
0
       # set default headers
0
       req["User-Agent"] = USER_AGENT
0
+      req["Accept"] = ACCEPT
0
       req["Content-Type"] = CONTENT_TYPE unless req.body.nil?
0
       req["Content-Length"] = req.body unless req.body.nil?
0
       
...
31
32
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
35
36
...
101
102
103
 
 
 
 
 
104
...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
116
117
118
119
120
121
122
123
124
0
@@ -31,6 +31,21 @@ end
0
 # Tests
0
 #++
0
 
0
+module Halcyon
0
+  class Client
0
+    private
0
+    def prepare_server(serv)
0
+      class << serv
0
+        alias :request_without_header_inspection :request
0
+        def request(req, body = nil, &block)
0
+          $accept = req["Accept"]
0
+          request_without_header_inspection(req, body, &block)
0
+        end
0
+      end
0
+    end
0
+  end
0
+end
0
+
0
 describe "Halcyon::Client" do
0
   
0
   before do
0
@@ -101,4 +116,9 @@ describe "Halcyon::Client" do
0
     @client.post('/returner', body)[:body][:key].should == "value"
0
   end
0
   
0
+  it "should set the Accept header to the appropriate type" do
0
+    @client.get('/returner')[:status].should == 200
0
+    $accept.should == Halcyon::Client::ACCEPT
0
+  end
0
+  
0
 end

Comments