mirror of
https://github.com/nmap/nmap.git
synced 2025-12-16 04:39:03 +00:00
Giving priority to transfer-encoding first than content-length, as mentioned in rfc2616, section 4.4.
isChunked now checks for transfer-encoding: identity instead of transfer-encoding: chunked. If transfer encoding is present and it is not identity, chunked encoding is considered. Also rfc2616, section 4.4 (item 2)
This commit is contained in:
@@ -516,11 +516,7 @@ function getNextResult( full_response, method )
|
|||||||
-- If it is a get response, attach body to response
|
-- If it is a get response, attach body to response
|
||||||
if method == "get" then
|
if method == "get" then
|
||||||
body_start = body_start + 1 -- fixing body start offset
|
body_start = body_start + 1 -- fixing body start offset
|
||||||
length = getLength( header )
|
if isChunked(header) then
|
||||||
if length then
|
|
||||||
length = length + #header
|
|
||||||
body = full_response:sub(body_start, length)
|
|
||||||
elseif isChunked(header) then
|
|
||||||
full_response = full_response:sub(body_start)
|
full_response = full_response:sub(body_start)
|
||||||
local body_delim = ( full_response:match( "\r\n" ) and "\r\n" ) or
|
local body_delim = ( full_response:match( "\r\n" ) and "\r\n" ) or
|
||||||
( full_response:match( "\n" ) and "\n" ) or nil
|
( full_response:match( "\n" ) and "\n" ) or nil
|
||||||
@@ -528,12 +524,18 @@ function getNextResult( full_response, method )
|
|||||||
local chunks = {}
|
local chunks = {}
|
||||||
for tmp_size, chunk in get_chunks(full_response, 1, body_delim) do
|
for tmp_size, chunk in get_chunks(full_response, 1, body_delim) do
|
||||||
chunks[#chunks + 1] = chunk
|
chunks[#chunks + 1] = chunk
|
||||||
size = tmp_size
|
size = tmp_size
|
||||||
end
|
end
|
||||||
body = table.concat(chunks)
|
body = table.concat(chunks)
|
||||||
else
|
else
|
||||||
stdnse.print_debug("Didn't find chunked encoding or content-length field, not splitting response")
|
length = getLength( header )
|
||||||
body = full_response:sub(body_start)
|
if length then
|
||||||
|
length = length + #header
|
||||||
|
body = full_response:sub(body_start, length)
|
||||||
|
else
|
||||||
|
stdnse.print_debug("Didn't find chunked encoding or content-length field, not splitting response")
|
||||||
|
body = full_response:sub(body_start)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -556,8 +558,15 @@ function isChunked( header )
|
|||||||
local encoding = nil
|
local encoding = nil
|
||||||
for number, line in ipairs( header or {} ) do
|
for number, line in ipairs( header or {} ) do
|
||||||
line = line:lower()
|
line = line:lower()
|
||||||
encoding = line:match("(transfer%-encoding: chunked)")
|
encoding = line:match("transfer%-encoding: (.*)")
|
||||||
if encoding then return true end
|
if encoding then
|
||||||
|
print(encoding)
|
||||||
|
if encoding:match("identity") then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user