Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Handle case where body is nil.

Closes #79.
  • Loading branch information...
commit c986238808ee6706eed4a95481c6be6b205e5c2a 1 parent d78791e
Myron Marston authored July 21, 2011
2  lib/vcr/structs/response.rb
@@ -13,7 +13,7 @@ def self.from_net_http_response(response)
13 13
     end
14 14
 
15 15
     def update_content_length_header
16  
-      headers['content-length'] &&= [body.length.to_s]
  16
+      headers['content-length'] &&= [body ? body.length.to_s : '0']
17 17
     end
18 18
   end
19 19
 end
7  spec/vcr/structs/response_spec.rb
@@ -57,5 +57,12 @@ def instance(body, content_length = nil)
57 57
         inst.update_content_length_header
58 58
       }.to change { inst.headers['content-length'] }.from(['3']).to(['8'])
59 59
     end
  60
+
  61
+    it 'sets the content_length header to 0 if the response body is nil' do
  62
+      inst = instance(nil, '3')
  63
+      expect {
  64
+        inst.update_content_length_header
  65
+      }.to change { inst.headers['content-length'] }.from(['3']).to(['0'])
  66
+    end
60 67
   end
61 68
 end

0 notes on commit c986238

Please sign in to comment.
Something went wrong with that request. Please try again.