8000 Add support for sending empty header values by GUI · Pull Request #132 · typhoeus/ethon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for sending empty header values #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/ethon/easy/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Easy
#
# @api private
module Header
EMPTY_STRING_VALUE = "".freeze

# Return headers, return empty hash if none.
#
# @example Return the headers.
Expand Down Expand Up @@ -53,7 +55,11 @@ def header_list
#
# @return [ String ] The composed header.
def compose_header(key, value)
Util.escape_zero_byte("#{key}: #{value}")
if(value == EMPTY_STRING_VALUE)
Util.escape_zero_byte("#{key};")
else
Util.escape_zero_byte("#{key}: #{value}")
end
end
end
end
Expand Down
30 changes: 30 additions & 0 deletions spec/ethon/easy/header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,36 @@
expect(easy.response_body).to include('"HTTP_USER_AGENT":"Ethon"')
end
end

context "when header value is empty string" do
let(:headers) { { 'User-Agent' => "" } }

if(Ethon::Curl.version_info[:version] >= "7.23.0")
it "sends header with empty value" do
expect(easy.response_body).to include('"HTTP_USER_AGENT":""')
end
else
it "does not send header (curl < 7.23.0 does not support empty values)" do
expect(easy.response_body).to_not include('"HTTP_USER_AGENT"')
end
end
end

context "when header value is nil" do
let(:headers) { { 'User-Agent' => nil } }

it "does not send header" do
expect(easy.response_body).to_not include('"HTTP_USER_AGENT"')
end
end

context "when header value is integer" do
let(:headers) { { 'User-Agent' => 0 } }

it "sends as string" do
expect(easy.response_body).to include('"HTTP_USER_AGENT":"0"')
end
end
end
end

Expand Down
0