Fix #6609 and #6587 - Change Content-Length behavior in Rex HTTP

This patches changes two things:

1. If a module has a custom Content-Length, it will respect that
   instead of forcing its own.

2. If a request does not have anything in the body, the
   Content-Length header will not be set.

Fix #6609
Fix #6587
bug/bundler_fix
wchen-r7 2016-02-29 10:50:21 -06:00
parent 53ff3051e1
commit bff4b4d5fc
2 changed files with 22 additions and 2 deletions

View File

@ -391,8 +391,9 @@ class ClientRequest
#
# Return the content length header
#
def set_content_len_header(clen)
return "" if opts['chunked_size'] > 0
return "" if clen == 0 || opts['chunked_size'] > 0 || (opts['headers'] && opts['headers']['Content-Length'])
set_formatted_header("Content-Length", clen)
end

View File

@ -151,7 +151,26 @@ RSpec.describe Rex::Proto::Http::ClientRequest do
{
:set_host_header => { :result => "Host: [2001:DB8::1]:1234\r\n" },
}
]
],
[
"with modified Content-Length header",
default_options.merge({
'headers' => { 'Content-Length' => 1337 }
}),
{
:set_content_len_header => { args: 0, result: ''}
}
],
[
"with 1024 bytes of Content-Length",
default_options,
{
:set_content_len_header => { args: 1024, result: "Content-Length: 1024\r\n"}
}
],
].each do |c, opts, expectations|
context c do
subject(:client_request) { Rex::Proto::Http::ClientRequest.new(opts) }