Fixed WSF_REQUEST.script_url (..) for clean path

Added related autotests
This commit is contained in:
Jocelyn Fiat
2012-01-19 10:25:53 +01:00
parent 4cf3393a13
commit 1b55b09b64
11 changed files with 399 additions and 5 deletions

View File

@@ -0,0 +1,10 @@
${NOTE_KEYWORD}
copyright: "2011-${YEAR}, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="connector_cgi" uuid="3BCBC1C5-9D99-45BB-B15D-B03D2C069CED" library_target="connector_cgi">
<target name="connector_cgi">
<root all_classes="true"/>
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/\.git$</exclude>
<exclude>/\.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
<library name="http" location="..\..\..\..\protocol\http\http-safe.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="connector_cgi" uuid="3BCBC1C5-9D99-45BB-B15D-B03D2C069CED" library_target="connector_cgi">
<target name="connector_cgi">
<root all_classes="true"/>
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/\.git$</exclude>
<exclude>/\.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="ewsgi" location="..\..\ewsgi.ecf" readonly="false"/>
<library name="http" location="..\..\..\..\protocol\http\http.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,74 @@
note
description: "Summary description for {WGI_NULL_CONNECTOR}."
date: "$Date$"
revision: "$Revision$"
class
WGI_NULL_CONNECTOR
inherit
WGI_CONNECTOR
create
make
feature {NONE} -- Initialization
make (a_service: like service)
do
service := a_service
end
feature -- Access
Name: STRING_8 = "NULL"
-- Name of Current connector
Version: STRING_8 = "0.1"
-- Version of Current connector
feature {NONE} -- Access
service: WGI_SERVICE
-- Gateway Service
feature -- Execution
launch
local
req: WGI_REQUEST_FROM_TABLE
res: detachable WGI_RESPONSE_STREAM
rescued: BOOLEAN
do
if not rescued then
create req.make ((create {EXECUTION_ENVIRONMENT}).starting_environment_variables, create {WGI_NULL_INPUT_STREAM}.make, Current)
create res.make (create {WGI_NULL_OUTPUT_STREAM}.make)
service.execute (req, res)
else
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.exception_trace as l_trace then
if res /= Void then
if not res.status_is_set then
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
end
if res.message_writable then
res.put_string ("<pre>" + l_trace + "</pre>")
end
end
end
end
rescue
rescued := True
retry
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,44 @@
note
description: "Summary description for WGI_NULL_INPUT_STREAM."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
WGI_NULL_INPUT_STREAM
inherit
WGI_INPUT_STREAM
undefine
read_to_string
end
CONSOLE
rename
make as console_make,
read_stream as read_string,
end_of_file as end_of_input
end
create
make
feature {NONE} -- Initialization
make
do
make_open_stdin ("stdin")
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,80 @@
note
description: "Summary description for WGI_NULL_OUTPUT_STREAM."
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
WGI_NULL_OUTPUT_STREAM
inherit
WGI_OUTPUT_STREAM
rename
put_string as put_readable_string_8
end
CONSOLE
rename
make as console_make
end
HTTP_STATUS_CODE_MESSAGES
export
{NONE} all
end
create
make
feature {NONE} -- Initialization
make
do
make_open_stdout ("stdout")
end
feature -- Status writing
put_status_line (a_code: INTEGER)
-- Put status code line for `a_code'
--| Note this is a default implementation, and could be redefined
--| for instance in relation to NPH NULL script
local
s: STRING
do
if a_code /= 200 then
create s.make (16)
s.append ("Status:")
s.append_character (' ')
s.append_integer (a_code)
if attached http_status_code_message (a_code) as l_status_message then
s.append_character (' ')
s.append_string (l_status_message)
end
put_header_line (s)
end
end
put_readable_string_8 (s: READABLE_STRING_8)
-- Write `s' at end of default output.
local
ext: C_STRING
do
if s.count > 0 then
create ext.make (s)
console_ps (file_pointer, ext.managed_data.item, s.count)
end
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -1202,7 +1202,7 @@ feature -- URL Utility
-- Url relative to script name if any, extended by `a_path'
local
l_base_url: like internal_url_base
i,m,n: INTEGER
i,m,n,spos: INTEGER
l_rq_uri: like request_uri
do
l_base_url := internal_url_base
@@ -1220,16 +1220,26 @@ feature -- URL Utility
until
i > m or i > n or l_rq_uri[i] /= l_script_name[i]
loop
if l_rq_uri[i] = '/' then
spos := i
end
i := i + 1
end
if i > 1 then
if l_rq_uri[i-1] = '/' then
i := i -1
elseif spos > 0 then
i := spos
end
spos := l_rq_uri.substring_index (path_info, i)
if spos > 0 then
l_base_url := l_rq_uri.substring (1, spos - 1)
else
l_base_url := l_rq_uri.substring (1, i - 1)
end
end
end
end
if l_base_url = Void then
create l_base_url.make_empty
end

View File

@@ -0,0 +1,91 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
TEST_WSF_REQUEST_SCRIPT_URL
inherit
EQA_TEST_SET
WSF_SERVICE
undefine
default_create
end
feature {NONE} -- Events
port_number: INTEGER
base_url: detachable STRING
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
--| do nothing
end
feature -- Tests
test_script_url
local
req: WSF_REQUEST
s: READABLE_STRING_8
do
--| Case #1
req := new_request (<<
["REQUEST_METHOD", "GET"],
["QUERY_STRING", ""],
["REQUEST_URI", "/foo/bar/test/home"],
["SCRIPT_NAME", "/foo/bar/app.ext"],
["PATH_INFO", "/test/home"]
>>
)
s := req.script_url ("/new/path/")
assert ("script_url (/new/path/) = %""+s+"%" but should be %"/foo/bar/new/path/%"", s.same_string ("/foo/bar/new/path/"))
--| Case #2
req := new_request (<<
["REQUEST_METHOD", "GET"],
["QUERY_STRING", ""],
["REQUEST_URI", "/foo/bar/abc/DEF"],
["SCRIPT_NAME", "/foo/bar/app.ext"],
["PATH_INFO", "/abc/DEF"]
>>
)
s := req.script_url ("/new/path/")
assert ("script_url (/new/path/) = %""+s+"%" but should be %"/foo/bar/new/path/%"", s.same_string ("/foo/bar/new/path/"))
--| Case #3
req := new_request (<<
["REQUEST_METHOD", "GET"],
["QUERY_STRING", ""],
["REQUEST_URI", "/intranet/collab/cms/home"],
["SCRIPT_NAME", "/intranet/collab/collab.ews"],
["PATH_INFO", "/home"]
>>
)
s := req.script_url ("/new/path/")
assert ("script_url (/new/path/) = %""+s+"%" but should be %"/intranet/collab/cms/new/path/%"", s.same_string ("/intranet/collab/cms/new/path/"))
end
feature {NONE} -- Implementation
new_request (a_meta: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]): WSF_REQUEST
local
wgi_req: WGI_REQUEST
req: WSF_REQUEST
do
create {WGI_REQUEST_NULL} wgi_req.make (Current, a_meta)
create Result.make_from_wgi (wgi_req)
end
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WGI_REQUEST_NULL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WGI_REQUEST_NULL
inherit
WGI_REQUEST_FROM_TABLE
rename
make as wgi_request_from_table_make
end
create
make
feature {NONE} -- Initialization
make (s: WSF_SERVICE; a_meta: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]])
local
ht: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
i: WGI_NULL_INPUT_STREAM
c: WGI_NULL_CONNECTOR
do
create c.make (s)
create i.make
create ht.make (a_meta.count)
across
a_meta as curs
loop
ht.force (curs.item.value, curs.item.name)
end
wgi_request_from_table_make (ht, i, c)
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="wsf_tests" uuid="CA72F5B3-E608-4FA5-8F05-A812441DB961">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="wsf_tests" uuid="CA72F5B3-E608-4FA5-8F05-A812441DB961">
<target name="tests">
<root class="ANY" feature="default_create"/>
<file_rule>
@@ -7,16 +7,18 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="provisional">
<option warning="true" full_class_checking="true" is_attached_by_default="false" void_safety="none" syntax="provisional">
</option>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="connector_nino" location="..\..\ewsgi\connectors\nino\nino.ecf" readonly="false"/>
<library name="connector_null" location="..\..\ewsgi\connectors\null\null.ecf" readonly="false"/>
<library name="dft_nino" location="..\default\nino.ecf"/>
<library name="ewsgi" location="..\..\ewsgi\ewsgi.ecf"/>
<library name="http_client" location="..\..\..\client\http_client\http_client.ecf"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread.ecf"/>
<library name="wsf" location="..\wsf.ecf"/>
<library name="wsf" location="..\wsf.ecf" readonly="false"/>
<tests name="src" location=".\src\" recursive="true"/>
</target>
</system>