Better CGI handler
- improvement related to current directory for the execution of the CGI script, - and updated SCRIPT_NAME, to the path info is correctly computed.
This commit is contained in:
@@ -16,35 +16,79 @@ feature {NONE} -- Creation
|
|||||||
|
|
||||||
make (a_dir: PATH)
|
make (a_dir: PATH)
|
||||||
do
|
do
|
||||||
working_direction := a_dir
|
working_directory := a_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Settings
|
feature -- Settings
|
||||||
|
|
||||||
buffer_size: INTEGER = 1_024
|
buffer_size: INTEGER = 1_024
|
||||||
|
|
||||||
working_direction: PATH
|
working_directory: PATH
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
cgi_file_path (req: WSF_REQUEST): PATH
|
cgi_request_data (req: WSF_REQUEST): TUPLE [location: PATH; script_name: READABLE_STRING_8; path_info: READABLE_STRING_8]
|
||||||
local
|
local
|
||||||
l_path_info: READABLE_STRING_32
|
l_path_info, l_scriptname: STRING_32
|
||||||
|
fut: FILE_UTILITIES
|
||||||
|
r,p,pp: PATH
|
||||||
|
enc: PERCENT_ENCODER
|
||||||
|
wc: INTEGER
|
||||||
do
|
do
|
||||||
-- Path to CGI executable.
|
-- Path to CGI executable.
|
||||||
l_path_info := req.path_info
|
l_path_info := req.path_info
|
||||||
if l_path_info.starts_with_general ("/") then
|
if l_path_info.starts_with_general ("/") then
|
||||||
l_path_info := l_path_info.substring (2, l_path_info.count)
|
r := working_directory.extended (l_path_info.substring (2, l_path_info.count))
|
||||||
|
else
|
||||||
|
r := working_directory.extended (l_path_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Process
|
from
|
||||||
Result := working_direction.extended (l_path_info)
|
p := r
|
||||||
|
until
|
||||||
|
p = Void or else fut.file_path_exists (p)
|
||||||
|
loop
|
||||||
|
pp := p.parent
|
||||||
|
if not p.same_as (pp) then
|
||||||
|
p := pp
|
||||||
|
else
|
||||||
|
p := Void
|
||||||
|
end
|
||||||
|
end
|
||||||
|
create enc
|
||||||
|
wc := working_directory.name.count
|
||||||
|
if p = Void then
|
||||||
|
p := r
|
||||||
|
l_path_info := ""
|
||||||
|
else
|
||||||
|
l_path_info := r.name
|
||||||
|
l_path_info.remove_head (wc + 1)
|
||||||
|
end
|
||||||
|
l_scriptname := p.name
|
||||||
|
l_scriptname.remove_head (wc + 1)
|
||||||
|
l_path_info.remove_head (l_scriptname.count + 1)
|
||||||
|
|
||||||
|
Result := [p, to_percent_encoded_uri (l_scriptname), to_percent_encoded_uri (l_path_info)]
|
||||||
end
|
end
|
||||||
|
|
||||||
exists (req: WSF_REQUEST): BOOLEAN
|
to_percent_encoded_uri (s: READABLE_STRING_32): STRING_8
|
||||||
-- CGI file exists?
|
local
|
||||||
|
enc: PERCENT_ENCODER
|
||||||
|
p: PATH
|
||||||
do
|
do
|
||||||
Result := (create {FILE_UTILITIES}).file_path_exists (cgi_file_path (req))
|
if s.is_empty then
|
||||||
|
Result := ""
|
||||||
|
else
|
||||||
|
create p.make_from_string (s)
|
||||||
|
create Result.make (s.count)
|
||||||
|
create enc
|
||||||
|
across
|
||||||
|
p.components as ic
|
||||||
|
loop
|
||||||
|
Result.append_character ('/')
|
||||||
|
enc.append_percent_encoded_string_to (ic.item.name, Result)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Execution
|
feature -- Execution
|
||||||
@@ -53,7 +97,6 @@ feature -- Execution
|
|||||||
-- Execute `req' responding in `res'.
|
-- Execute `req' responding in `res'.
|
||||||
local
|
local
|
||||||
fut: FILE_UTILITIES
|
fut: FILE_UTILITIES
|
||||||
l_exec_path: PATH
|
|
||||||
proc: BASE_PROCESS
|
proc: BASE_PROCESS
|
||||||
l_input_env: STRING_TABLE [READABLE_STRING_GENERAL]
|
l_input_env: STRING_TABLE [READABLE_STRING_GENERAL]
|
||||||
l_input_header: detachable STRING
|
l_input_header: detachable STRING
|
||||||
@@ -85,11 +128,15 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
-- No need to import `l_input_header` in environment
|
-- No need to import `l_input_header` in environment
|
||||||
-- As current connector already did the job.
|
-- As current connector already did the job.
|
||||||
|
if
|
||||||
|
attached cgi_request_data (req) as d and then
|
||||||
|
fut.file_path_exists (d.location)
|
||||||
|
then
|
||||||
|
l_input_env.force (d.script_name, "SCRIPT_NAME")
|
||||||
|
l_input_env.force (d.path_info, "PATH_INFO")
|
||||||
|
|
||||||
-- Process
|
-- Process
|
||||||
l_exec_path := cgi_file_path (req)
|
proc := (create {BASE_PROCESS_FACTORY}).process_launcher (d.location.name, Void, working_directory.name)
|
||||||
if fut.file_path_exists (l_exec_path) then
|
|
||||||
proc := (create {BASE_PROCESS_FACTORY}).process_launcher (l_exec_path.name, Void, working_direction.name)
|
|
||||||
proc.set_hidden (True)
|
proc.set_hidden (True)
|
||||||
proc.set_environment_variable_table (l_input_env)
|
proc.set_environment_variable_table (l_input_env)
|
||||||
proc.set_separate_console (False)
|
proc.set_separate_console (False)
|
||||||
@@ -225,7 +272,7 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
copyright: "2011-2019, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
Reference in New Issue
Block a user