commit
55b38ad089
|
@ -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
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in New Issue