From fff7a5c96dbd0c279f99ae86685cd9bf647c248c Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 1 Dec 2011 18:22:47 +0100 Subject: [PATCH] Added WSF_RESPONSE.write_chunk (s: ?READABLE_STRING_8) to help user sending chunk with "Transfer-Encoding: chunked" --- .../src/hello_routed_world.e | 20 +++--------- library/server/wsf/src/wsf_response.e | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/examples/hello_routed_world/src/hello_routed_world.e b/examples/hello_routed_world/src/hello_routed_world.e index a1a83d92..14515018 100644 --- a/examples/hello_routed_world/src/hello_routed_world.e +++ b/examples/hello_routed_world/src/hello_routed_world.e @@ -92,6 +92,7 @@ feature -- Execution s: STRING_8 do l_url := req.script_url ("/home") + n := 3 create h.make h.put_refresh (l_url, 5) @@ -112,7 +113,7 @@ feature -- Execution else s.append ("%NRedirected to " + l_url + " in 1 second :%N") end - write_chunk (s, res); s.wipe_out + res.write_chunk (s); s.wipe_out from i := 1 until @@ -122,26 +123,15 @@ feature -- Execution if i \\ 100 = 0 then s.append_character ('%N') end - write_chunk (s, res); s.wipe_out + res.write_chunk (s); s.wipe_out e.sleep (1_000_000) i := i + 1 end n := n - 1 end s.append ("%NYou are now being redirected...%N") - write_chunk (s, res); s.wipe_out - write_chunk (Void, res) - end - - write_chunk (s: detachable READABLE_STRING_8; res: WSF_RESPONSE) - do - if s /= Void then - res.write_string (s.count.to_hex_string + {HTTP_CONSTANTS}.crlf) - res.write_string (s) - else - res.write_string ("0" + {HTTP_CONSTANTS}.crlf) - end - res.flush + res.write_chunk (s); s.wipe_out + res.write_chunk (Void) end execute_home (ctx: REQUEST_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE) diff --git a/library/server/wsf/src/wsf_response.e b/library/server/wsf/src/wsf_response.e index f88e0363..a3dbbe0a 100644 --- a/library/server/wsf/src/wsf_response.e +++ b/library/server/wsf/src/wsf_response.e @@ -132,6 +132,37 @@ feature -- Output operation wgi_response.write_substring (s, a_begin_index, a_end_index) end + write_chunk (s: detachable READABLE_STRING_8) + -- Write chunk `s' + -- If s is Void, this means this was the final chunk + -- Note: that you should have header + -- "Transfer-Encoding: chunked" + local + hex: STRING + i: INTEGER + do + if s /= Void then + --| Remove all left '0' + hex := s.count.to_hex_string + from + i := 1 + until + hex[i] /= '0' + loop + i := i + 1 + end + if i > 1 then + hex := hex.substring (i, hex.count) + end + write_string (hex + {HTTP_CONSTANTS}.crlf) + write_string (s) + write_string ({HTTP_CONSTANTS}.crlf) + else + write_string ("0" + {HTTP_CONSTANTS}.crlf) + end + flush + end + write_file_content (fn: READABLE_STRING_8) -- Send the content of file `fn' require