minor improvements on response_as_result code
This commit is contained in:
@@ -13,12 +13,15 @@ feature {NONE} -- Initialization
|
||||
|
||||
make_and_launch
|
||||
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)
|
||||
end
|
||||
|
||||
port_number: INTEGER = 80
|
||||
port_number: INTEGER
|
||||
|
||||
invariant
|
||||
port_number_valid: port_number > 0
|
||||
note
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
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
|
||||
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_header ("Content-Type", "text/html; charset=utf-8")
|
||||
end
|
||||
|
||||
@@ -31,23 +31,26 @@ feature {NONE} -- Entity body
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
if current_hello >= 100000 then
|
||||
if current_hello >= 10000 then
|
||||
end_of_blocks := True
|
||||
else
|
||||
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
|
||||
from
|
||||
i := 0
|
||||
until
|
||||
i = 10000
|
||||
i = 1000
|
||||
loop
|
||||
current_block.append ("Hello World ("+ current_hello.out +","+ i.out +")<br/>%N")
|
||||
i := i + 1
|
||||
end
|
||||
current_hello := current_hello + i
|
||||
if current_hello = 100000 then
|
||||
current_block.append ("Bye bye..<br/></body></html>")
|
||||
current_block.append ("<div id=%"status%">In progress - "+ (100 * current_hello // 10000).out +"%%</div>")
|
||||
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
|
||||
|
||||
@@ -131,7 +131,8 @@ feature {EWSGI_RESPONSE_APPLICATION} -- Message body
|
||||
-- -- TBD!
|
||||
end
|
||||
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
|
||||
|
||||
last_block: STRING
|
||||
|
||||
Reference in New Issue
Block a user