Skip to content

Commit

Permalink
Set content length header based on number of bytes, not chars.
Browse files Browse the repository at this point in the history
Closes vcr#96.
  • Loading branch information
myronmarston committed Nov 9, 2011
1 parent 8be100d commit b1318f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/vcr/structs.rb
Expand Up @@ -188,8 +188,7 @@ def self.from_hash(hash)
end

def update_content_length_header
# TODO: should this be the bytesize?
value = body ? body.length.to_s : '0'
value = body ? body.bytesize.to_s : '0'
key = %w[ Content-Length content-length ].find { |k| headers.has_key?(k) }
headers[key] = [value] if key
end
Expand Down
9 changes: 9 additions & 0 deletions spec/vcr/structs_spec.rb
@@ -1,3 +1,5 @@
# encoding: UTF-8

require 'yaml'
require 'vcr/structs'

Expand Down Expand Up @@ -301,6 +303,13 @@ def instance(body)
inst.update_content_length_header
}.to change { inst.headers[header] }.from(['3']).to(['0'])
end

it 'sets the header according to RFC 2616 based on the number of bytes (not the number of characters)' do
inst = instance('aؼ', '2') # the second char is a double byte char
expect {
inst.update_content_length_header
}.to change { inst.headers[header] }.from(['2']).to(['3'])
end
end
end
end
Expand Down

0 comments on commit b1318f6

Please sign in to comment.