minor improvements on response_as_result code
This commit is contained in:
@@ -13,12 +13,15 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make_and_launch
|
make_and_launch
|
||||||
do
|
do
|
||||||
print ("Example: start a Nino web server on port " + port_number.out + ", %Nand reply Hello World for any request such as http://localhost:8123/%N")
|
port_number := 80
|
||||||
|
print ("Example: start a Nino web server on port " + port_number.out + ", %Nand reply Hello World for any request such as http://localhost:" + port_number.out + "/%N")
|
||||||
(create {NINO_APPLICATION}.make_custom (agent execute, "")).listen (port_number)
|
(create {NINO_APPLICATION}.make_custom (agent execute, "")).listen (port_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
port_number: INTEGER = 80
|
port_number: INTEGER
|
||||||
|
|
||||||
|
invariant
|
||||||
|
port_number_valid: port_number > 0
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2011, 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)"
|
||||||
|
|||||||
@@ -19,7 +19,19 @@ feature -- Response
|
|||||||
|
|
||||||
response (request: EWSGI_REQUEST): EWSGI_RESPONSE
|
response (request: EWSGI_REQUEST): EWSGI_RESPONSE
|
||||||
do
|
do
|
||||||
create {HELLO_WORLD_RESPONSE} Result.make
|
if request.environment.path_info.starts_with ("/streaming/") then
|
||||||
|
Result := streaming_response (request)
|
||||||
|
else
|
||||||
|
create Result.make
|
||||||
|
Result.set_status (200)
|
||||||
|
Result.set_header ("Content-Type", "text/html; charset=utf-8")
|
||||||
|
Result.set_message_body ("<html><body>Hello World</body></html>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
streaming_response (request: EWSGI_REQUEST): EWSGI_RESPONSE
|
||||||
|
do
|
||||||
|
create {HELLO_WORLD_RESPONSE} Result.make
|
||||||
Result.set_status (200)
|
Result.set_status (200)
|
||||||
Result.set_header ("Content-Type", "text/html; charset=utf-8")
|
Result.set_header ("Content-Type", "text/html; charset=utf-8")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,23 +31,26 @@ feature {NONE} -- Entity body
|
|||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
if current_hello >= 100000 then
|
if current_hello >= 10000 then
|
||||||
end_of_blocks := True
|
end_of_blocks := True
|
||||||
else
|
else
|
||||||
if current_hello = 0 then
|
if current_hello = 0 then
|
||||||
current_block := "<html><body>%N"
|
current_block := "<html><style>div#status {position: absolute; top: 30%%; left: 40%%; border: red solid 1px; padding: 10px; background-color: #ffcccc;}</style><body>%N"
|
||||||
|
current_block.append ("<a name=%"top%">Welcome</a><br/><div id=%"status%">In progress</div>")
|
||||||
end
|
end
|
||||||
from
|
from
|
||||||
i := 0
|
i := 0
|
||||||
until
|
until
|
||||||
i = 10000
|
i = 1000
|
||||||
loop
|
loop
|
||||||
current_block.append ("Hello World ("+ current_hello.out +","+ i.out +")<br/>%N")
|
current_block.append ("Hello World ("+ current_hello.out +","+ i.out +")<br/>%N")
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
current_hello := current_hello + i
|
current_hello := current_hello + i
|
||||||
if current_hello = 100000 then
|
current_block.append ("<div id=%"status%">In progress - "+ (100 * current_hello // 10000).out +"%%</div>")
|
||||||
current_block.append ("Bye bye..<br/></body></html>")
|
if current_hello = 10000 then
|
||||||
|
current_block.append ("<a name=%"bottom%">Bye bye..</a><br/><div id=%"status%">Completed - GO TO <a href=%"#bottom%">BOTTOM</a></div></body></html>")
|
||||||
|
end_of_blocks := True
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -131,7 +131,8 @@ feature {EWSGI_RESPONSE_APPLICATION} -- Message body
|
|||||||
-- -- TBD!
|
-- -- TBD!
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
not is_buffered implies last_block.count <= max_block_size
|
--Commented, since it is far from obvious to ensure that:
|
||||||
|
-- not is_buffered implies last_block.count <= max_block_size
|
||||||
end
|
end
|
||||||
|
|
||||||
last_block: STRING
|
last_block: STRING
|
||||||
|
|||||||
Reference in New Issue
Block a user