Skip to content

Commit

Permalink
Escape zero bytes in header values.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshasselberg committed Jun 11, 2012
1 parent 9ae481f commit a2b0874
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/typhoeus/easy/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ def set_option(option, value)

def set_headers
@header_list = nil
headers.each {|key, value| @header_list = Curl.slist_append(@header_list, "#{key}: #{value}") }
headers.each {|key, value| @header_list = Curl.slist_append(@header_list, "#{key}: #{escape_zero_byte(value)}") }
set_option(:httpheader, @header_list) unless headers.empty?
end

def escape_zero_byte(value)
value.gsub(0.chr, '\\\0')
end
end
end
end
16 changes: 16 additions & 0 deletions spec/typhoeus/easy/options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Typhoeus::EasyFu::Options do
describe "#set_headers" do
let(:headers) { { 'User-Agent' => "fubar\0" } }
let(:request) { Typhoeus::Request.get("http://localhost:3001", { :headers => headers }) }

it "sends them" do
request.body.should include("fubar")
end

it "removes zero bytes from values" do
request.body.should include("fubar\\\\0")
end
end
end

0 comments on commit a2b0874

Please sign in to comment.