diff --git a/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e b/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e index 5f63dcb4..54762849 100644 --- a/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e +++ b/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e @@ -2,6 +2,7 @@ note description: "Summary description for {WGI_CHUNKED_INPUT_STREAM}." date: "$Date$" revision: "$Revision$" + EIS: "name=Chunked Transfer Coding", "protocol=URI", "src=http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1" class WGI_CHUNKED_INPUT_STREAM @@ -36,7 +37,7 @@ feature -- Input if index > chunk_upper then read_chunk if last_chunk = Void then - read_trailer + read_trailer_and_crlf end end last_character := last_chunk.item (index) @@ -45,37 +46,48 @@ feature -- Input read_string (nb: INTEGER) -- Read the next `nb' characters and -- make the string result available in `last_string' + --| Chunked-Body = *chunk + --| last-chunk + --| trailer + --| CRLF local i: like index do last_string.wipe_out - if last_chunk_size = 0 then - read_chunk - end - from - index := index + 1 - i := index - until - i - index + 1 = nb or last_chunk_size = 0 - loop - if i + nb - 1 <= chunk_upper then - last_string.append (last_chunk.substring (i, i + nb - 1)) - i := i + nb - 1 - else - -- Need to read new chunk - -- first get all available data from current chunk - if i <= chunk_upper then - last_string.append (last_chunk.substring (i, chunk_upper)) - i := chunk_upper - end - -- then continue + if last_trailer /= Void then + -- trailer already reached, no more data + check input.end_of_input end + else + if last_chunk_size = 0 then read_chunk end + from + index := index + 1 + i := index + until + i - index + 1 = nb or last_chunk_size = 0 + loop + if i + nb - 1 <= chunk_upper then + last_string.append (last_chunk.substring (i - chunk_lower + 1, i - chunk_lower + 1 + nb - 1)) + i := i + nb - 1 + else + -- Need to read new chunk + -- first get all available data from current chunk + if i <= chunk_upper then + last_string.append (last_chunk.substring (i - chunk_lower + 1, chunk_upper - chunk_lower + 1)) + i := chunk_upper + end + -- then continue + read_chunk + i := i + 1 + check i = chunk_lower end + end + end + if last_chunk_size = 0 then + read_trailer_and_crlf + end + index := i end - if last_chunk_size = 0 then - read_trailer - end - index := i end feature -- Access @@ -91,6 +103,9 @@ feature -- Access last_character: CHARACTER_8 -- Last item read. + last_trailer: detachable STRING_8 + -- Last trailer content if any. + feature -- Status report is_open_read: BOOLEAN @@ -114,14 +129,26 @@ feature {NONE} -- Parser tmp_hex_chunk_size: STRING_8 read_chunk + local + l_input: like input do - chunk_lower := chunk_upper + 1 - last_chunk.wipe_out - last_chunk_size := 0 - read_chunk_size - if last_chunk_size > 0 then - chunk_upper := chunk_upper + last_chunk_size - read_chunk_data + if input.end_of_input then + else + chunk_lower := chunk_upper + 1 + last_chunk.wipe_out + last_chunk_size := 0 + read_chunk_size + if last_chunk_size > 0 then + chunk_upper := chunk_upper + last_chunk_size + read_chunk_data + check last_chunk.count = last_chunk_size end + + l_input := input + l_input.read_character + check l_input.last_character = '%R' end + l_input.read_character + check l_input.last_character = '%N' end + end end ensure attached last_chunk as l_last_chunk implies l_last_chunk.count = chunk_upper - chunk_lower @@ -134,6 +161,9 @@ feature {NONE} -- Parser local l_input: like input do + debug ("wgi") + print (" Read chunk data ("+ last_chunk_size.out +") %N") + end l_input := input l_input.read_string (last_chunk_size) last_chunk := l_input.last_string @@ -151,6 +181,10 @@ feature {NONE} -- Parser hex : HEXADECIMAL_STRING_TO_INTEGER_CONVERTER l_input: like input do + debug ("wgi") + print (" Read chunk size: ") + end + l_input := input from l_input.read_character @@ -158,6 +192,9 @@ feature {NONE} -- Parser eol loop c := l_input.last_character + debug ("wgi") + print (c.out) + end inspect c when '%R' then -- We are in the end of the line, we need to read the next character to start the next line. @@ -183,6 +220,10 @@ feature {NONE} -- Parser end end tmp_hex_chunk_size.wipe_out + + debug ("wgi") + print ("%N Chunk size = " + last_chunk_size.out + "%N") + end end read_extension_chunk @@ -190,7 +231,7 @@ feature {NONE} -- Parser l_input: like input do l_input := input - debug + debug ("wgi") print (" Reading extension chunk ") end from @@ -198,41 +239,59 @@ feature {NONE} -- Parser until l_input.last_character = '%R' loop - debug + debug ("wgi") print (l_input.last_character) end l_input.read_character end end - read_trailer + read_trailer_and_crlf + -- trailer = *(entity-header CRLF) + -- CRLF local l_input: like input + l_line_size: INTEGER + s: STRING_8 do + create s.make_empty l_input := input if not l_input.end_of_input then - debug + debug ("wgi") print (" Reading trailer ") end from - l_input.read_character + l_line_size := 1 -- Dummy value /= 0 until - l_input.last_character = '%R' + l_line_size = 0 loop - debug - print (l_input.last_character) + l_line_size := 0 + from + l_input.read_character + s.append_character (l_input.last_character) + until + l_input.last_character = '%R' + loop + l_line_size := l_line_size + 1 + debug ("wgi") + print (l_input.last_character) + end + l_input.read_character + s.append_character (l_input.last_character) end + s.remove_tail (1) + -- read the LF l_input.read_character + check l_input.last_character = '%N' end end - -- read the LF - l_input.read_character end + last_trailer := s end feature {NONE} -- Implementation input: WGI_INPUT_STREAM - -- Input Stream + -- Input Stream ;note copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" diff --git a/library/server/wsf/extension/wsf_resource_handler_helper.e b/library/server/wsf/extension/wsf_resource_handler_helper.e index dab8cb64..e9781b3d 100644 --- a/library/server/wsf/extension/wsf_resource_handler_helper.e +++ b/library/server/wsf/extension/wsf_resource_handler_helper.e @@ -205,7 +205,7 @@ feature -- Retrieve content from WGI_INPUT_STREAM l_input := req.input if req.is_chunked_input then from - n := 1_024 + n := 8_192 create Result.make (n) until n = 0 diff --git a/library/server/wsf/src/support/wsf_mime_handler_helper.e b/library/server/wsf/src/support/wsf_mime_handler_helper.e index 993417fa..88d6b444 100644 --- a/library/server/wsf/src/support/wsf_mime_handler_helper.e +++ b/library/server/wsf/src/support/wsf_mime_handler_helper.e @@ -21,7 +21,7 @@ feature {NONE} -- Implementation t: STRING do from - n := 1_024 + n := 8_192 create Result.make (n) until n = 0 diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index deb49a1f..36a918a3 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -207,7 +207,7 @@ feature -- Access: Input l_input := input if is_chunked_input then from - n := 1_024 + n := 8_192 until n = 0 loop