Test simple_file with different sizes.

This commit is contained in:
Jocelyn Fiat
2017-04-13 15:01:34 +02:00
parent 72abb87d75
commit 0c365ca162
2 changed files with 55 additions and 1 deletions

View File

@@ -7,7 +7,12 @@
<h1>EWF simple_file example</h1> <h1>EWF simple_file example</h1>
<p>This is a static html file served by EWF.</p> <p>This is a static html file served by EWF.</p>
<p>Try to <a href="nowhere.html">get lost</a>.</p> <p>Try to <a href="nowhere.html">get lost</a>.</p>
<a href="ewf.png"><img src="ewf.png"/></a> <li><a href="ewf.png"><img src="ewf.png"/></a><li>
<li><a href="big.png">see big.png</a><li>
<li><a href="huge.png">see huge.png</a><li>
<li><a href="5mb.txt">see 5mb.txt</a><li>
<li><a href="10mb.txt">see 10mb.txt</a><li>
<li><a href="100mb.txt">see 100mb.txt</a><li>
</body> </body>
</html> </html>

View File

@@ -18,11 +18,31 @@ feature {NONE} -- Initialization
local local
mesg: WSF_RESPONSE_MESSAGE mesg: WSF_RESPONSE_MESSAGE
not_found: WSF_NOT_FOUND_RESPONSE not_found: WSF_NOT_FOUND_RESPONSE
s: STRING
n: INTEGER
do do
if request.path_info.is_case_insensitive_equal_general ("/") then if request.path_info.is_case_insensitive_equal_general ("/") then
create {WSF_FILE_RESPONSE} mesg.make_html ("home.html") create {WSF_FILE_RESPONSE} mesg.make_html ("home.html")
elseif request.path_info.is_case_insensitive_equal_general ("/ewf.png") then elseif request.path_info.is_case_insensitive_equal_general ("/ewf.png") then
create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.image_png ,"ewf.png") create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.image_png ,"ewf.png")
elseif request.path_info.is_case_insensitive_equal_general ("/big.png") then
create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.image_png ,"big.png")
elseif request.path_info.is_case_insensitive_equal_general ("/huge.png") then
create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.image_png ,"huge.png")
elseif request.path_info.ends_with_general ("mb.txt") then
s := request.path_info
s.remove_head (1)
s.remove_tail (6)
if s.is_integer then
n := s.to_integer
end
build_txt_file (n)
create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.text_plain , n.out + "mb.txt")
-- elseif request.path_info.is_case_insensitive_equal_general ("/5mb.txt") then
-- create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.text_plain ,"5mb.txt")
-- elseif request.path_info.is_case_insensitive_equal_general ("/10mb.txt") then
-- create {WSF_FILE_RESPONSE} mesg.make_with_content_type ({HTTP_MIME_TYPES}.text_plain ,"10mb.txt")
else else
create not_found.make (request) create not_found.make (request)
not_found.add_suggested_location (request.absolute_script_url (""), "Home", "Back to home page") not_found.add_suggested_location (request.absolute_script_url (""), "Home", "Back to home page")
@@ -32,4 +52,33 @@ feature {NONE} -- Initialization
response.send (mesg) response.send (mesg)
end end
build_txt_file (a_nb_mb: INTEGER)
local
f: RAW_FILE
i: INTEGER
s: STRING
do
create f.make_with_name (a_nb_mb.out + "mb.txt")
if not f.exists then
f.create_read_write
from
i := 1
until
i > 10_000 * a_nb_mb
loop
s := i.out
from
until
s.count >= 9
loop
s.prepend_character ('_')
end
f.put_string (s)
f.put_string (":01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678%N")
i := i + 1
end
f.close
end
end
end end