Added process directory
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
class GET_REQUEST_HANDLER
|
class
|
||||||
|
GET_REQUEST_HANDLER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
SHARED_DOCUMENT_ROOT
|
SHARED_DOCUMENT_ROOT
|
||||||
|
|
||||||
SHARED_URI_CONTENTS_TYPES
|
SHARED_URI_CONTENTS_TYPES
|
||||||
@@ -10,21 +10,24 @@ inherit
|
|||||||
|
|
||||||
HTTP_CONSTANTS
|
HTTP_CONSTANTS
|
||||||
|
|
||||||
|
create
|
||||||
|
default_create
|
||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
process
|
process
|
||||||
-- process the request and create an answer
|
-- process the request and create an answer
|
||||||
local
|
local
|
||||||
fname: STRING
|
fname: STRING_8
|
||||||
f: RAW_FILE
|
f: RAW_FILE
|
||||||
ctype, extension: STRING
|
ctype, extension: STRING_8
|
||||||
do
|
do
|
||||||
create answer.make
|
create answer.make
|
||||||
if request_uri.is_equal ("/") then
|
if request_uri.is_equal ("/") then
|
||||||
process_default
|
process_default
|
||||||
answer.set_content_type ("text/html")
|
answer.set_content_type ("text/html")
|
||||||
else
|
else
|
||||||
fname := document_root_cell.item.twin
|
fname := Document_root_cell.item.twin
|
||||||
fname.append (request_uri)
|
fname.append (request_uri)
|
||||||
debug
|
debug
|
||||||
print ("URI name: " + fname)
|
print ("URI name: " + fname)
|
||||||
@@ -32,8 +35,11 @@ feature
|
|||||||
create f.make (fname)
|
create f.make (fname)
|
||||||
create answer.make
|
create answer.make
|
||||||
if f.exists then
|
if f.exists then
|
||||||
extension := ct_table.extension (request_uri)
|
extension := Ct_table.extension (request_uri)
|
||||||
ctype := ct_table.content_types.item (extension)
|
ctype := Ct_table.content_types.item (extension)
|
||||||
|
if f.is_directory then
|
||||||
|
process_directory (f)
|
||||||
|
else
|
||||||
if ctype = Void then
|
if ctype = Void then
|
||||||
process_raw_file (f)
|
process_raw_file (f)
|
||||||
answer.set_content_type ("text/html")
|
answer.set_content_type ("text/html")
|
||||||
@@ -45,9 +51,10 @@ feature
|
|||||||
end
|
end
|
||||||
answer.set_content_type (ctype)
|
answer.set_content_type (ctype)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
answer.set_status_code (not_found)
|
answer.set_status_code (Not_found)
|
||||||
answer.set_reason_phrase (not_found_message)
|
answer.set_reason_phrase (Not_found_message)
|
||||||
answer.set_reply_text ("Not found on this server")
|
answer.set_reply_text ("Not found on this server")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -57,22 +64,13 @@ feature
|
|||||||
process_default
|
process_default
|
||||||
-- Return a defaul response
|
-- Return a defaul response
|
||||||
local
|
local
|
||||||
html : STRING
|
html: STRING_8
|
||||||
do
|
do
|
||||||
answer.set_reply_text ("")
|
answer.set_reply_text ("")
|
||||||
html := " <html> <head> <title> NINO HTTPD </title> " +
|
html := " <html> <head> <title> NINO HTTPD </title> " + " </head> " + " <body> " + " <h1> Welcome to NINO HTTPD! </h1> " + " <p> Default page " + " </p> " + " </body> " + " </html> "
|
||||||
" </head> " +
|
|
||||||
" <body> " +
|
|
||||||
" <h1> Welcome to NINO HTTPD! </h1> "+
|
|
||||||
" <p> Default page " +
|
|
||||||
|
|
||||||
" </p> " +
|
|
||||||
" </body> " +
|
|
||||||
" </html> "
|
|
||||||
answer.append_reply_text (html)
|
answer.append_reply_text (html)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
process_text_file (f: FILE)
|
process_text_file (f: FILE)
|
||||||
-- send a text file reply
|
-- send a text file reply
|
||||||
require
|
require
|
||||||
@@ -82,10 +80,11 @@ feature
|
|||||||
from
|
from
|
||||||
answer.set_reply_text ("")
|
answer.set_reply_text ("")
|
||||||
f.read_line
|
f.read_line
|
||||||
until f.end_of_file
|
until
|
||||||
|
f.end_of_file
|
||||||
loop
|
loop
|
||||||
answer.append_reply_text (f.last_string)
|
answer.append_reply_text (f.last_string)
|
||||||
answer.append_reply_text (crlf)
|
answer.append_reply_text (Crlf)
|
||||||
f.read_line
|
f.read_line
|
||||||
end
|
end
|
||||||
f.close
|
f.close
|
||||||
@@ -96,11 +95,11 @@ feature
|
|||||||
require
|
require
|
||||||
valid_f: f /= Void
|
valid_f: f /= Void
|
||||||
do
|
do
|
||||||
-- this is not quite right....
|
|
||||||
f.open_read
|
f.open_read
|
||||||
from
|
from
|
||||||
answer.set_reply_text ("")
|
answer.set_reply_text ("")
|
||||||
until f.end_of_file
|
until
|
||||||
|
f.end_of_file
|
||||||
loop
|
loop
|
||||||
f.read_stream_thread_aware (1024)
|
f.read_stream_thread_aware (1024)
|
||||||
answer.append_reply_text (f.last_string)
|
answer.append_reply_text (f.last_string)
|
||||||
@@ -108,5 +107,39 @@ feature
|
|||||||
f.close
|
f.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
process_directory (f: FILE)
|
||||||
|
--read the directory
|
||||||
|
require
|
||||||
|
is_directory: f.is_directory
|
||||||
|
local
|
||||||
|
l_dir: DIRECTORY
|
||||||
|
files: ARRAYED_LIST [STRING_8]
|
||||||
|
html1: STRING_8
|
||||||
|
html2: STRING_8
|
||||||
|
htmldir: STRING_8
|
||||||
|
path: STRING_8
|
||||||
|
index: INTEGER_32
|
||||||
|
do
|
||||||
|
answer.set_reply_text ("")
|
||||||
|
html1 := " <html> <head> <title> NINO HTTPD </title> " + " </head> " + " <body> " + " <h1> Welcome to NINO HTTPD! </h1> " + " <p> Default page "
|
||||||
|
html2 := " </p> " + " </body> " + " </html> "
|
||||||
|
path := f.name.twin
|
||||||
|
index := path.last_index_of ('/', path.count)
|
||||||
|
path.remove_substring (1, index)
|
||||||
|
create l_dir.make_open_read (f.name)
|
||||||
|
files := l_dir.linear_representation
|
||||||
|
from
|
||||||
|
files.start
|
||||||
|
htmldir := "<ul>"
|
||||||
|
until
|
||||||
|
files.after
|
||||||
|
loop
|
||||||
|
htmldir := htmldir + "<li><a href=%"./" + path + "/" + files.item_for_iteration + "%">" + files.item_for_iteration + "</a> </li>%N"
|
||||||
|
files.forth
|
||||||
end
|
end
|
||||||
|
htmldir := htmldir + "</ul>"
|
||||||
|
answer.append_reply_text (html1 + htmldir + html2)
|
||||||
|
end
|
||||||
|
|
||||||
|
end -- class GET_REQUEST_HANDLER
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user