Fixed an issue with one short chunk and empty trailer

issue#81
This commit is contained in:
2013-10-18 20:59:29 +02:00
parent 0f7dca0701
commit 3065637c80
3 changed files with 61 additions and 22 deletions

View File

@@ -20,8 +20,9 @@ feature {NONE} -- Initialization
res.set_post_commit_action (agent commit) res.set_post_commit_action (agent commit)
end end
wgi_response: WGI_RESPONSE feature -- Access
wgi_response: WGI_RESPONSE
feature {WGI_FILTER_RESPONSE} -- Change feature {WGI_FILTER_RESPONSE} -- Change

View File

@@ -9,6 +9,9 @@ class
inherit inherit
WGI_INPUT_STREAM WGI_INPUT_STREAM
redefine
last_character_available
end
create create
make make
@@ -36,12 +39,18 @@ feature -- Input
index := index + 1 index := index + 1
if index > chunk_upper then if index > chunk_upper then
read_chunk_block read_chunk_block
if last_chunk_data = Void then if
last_chunk_size = 0
then
read_trailer_and_crlf read_trailer_and_crlf
end last_character := '%U'
end else
last_character := last_chunk_data.item (index) last_character := last_chunk_data.item (index)
end end
else
last_character := last_chunk_data.item (index)
end
end
read_string (nb: INTEGER) read_string (nb: INTEGER)
-- Read the next `nb' characters and -- Read the next `nb' characters and
@@ -54,7 +63,7 @@ feature -- Input
i: like index i: like index
do do
last_string.wipe_out last_string.wipe_out
if last_trailer /= Void then if is_trailer_reached then
-- trailer already reached, no more data -- trailer already reached, no more data
check input.end_of_input end check input.end_of_input end
else else
@@ -103,6 +112,12 @@ feature -- Access
last_character: CHARACTER_8 last_character: CHARACTER_8
-- Last item read. -- Last item read.
last_character_available: BOOLEAN
-- <Precursor>
do
Result := not is_trailer_reached
end
feature -- Access: chunk feature -- Access: chunk
last_chunk_size: INTEGER last_chunk_size: INTEGER
@@ -142,7 +157,13 @@ feature -- Status report
end_of_input: BOOLEAN end_of_input: BOOLEAN
-- Has the end of input stream been reached? -- Has the end of input stream been reached?
do do
Result := input.end_of_input Result := input.end_of_input or is_trailer_reached
end
is_trailer_reached: BOOLEAN
-- Trailer reached?
do
Result := last_trailer /= Void
end end
feature {NONE} -- Parser feature {NONE} -- Parser
@@ -320,12 +341,8 @@ feature {NONE} -- Parser
check l_input.last_character = '%N' end check l_input.last_character = '%N' end
end end
end end
if s.is_empty then
last_trailer := Void
else
last_trailer := s last_trailer := s
end end
end
feature {NONE} -- Implementation feature {NONE} -- Implementation
@@ -333,7 +350,7 @@ feature {NONE} -- Implementation
-- Input Stream -- Input Stream
;note ;note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -62,8 +62,8 @@ feature -- Input
i > end_pos i > end_pos
loop loop
read_character read_character
if last_character_available then
a_string.put (last_character, i) a_string.put (last_character, i)
if end_of_input then if end_of_input then
Result := i Result := i
-- Jump out of the loop. -- Jump out of the loop.
@@ -71,6 +71,11 @@ feature -- Input
else else
i := i + 1 i := i + 1
end end
else
-- reached end of input
-- Jump out of the loop.
i := end_pos + 1
end
end end
if not end_of_input then if not end_of_input then
Result := i Result := i
@@ -107,14 +112,21 @@ feature -- Input
i > end_pos i > end_pos
loop loop
read_character read_character
if last_character_available then
a_string.extend (last_character) a_string.extend (last_character)
l_count := l_count + 1 l_count := l_count + 1
if end_of_input then if end_of_input then
-- Jump out of the loop. -- Jump out of the loop.
i := end_pos + 1 i := end_pos + 1
else else
i := i + 1 i := i + 1
end end
else
-- reached end of input
-- Jump out of the loop.
i := end_pos + 1
end
end end
last_appended_count := l_count last_appended_count := l_count
ensure ensure
@@ -194,6 +206,15 @@ feature -- Access
deferred deferred
end end
last_character_available: BOOLEAN
-- Is `last_character' available? i.e read?
--| with chunked encoding, we may reach the end and the `last_character'
--| should not be used.
--| to redefine in descendant if needed
do
Result := True
end
last_appended_count: INTEGER last_appended_count: INTEGER
-- Count of characters actually read by last `append_to_string' call. -- Count of characters actually read by last `append_to_string' call.