From 0f51925ec1ae8d86b895712ca9aafdae1fe81500 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 15 Dec 2011 08:53:50 -0300 Subject: [PATCH 1/3] Initial implementation of wgi_chunked_input_stream as a wrapper of wgi_input_stream --- .../ewsgi/src/wgi_chunked_input_stream.e | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 library/server/ewsgi/src/wgi_chunked_input_stream.e diff --git a/library/server/ewsgi/src/wgi_chunked_input_stream.e b/library/server/ewsgi/src/wgi_chunked_input_stream.e new file mode 100644 index 00000000..d9db7584 --- /dev/null +++ b/library/server/ewsgi/src/wgi_chunked_input_stream.e @@ -0,0 +1,157 @@ +note + description: "Summary description for {WGI_CHUNKED_INPUT_STREAM}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WGI_CHUNKED_INPUT_STREAM +create + make +feature {NONE} -- Implementation + make ( an_input : like input) + do + create last_chunked.make_empty + create last_chunk_size.make_empty + input := an_input + end + +feature --Input + read + -- Read all the data in a chunked stream. + -- Make the result available in `last_chunked'. + -- Chunked-Body = *chunk + -- last-chunk + -- trailer + -- CRLF + -- chunk = chunk-size [ chunk-extension ] CRLF + -- chunk-data CRLF + -- chunk-size = 1*HEX + -- last-chunk = 1*("0") [ chunk-extension ] CRLF + -- chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) + -- chunk-ext-name = token + -- chunk-ext-val = token | quoted-string + -- chunk-data = chunk-size(OCTET) + -- trailer = *(entity-header CRLF) + local + eoc : BOOLEAN + do + from + read_chunk + last_chunked.append (input.last_string) + if last_chunk_size.is_equal ("0") then + eoc := true + end + until + eoc + loop + read_chunk + last_chunked.append (input.last_string) + if last_chunk_size.is_equal ("0") then + eoc := true + end + end + + read_trailer + + end + +feature {NONE} -- Parser + last_chunk_size : STRING + + read_chunk + do + -- clear last results + last_chunk_size.wipe_out + + -- new read + read_chunk_size + read_chunk_data + end + + read_chunk_data + local + hex : HEXADECIMAL_STRING_TO_INTEGER_CONVERTER + do + create hex.make + hex.parse_string_with_type (last_chunk_size, hex.type_integer) + if hex.parse_successful then + input.read_string (hex.parsed_integer) + end + -- read CRLF + input.read_character + if input.last_character.is_equal ('%R') then + input.read_character + end + end + + read_chunk_size + local + eol : BOOLEAN + do + from + input.read_character + until + eol + loop + + if input.last_character.is_equal ('%R') then + -- We are in the end of the line, we need to read the next character to start the next line. + input.read_character + eol := true + elseif input.last_character.is_equal (';') then + -- We are in an extension chunk data + read_extension_chunk + else + last_chunk_size.append_character (input.last_character) + input.read_character + end + end + end + + read_extension_chunk + do + print (" Reading extension chunk ") + from + input.read_character + until + input.last_character.is_equal ('%R') + loop + print (input.last_character) + input.read_character + end + end + + read_trailer + do + print (" Reading trailer ") + from + input.read_character + until + input.last_character.is_equal ('%R') + loop + print (input.last_character) + input.read_character + end + -- read the LF + input.read_character + end +feature {NONE} -- Access + + input: WGI_INPUT_STREAM + -- Input Stream + +feature -- Access + last_chunked: STRING_8 + +;note + copyright: "2011-2011, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end From 1423412f31b6725483acf7a34af0f1009a62e311 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Thu, 15 Dec 2011 09:18:37 -0300 Subject: [PATCH 2/3] Update read_trailer feature. --- .../ewsgi/src/wgi_chunked_input_stream.e | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/library/server/ewsgi/src/wgi_chunked_input_stream.e b/library/server/ewsgi/src/wgi_chunked_input_stream.e index d9db7584..016e7107 100644 --- a/library/server/ewsgi/src/wgi_chunked_input_stream.e +++ b/library/server/ewsgi/src/wgi_chunked_input_stream.e @@ -124,17 +124,19 @@ feature {NONE} -- Parser read_trailer do - print (" Reading trailer ") - from - input.read_character - until - input.last_character.is_equal ('%R') - loop - print (input.last_character) + if not input.end_of_input then + print (" Reading trailer ") + from + input.read_character + until + input.last_character.is_equal ('%R') + loop + print (input.last_character) + input.read_character + end + -- read the LF input.read_character end - -- read the LF - input.read_character end feature {NONE} -- Access From 6b3a2d3b434f3c849121303eb048980b8e80d49a Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 21 Dec 2011 15:40:03 -0200 Subject: [PATCH 3/3] Update examples/restbucksCRUD/readme.md --- examples/restbucksCRUD/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/restbucksCRUD/readme.md b/examples/restbucksCRUD/readme.md index c833a939..6d06a051 100644 --- a/examples/restbucksCRUD/readme.md +++ b/examples/restbucksCRUD/readme.md @@ -1,6 +1,6 @@ Restbuck Eiffel Implementation based on the book of REST in Practice ==================================================================== -This is an ihmplementation of CRUD pattern for manipulate resources, this is the first step to use +This is an implementation of CRUD pattern for manipulate resources, this is the first step to use the HTTP protocol as an application protocol instead of a transport protocol. Restbuck Protocol