Update Content Length Header
When the :update_content_length_header
option is set to a truthy value, VCR will ensure that the Content-Length
header will have the correct value. This is useful in several situations:
When you manually edit the cassette file and change the resonse body
length. You can use this option so you don't have to manually calculate
and update the body length.
When you use ERB, the response body length may vary. This will ensure
it is always correct.
Syck, the default YAML engine for ruby 1.8 (and 1.9, unless you compile it to use Psych), has a bug where it sometimes will remove some whitespace strings when you serialize them. This may cause the
Content-Length
header to have the wrong value.This is especially important when you use a client that checks the
Content-Length
header. Mechanize, for example, will raise anEOFError
when the header value does not match the actual body length.
Background ()
Given a previously recorded cassette file "cassettes/example.yml" with:
And a file named "common_stuff.rb" with:
Default :update_content_length_header setting
Given a file named "default.rb" with:
When I run ruby default.rb
Then the output should contain:
:update_content_length_header => false
Given a file named "false.rb" with:
When I run ruby false.rb
Then the output should contain:
:update_content_length_header => true
Given a file named "true.rb" with:
When I run ruby true.rb
Then the output should contain:
Last updated