Fixed sending of chunk, especially the ending where there is an optional Trailer, and a mandatory final CRLF

Now put_chunk does not support anymore empty chunk, and thus does not call put_chunk_end if ever it is called with empty chunk content.
Fixed the `transfered_content_length' when dealing with chunk transfert encoding
This commit is contained in:
Jocelyn Fiat
2012-12-18 23:34:55 +01:00
parent de93ce32ff
commit 0d87c7939a

View File

@@ -13,6 +13,8 @@ note
]" ]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
EIS: "name=Hypertext Transfer Protocol -- HTTP/1.1 ", "protocol=URI", "src=http://www.w3.org/Protocols/rfc2616/rfc2616.html"
EIS: "name=Chunked Transfer Coding", "protocol=URI", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1"
class class
WSF_RESPONSE WSF_RESPONSE
@@ -222,44 +224,57 @@ feature -- Output operation
l_chunk_size_line: STRING_8 l_chunk_size_line: STRING_8
i: INTEGER i: INTEGER
do do
if s.is_empty then --| Remove all left '0'
-- Should not occur due to precondition, l_chunk_size_line := s.count.to_hex_string
-- but let's handle the case for backward compatibility reason. from
put_chunk_end i := 1
else until
--| Remove all left '0' l_chunk_size_line[i] /= '0'
l_chunk_size_line := s.count.to_hex_string loop
from i := i + 1
i := 1
until
l_chunk_size_line[i] /= '0'
loop
i := i + 1
end
if i > 1 then
l_chunk_size_line := l_chunk_size_line.substring (i, l_chunk_size_line.count)
end
if a_extension /= Void then
l_chunk_size_line.append_character (';')
l_chunk_size_line.append (a_extension)
end
l_chunk_size_line.append ({HTTP_CONSTANTS}.crlf)
put_string (l_chunk_size_line)
put_string (s)
put_string ({HTTP_CONSTANTS}.crlf)
flush
increment_transfered_content_length (s.count)
end end
if i > 1 then
l_chunk_size_line := l_chunk_size_line.substring (i, l_chunk_size_line.count)
end
if a_extension /= Void then
l_chunk_size_line.append_character (';')
l_chunk_size_line.append (a_extension)
end
l_chunk_size_line.append ({HTTP_CONSTANTS}.crlf)
wgi_response.put_string (l_chunk_size_line)
put_string (s)
wgi_response.put_string ({HTTP_CONSTANTS}.crlf)
flush
ensure
transfered_content_length = old transfered_content_length + s.count.to_natural_64
end end
put_chunk_end put_chunk_end
-- Put end of chunked content -- Put end of chunked content
-- without any optional trailer.
do do
put_string ("0" + {HTTP_CONSTANTS}.crlf) wgi_response.put_string ("0")
wgi_response.put_string ({HTTP_CONSTANTS}.crlf)
-- No trailer
wgi_response.put_string ({HTTP_CONSTANTS}.crlf)
flush flush
end end
put_chunk_end_with_trailer (a_trailer: detachable READABLE_STRING_8)
-- Put end of chunked content
-- with optional trailer: *(entity-header CRLF)
require
a_trailer_well_formatted: (a_trailer /= Void and then not a_trailer.is_empty) implies a_trailer.ends_with ({HTTP_CONSTANTS}.crlf)
do
if a_trailer /= Void and then not a_trailer.is_empty then
wgi_response.put_string (a_trailer)
end
wgi_response.put_string ({HTTP_CONSTANTS}.crlf)
end
flush flush
-- Flush if it makes sense -- Flush if it makes sense
do do