Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Escape zero bytes in header values.

Fixes #180.
  • Loading branch information...
commit a2b0874f3f8ba905531cf1ef68e03c41aa565b46 1 parent 9ae481f
@i0rek i0rek authored
View
6 lib/typhoeus/easy/options.rb
@@ -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
View
16 spec/typhoeus/easy/options_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.