Using Transfer-Encoding: chunked in example to send response progressively
This commit is contained in:
@@ -69,42 +69,58 @@ feature -- Execution
|
|||||||
e: EXECUTION_ENVIRONMENT
|
e: EXECUTION_ENVIRONMENT
|
||||||
n: INTEGER
|
n: INTEGER
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
|
s: STRING_8
|
||||||
do
|
do
|
||||||
l_url := req.script_url ("/home")
|
l_url := req.script_url ("/home")
|
||||||
n := 3
|
n := 3
|
||||||
create h.make
|
create h.make
|
||||||
h.put_refresh (l_url, 5)
|
h.put_refresh (l_url, 5)
|
||||||
|
h.put_content_type_text_plain
|
||||||
|
h.put_transfer_encoding_chunked
|
||||||
|
-- h.put_content_length (0)
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.moved_permanently)
|
res.set_status_code ({HTTP_STATUS_CODE}.moved_permanently)
|
||||||
res.write_headers_string (h.string)
|
res.write_headers_string (h.string)
|
||||||
|
|
||||||
from
|
from
|
||||||
create e
|
create e
|
||||||
|
create s.make (255)
|
||||||
until
|
until
|
||||||
n = 0
|
n = 0
|
||||||
loop
|
loop
|
||||||
if n > 1 then
|
if n > 1 then
|
||||||
res.write_string ("Redirected to " + l_url + " in " + n.out + " seconds :%N")
|
s.append ("%NRedirected to " + l_url + " in " + n.out + " seconds :%N")
|
||||||
else
|
else
|
||||||
res.write_string ("Redirected to " + l_url + " in 1 second :%N")
|
s.append ("%NRedirected to " + l_url + " in 1 second :%N")
|
||||||
end
|
end
|
||||||
res.flush
|
write_chunk (s, res); s.wipe_out
|
||||||
from
|
from
|
||||||
i := 1
|
i := 1
|
||||||
until
|
until
|
||||||
i = 1001
|
i = 1001
|
||||||
loop
|
loop
|
||||||
res.write_string (".")
|
s.append_character ('.')
|
||||||
if i \\ 100 = 0 then
|
if i \\ 100 = 0 then
|
||||||
res.write_string ("%N")
|
s.append_character ('%N')
|
||||||
end
|
end
|
||||||
res.flush
|
write_chunk (s, res); s.wipe_out
|
||||||
e.sleep (1_000_000)
|
e.sleep (1_000_000)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
res.write_string ("%N")
|
|
||||||
n := n - 1
|
n := n - 1
|
||||||
end
|
end
|
||||||
res.write_string ("You are now being redirected...%N")
|
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: WGI_RESPONSE_BUFFER)
|
||||||
|
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.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ feature -- Server, header
|
|||||||
|
|
||||||
feature -- Misc
|
feature -- Misc
|
||||||
|
|
||||||
|
crlf: STRING = "%R%N"
|
||||||
|
|
||||||
default_bufsize: INTEGER = 16384 --| 16K
|
default_bufsize: INTEGER = 16384 --| 16K
|
||||||
|
|
||||||
note
|
note
|
||||||
|
|||||||
Reference in New Issue
Block a user