Land #6398, content length header

lands wei's content length header pr
bug/bundler_fix
David Maloney 2016-05-04 11:53:46 -05:00
commit 55b38ad089
No known key found for this signature in database
GPG Key ID: DEDBA9DC3A913DB2
2 changed files with 21 additions and 1 deletions

View File

@ -393,7 +393,17 @@ class ClientRequest
# Return the content length header
#
def set_content_len_header(clen)
return "" if clen == 0 || opts['chunked_size'] > 0 || (opts['headers'] && opts['headers']['Content-Length'])
if opts['method'] == 'GET' && (clen == 0 || opts['chunked_size'] > 0)
# This condition only applies to GET because of the specs.
# RFC-7230:
# A Content-Length header field is normally sent in a POST
# request even when the value is 0 (indicating an empty payload body)
return ''
elsif opts['headers'] && opts['headers']['Content-Length']
# If the module has a modified content-length header, respect that by
# not setting another one.
return ''
end
set_formatted_header("Content-Length", clen)
end

View File

@ -171,6 +171,16 @@ RSpec.describe Rex::Proto::Http::ClientRequest do
}
],
[
"with a POST request and no payload body",
default_options.merge({
'method' => 'POST'
}),
{
:set_content_len_header => { args: 0, result: "Content-Length: 0\r\n"}
}
],
].each do |c, opts, expectations|
context c do
subject(:client_request) { Rex::Proto::Http::ClientRequest.new(opts) }