Implemented support for base url in httpd connector.

This commit is contained in:
2015-03-25 22:22:57 +01:00
parent b4a9c92ffc
commit 7d2ce8a77f
19 changed files with 168 additions and 198 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-12-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-12-0 http://www.eiffel.com/developers/xml/configuration-1-12-0.xsd" name="connector_cgi" uuid="3BCBC1C5-9D99-45BB-B15D-B03D2C069CED" library_target="connector_cgi">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-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>
@@ -12,6 +12,7 @@
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
<library name="http" location="..\..\..\..\network\protocol\http\http-safe.ecf"/>
<library name="encoder" location="..\..\..\..\text\encoder\encoder-safe.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -12,6 +12,7 @@
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="ewsgi" location="..\..\ewsgi.ecf" readonly="false"/>
<library name="http" location="../../../../network/protocol/http/http.ecf"/>
<library name="encoder" location="..\..\..\..\text\encoder\encoder.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -9,6 +9,10 @@ class
inherit
WGI_CONNECTOR
SHARED_HTML_ENCODER
SHARED_EXECUTION_ENVIRONMENT
feature -- Access
Name: STRING_8 = "CGI"
@@ -27,27 +31,14 @@ feature -- Execution
rescued: BOOLEAN
do
if not rescued then
create req.make ((create {EXECUTION_ENVIRONMENT}).starting_environment, create {WGI_CGI_INPUT_STREAM}.make, Current)
create req.make (execution_environment.starting_environment, create {WGI_CGI_INPUT_STREAM}.make, Current)
create res.make (create {WGI_CGI_OUTPUT_STREAM}.make, create {WGI_CGI_ERROR_STREAM}.make)
create {G} exec.make (req, res)
exec.execute
res.flush
res.push
exec.clean
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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (l_trace)
res.put_string ("</pre>")
end
res.push
end
end
process_rescue (res)
if exec /= Void then
exec.clean
end
@@ -59,6 +50,23 @@ feature -- Execution
end
end
process_rescue (res: detachable WGI_RESPONSE)
do
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (html_encoder.encoded_string (l_trace))
res.put_string ("</pre>")
end
res.push
end
end
end
note
copyright: "2011-2015, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -16,55 +16,7 @@
<library name="encoder" location="..\..\..\..\text\encoder\encoder-safe.ecf"/>
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
<library name="http" location="..\..\..\..\network\protocol\http\http-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf">
<option>
<assertions precondition="true" postcondition="true" check="true"/>
</option>
</library>
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl-safe.ecf">
<condition>
<custom name="httpd_ssl_enabled" value="true"/>
</condition>
</library>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf">
<condition>
<concurrency excluded_value="none"/>
</condition>
</library>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<cluster name="httpd_server" location=".\src\httpd\" recursive="true">
<file_rule>
<exclude>/ssl$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/no_ssl$</exclude>
<exclude>/concurrency$</exclude>
</file_rule>
<cluster name="no_ssl" location="$|no_ssl\" recursive="true">
<condition>
<custom name="httpd_ssl_enabled" excluded_value="true"/>
</condition>
</cluster>
<cluster name="ssl" location="$|ssl\" recursive="true">
<condition>
<custom name="httpd_ssl_enabled" value="true"/>
</condition>
</cluster>
<cluster name="concurrency_none" location="$|concurrency\none\" recursive="true">
<condition>
<concurrency value="none"/>
</condition>
</cluster>
<cluster name="concurrency_thread" location="$|concurrency\thread\" recursive="true">
<condition>
<concurrency value="thread"/>
</condition>
</cluster>
<cluster name="concurrency_scoop" location="$|concurrency\scoop\" recursive="true">
<condition>
<concurrency value="scoop"/>
</condition>
</cluster>
</cluster>
<library name="httpd" location="src\httpd\httpd-safe.ecf"/>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/httpd$</exclude>

View File

@@ -10,9 +10,8 @@
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="all" syntax="standard">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="concurrency" value="thread"/>
<setting name="concurrency" value="scoop"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl-safe.ecf">
<condition>

View File

@@ -46,7 +46,7 @@ feature {NONE} -- Initialization
set_base (a_base)
end
set_factory_connector (conn: detachable separate WGI_CONNECTOR; fac: separate WGI_HTTPD_REQUEST_HANDLER_FACTORY [G])
set_factory_connector (conn: detachable separate WGI_HTTPD_CONNECTOR [G]; fac: separate WGI_HTTPD_REQUEST_HANDLER_FACTORY [G])
do
fac.set_connector (conn)
end
@@ -129,8 +129,15 @@ feature -- Element change
end
set_max_concurrent_connections (nb: INTEGER)
require
nb_positive_or_zero: nb >= 0
do
set_max_concurrent_connections_on_configuration (nb, configuration)
end
set_is_verbose (b: BOOLEAN)
do
set_is_verbose_on_configuration (b, configuration)
end
feature {NONE} -- Implementation
@@ -145,6 +152,11 @@ feature {NONE} -- Implementation
cfg.set_max_concurrent_connections (nb)
end
set_is_verbose_on_configuration (b: BOOLEAN; cfg: like configuration)
do
cfg.set_is_verbose (b)
end
feature -- Server
launch

View File

@@ -14,6 +14,8 @@ inherit
REFACTORING_HELPER
SHARED_HTML_ENCODER
create
make,
make_with_connector
@@ -26,7 +28,21 @@ feature {NONE} -- Initialization
connector := conn
end
connector: detachable separate WGI_CONNECTOR
connector: detachable separate WGI_HTTPD_CONNECTOR [G]
base: detachable IMMUTABLE_STRING_8
do
if attached connector as conn then
if attached connector_base (conn) as l_base then
create Result.make_from_separate (l_base)
end
end
end
connector_base (conn: separate WGI_HTTPD_CONNECTOR [G]): detachable separate READABLE_STRING_8
do
Result := conn.base
end
feature -- Request processing
@@ -53,23 +69,10 @@ feature -- Request processing
create {G} exec.make (req, res)
exec.execute
res.flush
res.push
exec.clean
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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (l_trace)
res.put_string ("</pre>")
end
res.push
end
end
process_rescue (res)
if exec /= Void then
exec.clean
end
@@ -81,10 +84,21 @@ feature -- Request processing
end
end
base: detachable READABLE_STRING_8
process_rescue (res: detachable WGI_RESPONSE)
do
--TODO
to_implement ("Base url support")
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (html_encoder.encoded_string (l_trace))
res.put_string ("</pre>")
end
res.push
end
end
end
httpd_environment (a_socket: HTTPD_STREAM_SOCKET): STRING_TABLE [READABLE_STRING_8]
@@ -93,6 +107,7 @@ feature -- Request processing
l_request_uri, l_script_name, l_query_string, l_path_info: STRING
l_server_name, l_server_port: detachable STRING
l_headers_map: HASH_TABLE [STRING, STRING]
l_base: detachable READABLE_STRING_8
vn: STRING
e: EXECUTION_ENVIRONMENT
@@ -189,7 +204,11 @@ feature -- Request processing
set_environment_variable ({HTTPD_CONFIGURATION}.Server_details, "SERVER_SOFTWARE", Result)
--| Apply `base' value
if attached base as l_base and then l_request_uri /= Void then
l_base := base
if l_base = Void then
l_base := ""
end
if l_request_uri /= Void then
if l_request_uri.starts_with (l_base) then
l_path_info := l_request_uri.substring (l_base.count + 1, l_request_uri.count)
p := l_path_info.index_of ('?', 1)

View File

@@ -12,7 +12,7 @@ inherit
feature -- Access
connector: detachable separate WGI_CONNECTOR
connector: detachable separate WGI_HTTPD_CONNECTOR [G]
feature -- Element change

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-11-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-11-0 http://www.eiffel.com/developers/xml/configuration-1-11-0.xsd" name="connector_libfcgi" uuid="59C57E56-3EE6-4EF7-873F-7ED084B0EB22" library_target="connector_libfcgi">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="connector_libfcgi" uuid="59C57E56-3EE6-4EF7-873F-7ED084B0EB22" library_target="connector_libfcgi">
<target name="connector_libfcgi">
<root all_classes="true"/>
<file_rule>
@@ -13,6 +13,7 @@
<library name="ewsgi" location="..\..\ewsgi-safe.ecf"/>
<library name="http" location="..\..\..\..\network\protocol\http\http-safe.ecf"/>
<library name="libfcgi" location="..\..\..\libfcgi\libfcgi-safe.ecf"/>
<library name="encoder" location="..\..\..\..\text\encoder\encoder-safe.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -13,6 +13,7 @@
<library name="ewsgi" location="..\..\ewsgi.ecf" readonly="false"/>
<library name="libfcgi" location="..\..\..\libfcgi\libfcgi.ecf" />
<library name="http" location="../../../../network/protocol/http/http.ecf"/>
<library name="encoder" location="..\..\..\..\text\encoder\encoder.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -14,11 +14,16 @@ inherit
default_create
end
SHARED_HTML_ENCODER
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
Precursor
Precursor {WGI_CONNECTOR}
create fcgi.make
create input.make (fcgi)
create output.make (fcgi)
@@ -63,23 +68,10 @@ feature -- Execution
create res.make (a_output, a_output)
create {G} exec.make (req, res)
exec.execute
res.flush
res.push
exec.clean
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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (l_trace)
res.put_string ("</pre>")
end
res.push
end
end
process_rescue (res)
if exec /= Void then
exec.clean
end
@@ -90,6 +82,23 @@ feature -- Execution
retry
end
end
process_rescue (res: detachable WGI_RESPONSE)
do
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (html_encoder.encoded_string (l_trace))
res.put_string ("</pre>")
end
res.push
end
end
end
feature -- Input/Output

View File

@@ -9,18 +9,18 @@ class
inherit
WGI_CONNECTOR
SHARED_HTML_ENCODER
create
make,
make_with_base
feature {NONE} -- Initialization
make --(a_service: like service)
make
local
cfg: HTTP_SERVER_CONFIGURATION
do
-- service := a_service
create cfg.make
create server.make (cfg)
@@ -45,11 +45,6 @@ feature -- Access
version: STRING_8 = "0.1"
-- Version of Current connector
--feature {NONE} -- Access
-- service: WGI_SERVICE
-- -- Gateway Service
feature -- Access
server: HTTP_SERVER
@@ -142,23 +137,10 @@ feature -- Server
create {G} exec.make (req, res)
exec.execute
res.flush
res.push
exec.clean
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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (l_trace)
res.put_string ("</pre>")
end
res.push
end
end
process_rescue (res)
if exec /= Void then
exec.clean
end
@@ -170,6 +152,23 @@ feature -- Server
end
end
process_rescue (res: detachable WGI_RESPONSE)
do
if attached (create {EXCEPTION_MANAGER}).last_exception as e and then attached e.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, Void)
end
if res.message_writable then
res.put_string ("<pre>")
res.put_string (html_encoder.encoded_string (l_trace))
res.put_string ("</pre>")
end
res.push
end
end
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -30,7 +30,15 @@ feature -- Execution
-- Execute the request based on `request' and `response'.
deferred
ensure
status_is_set: response.status_is_set
is_valid_end_of_execution: is_valid_end_of_execution
end
feature -- Status report
is_valid_end_of_execution: BOOLEAN
-- Last `execute' completed in valid state?
do
Result := True
end
feature -- Cleaning
@@ -40,6 +48,11 @@ feature -- Cleaning
do
end
invariant
wgi_request_set: request /= Void
wgi_response_set: response /= Void
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"