First integration of the new GW_ design more centralized on connector, and does not require specific feature on GW_APPLICATION depending on the connector.
So this is really more flexible this way, and much easier to write application supporting CGI, FCGI, Nino and so on .. as demonstrated in hello_world This is a first version, more will come later, mainly migrating from Eiffel Web Reloaded to this Eiffel Web Framework project.
This commit is contained in:
9
library/server/ewsgi/COPYRIGHT
Normal file
9
library/server/ewsgi/COPYRIGHT
Normal file
@@ -0,0 +1,9 @@
|
||||
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
|
||||
|
||||
16
library/server/ewsgi/connectors/cgi/cgi-safe.ecf
Normal file
16
library/server/ewsgi/connectors/cgi/cgi-safe.ecf
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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"/>
|
||||
<cluster name="src" location=".\src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
16
library/server/ewsgi/connectors/cgi/cgi.ecf
Normal file
16
library/server/ewsgi/connectors/cgi/cgi.ecf
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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"/>
|
||||
<cluster name="src" location=".\src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
1
library/server/ewsgi/connectors/cgi/license.lic
Normal file
1
library/server/ewsgi/connectors/cgi/license.lic
Normal file
@@ -0,0 +1 @@
|
||||
reference:forum2
|
||||
36
library/server/ewsgi/connectors/cgi/src/gw_cgi_connector.e
Normal file
36
library/server/ewsgi/connectors/cgi/src/gw_cgi_connector.e
Normal file
@@ -0,0 +1,36 @@
|
||||
note
|
||||
description: "Summary description for {GW_CGI_CONNECTOR}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_CGI_CONNECTOR
|
||||
|
||||
inherit
|
||||
GW_CONNECTOR
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Execution
|
||||
|
||||
launch
|
||||
local
|
||||
env: GW_ENVIRONMENT_VARIABLES
|
||||
do
|
||||
create env.make_with_variables ((create {EXECUTION_ENVIRONMENT}).starting_environment_variables)
|
||||
application.process (env, create {GW_CGI_INPUT_STREAM}.make, create {GW_CGI_OUTPUT_STREAM}.make)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
@@ -0,0 +1,39 @@
|
||||
note
|
||||
description: "Summary description for GW_CGI_INPUT_STREAM."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_CGI_INPUT_STREAM
|
||||
|
||||
inherit
|
||||
GW_INPUT_STREAM
|
||||
|
||||
CONSOLE
|
||||
rename
|
||||
make as console_make
|
||||
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
|
||||
@@ -0,0 +1,39 @@
|
||||
note
|
||||
description: "Summary description for GW_CGI_OUTPUT_STREAM."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_CGI_OUTPUT_STREAM
|
||||
|
||||
inherit
|
||||
GW_OUTPUT_STREAM
|
||||
|
||||
CONSOLE
|
||||
rename
|
||||
make as console_make
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
make_open_stdout ("stdout")
|
||||
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
|
||||
17
library/server/ewsgi/connectors/libfcgi/libfcgi-safe.ecf
Normal file
17
library/server/ewsgi/connectors/libfcgi/libfcgi-safe.ecf
Normal 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_libfcgi" uuid="59C57E56-3EE6-4EF7-873F-7ED084B0EB22" library_target="connector_libfcgi">
|
||||
<target name="connector_libfcgi">
|
||||
<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="libfcgi" location="..\..\..\libfcgi\libfcgi-safe.ecf" />
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
17
library/server/ewsgi/connectors/libfcgi/libfcgi.ecf
Normal file
17
library/server/ewsgi/connectors/libfcgi/libfcgi.ecf
Normal 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_libfcgi" uuid="59C57E56-3EE6-4EF7-873F-7ED084B0EB22" library_target="connector_libfcgi">
|
||||
<target name="connector_libfcgi">
|
||||
<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="libfcgi" location="..\..\libfcgi\libfcgi.ecf" />
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
1
library/server/ewsgi/connectors/libfcgi/license.lic
Normal file
1
library/server/ewsgi/connectors/libfcgi/license.lic
Normal file
@@ -0,0 +1 @@
|
||||
reference:forum2
|
||||
@@ -0,0 +1,81 @@
|
||||
note
|
||||
description: "Summary description for {GW_LIBFCGI_CONNECTOR}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_LIBFCGI_CONNECTOR
|
||||
|
||||
inherit
|
||||
GW_CONNECTOR
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
do
|
||||
create fcgi.make
|
||||
create {GW_LIBFCGI_INPUT_STREAM} input.make (fcgi)
|
||||
create {GW_LIBFCGI_OUTPUT_STREAM} output.make (fcgi)
|
||||
end
|
||||
|
||||
feature -- Server
|
||||
|
||||
launch
|
||||
local
|
||||
res: INTEGER
|
||||
do
|
||||
from
|
||||
res := fcgi.fcgi_listen
|
||||
until
|
||||
res < 0
|
||||
loop
|
||||
process_fcgi_request (fcgi.updated_environ_variables, input, output)
|
||||
res := fcgi.fcgi_listen
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process_fcgi_request (vars: HASH_TABLE [STRING, STRING]; a_input: like input; a_output: like output)
|
||||
local
|
||||
gw_env: GW_ENVIRONMENT_VARIABLES
|
||||
do
|
||||
create gw_env.make_with_variables (vars)
|
||||
application.process (gw_env, a_input, a_output)
|
||||
end
|
||||
|
||||
feature -- Input/Output
|
||||
|
||||
input: GW_INPUT_STREAM
|
||||
-- Input from client (from httpd server via FCGI)
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
-- Output to client (via httpd server/fcgi)
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
fcgi: FCGI
|
||||
|
||||
invariant
|
||||
fcgi_attached: fcgi /= Void
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
@@ -0,0 +1,66 @@
|
||||
note
|
||||
description: "Summary description for GW_LIBFCGI_INPUT_STREAM."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_LIBFCGI_INPUT_STREAM
|
||||
|
||||
inherit
|
||||
GW_INPUT_STREAM
|
||||
|
||||
STRING_HANDLER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_fcgi: like fcgi)
|
||||
require
|
||||
valid_fcgi: a_fcgi /= Void
|
||||
do
|
||||
fcgi := a_fcgi
|
||||
initialize
|
||||
end
|
||||
|
||||
initialize
|
||||
-- Initialize Current
|
||||
do
|
||||
create last_string.make_empty
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
read_stream (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' bound characters
|
||||
-- or until end of file.
|
||||
-- Make result available in `last_string'.
|
||||
do
|
||||
fcgi.fill_string_from_stdin (last_string, nb_char)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
last_string: STRING
|
||||
-- Last string read
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
fcgi: FCGI;
|
||||
-- Bridge to FCGI world
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
@@ -0,0 +1,57 @@
|
||||
note
|
||||
description: "Summary description for {GW_LIBFCGI_OUTPUT_STREAM}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_LIBFCGI_OUTPUT_STREAM
|
||||
|
||||
inherit
|
||||
GW_OUTPUT_STREAM
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_fcgi: like fcgi)
|
||||
require
|
||||
valid_fcgi: a_fcgi /= Void
|
||||
do
|
||||
fcgi := a_fcgi
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
put_string (s: STRING)
|
||||
-- Send `s' to http client
|
||||
do
|
||||
fcgi.put_string (s)
|
||||
end
|
||||
|
||||
flush
|
||||
do
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
fcgi: FCGI
|
||||
-- Bridge to FCGI world
|
||||
|
||||
invariant
|
||||
fcgi_attached: fcgi /= Void
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
1
library/server/ewsgi/connectors/nino/license.lic
Normal file
1
library/server/ewsgi/connectors/nino/license.lic
Normal file
@@ -0,0 +1 @@
|
||||
reference:forum2
|
||||
17
library/server/ewsgi/connectors/nino/nino-safe.ecf
Normal file
17
library/server/ewsgi/connectors/nino/nino-safe.ecf
Normal 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_nino" uuid="F91861FB-4FEA-455F-9570-828D7903DC64" library_target="connector_nino">
|
||||
<target name="connector_nino">
|
||||
<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="nino" location="..\..\..\..\..\ext\server\nino\nino-safe.ecf" readonly="false"/>
|
||||
<cluster name="src" location=".\src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
17
library/server/ewsgi/connectors/nino/nino.ecf
Normal file
17
library/server/ewsgi/connectors/nino/nino.ecf
Normal 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_nino" uuid="F91861FB-4FEA-455F-9570-828D7903DC64" library_target="connector_nino">
|
||||
<target name="connector_nino">
|
||||
<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="nino" location="..\..\..\..\..\ext\server\nino\nino.ecf" readonly="false"/>
|
||||
<cluster name="src" location=".\src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
93
library/server/ewsgi/connectors/nino/src/gw_nino_connector.e
Normal file
93
library/server/ewsgi/connectors/nino/src/gw_nino_connector.e
Normal file
@@ -0,0 +1,93 @@
|
||||
note
|
||||
description: "Summary description for {GW_NINO_CONNECTOR}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_NINO_CONNECTOR
|
||||
|
||||
inherit
|
||||
GW_CONNECTOR
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_base
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_base (a_app: like application; a_base: like base)
|
||||
do
|
||||
make (a_app)
|
||||
base := a_base
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
local
|
||||
cfg: HTTP_SERVER_CONFIGURATION
|
||||
do
|
||||
create cfg.make
|
||||
create server.make (cfg)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
server: HTTP_SERVER
|
||||
|
||||
configuration: HTTP_SERVER_CONFIGURATION
|
||||
do
|
||||
Result := server.configuration
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
base: detachable STRING
|
||||
-- Root url base
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_base (b: like base)
|
||||
do
|
||||
base := b
|
||||
end
|
||||
|
||||
feature -- Server
|
||||
|
||||
launch
|
||||
local
|
||||
l_http_handler : HTTP_HANDLER
|
||||
do
|
||||
create {GW_NINO_HANDLER} l_http_handler.make_with_callback (server, "GW_NINO_HANDLER", Current)
|
||||
debug ("nino")
|
||||
if attached base as l_base then
|
||||
print ("Base=" + l_base + "%N")
|
||||
end
|
||||
end
|
||||
server.setup (l_http_handler)
|
||||
end
|
||||
|
||||
process_request (env: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM)
|
||||
local
|
||||
gw_env: GW_ENVIRONMENT_VARIABLES
|
||||
do
|
||||
create gw_env.make_with_variables (env)
|
||||
gw_env.set_variable ("RAW_HEADER_DATA", a_headers_text)
|
||||
application.process (gw_env, create {GW_NINO_INPUT_STREAM}.make (a_input), create {GW_NINO_OUTPUT_STREAM}.make (a_output))
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
156
library/server/ewsgi/connectors/nino/src/gw_nino_handler.e
Normal file
156
library/server/ewsgi/connectors/nino/src/gw_nino_handler.e
Normal file
@@ -0,0 +1,156 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
GW_NINO_HANDLER
|
||||
|
||||
inherit
|
||||
HTTP_CONNECTION_HANDLER
|
||||
|
||||
create
|
||||
make_with_callback
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_callback (a_main_server: like main_server; a_name: STRING; a_callback: like callback)
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
make (a_main_server, a_name)
|
||||
callback := a_callback
|
||||
end
|
||||
|
||||
callback: GW_NINO_CONNECTOR
|
||||
|
||||
feature -- Access
|
||||
|
||||
base: detachable STRING
|
||||
-- Root url base
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_base (a_uri: like base)
|
||||
-- Set `base' to `a_uri'
|
||||
do
|
||||
base := a_uri
|
||||
end
|
||||
|
||||
feature -- Request processing
|
||||
|
||||
process_request (a_handler: HTTP_CONNECTION_HANDLER; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM)
|
||||
-- Process request ...
|
||||
local
|
||||
env, vars: HASH_TABLE [STRING, STRING]
|
||||
p: INTEGER
|
||||
l_request_uri, l_script_name, l_query_string, l_path_info: STRING
|
||||
l_server_name, l_server_port: detachable STRING
|
||||
a_headers_map: HASH_TABLE [STRING, STRING]
|
||||
vn: STRING
|
||||
|
||||
e: EXECUTION_ENVIRONMENT
|
||||
do
|
||||
l_request_uri := a_handler.uri
|
||||
a_headers_map := a_handler.request_header_map
|
||||
create e
|
||||
vars := e.starting_environment_variables
|
||||
env := vars.twin
|
||||
|
||||
--| for Any Abc-Def-Ghi add (or replace) the HTTP_ABC_DEF_GHI variable to `env'
|
||||
from
|
||||
a_headers_map.start
|
||||
until
|
||||
a_headers_map.after
|
||||
loop
|
||||
vn := a_headers_map.key_for_iteration.as_upper
|
||||
vn.replace_substring_all ("-", "_")
|
||||
add_environment_variable (a_headers_map.item_for_iteration, vn, env)
|
||||
a_headers_map.forth
|
||||
end
|
||||
|
||||
--| Specific cases
|
||||
|
||||
p := l_request_uri.index_of ('?', 1)
|
||||
if p > 0 then
|
||||
l_script_name := l_request_uri.substring (1, p - 1)
|
||||
l_query_string := l_request_uri.substring (p + 1, l_request_uri.count)
|
||||
else
|
||||
l_script_name := l_request_uri.string
|
||||
l_query_string := ""
|
||||
end
|
||||
if attached a_headers_map.item ("Host") as l_host then
|
||||
add_environment_variable (l_host, "HTTP_HOST", env)
|
||||
p := l_host.index_of (':', 1)
|
||||
if p > 0 then
|
||||
l_server_name := l_host.substring (1, p - 1)
|
||||
l_server_port := l_host.substring (p+1, l_host.count)
|
||||
else
|
||||
l_server_name := l_host
|
||||
l_server_port := "80" -- Default
|
||||
end
|
||||
end
|
||||
|
||||
if attached a_headers_map.item ("Authorization") as l_authorization then
|
||||
add_environment_variable (l_authorization, "HTTP_AUTHORIZATION", env)
|
||||
p := l_authorization.index_of (' ', 1)
|
||||
if p > 0 then
|
||||
add_environment_variable (l_authorization.substring (1, p - 1), "AUTH_TYPE", env)
|
||||
end
|
||||
end
|
||||
|
||||
add_environment_variable ("CGI/1.1", "GATEWAY_INTERFACE", env)
|
||||
add_environment_variable (l_query_string, "QUERY_STRING", env)
|
||||
|
||||
if attached a_handler.remote_info as l_remote_info then
|
||||
add_environment_variable (l_remote_info.addr, "REMOTE_ADDR", env)
|
||||
add_environment_variable (l_remote_info.hostname, "REMOTE_HOST", env)
|
||||
add_environment_variable (l_remote_info.port.out, "REMOTE_PORT", env)
|
||||
-- add_environment_variable (Void, "REMOTE_IDENT", env)
|
||||
-- add_environment_variable (Void, "REMOTE_USER", env)
|
||||
end
|
||||
|
||||
add_environment_variable (l_request_uri, "REQUEST_URI", env)
|
||||
add_environment_variable (a_handler.method, "REQUEST_METHOD", env)
|
||||
|
||||
add_environment_variable (l_script_name, "SCRIPT_NAME", env)
|
||||
add_environment_variable (l_server_name, "SERVER_NAME", env)
|
||||
add_environment_variable (l_server_port, "SERVER_PORT", env)
|
||||
add_environment_variable (a_handler.version, "SERVER_PROTOCOL", env)
|
||||
add_environment_variable ({HTTP_SERVER_CONFIGURATION}.Server_details, "SERVER_SOFTWARE", env)
|
||||
|
||||
--| Apply `base' value
|
||||
if attached base as l_base and then 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)
|
||||
if p > 0 then
|
||||
l_path_info.keep_head (p - 1)
|
||||
end
|
||||
env.force (l_path_info, "PATH_INFO")
|
||||
env.force (l_base, "SCRIPT_NAME")
|
||||
end
|
||||
end
|
||||
|
||||
callback.process_request (env, a_handler.request_header, a_input, a_output)
|
||||
end
|
||||
|
||||
add_environment_variable (a_value: detachable STRING; a_var_name: STRING; env: HASH_TABLE [STRING, STRING])
|
||||
-- Add variable `a_var_name => a_value' to `env'
|
||||
do
|
||||
if a_value /= Void then
|
||||
env.force (a_value, a_var_name)
|
||||
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
|
||||
@@ -0,0 +1,61 @@
|
||||
note
|
||||
description: "Summary description for {GW_NINO_INPUT_STREAM}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_NINO_INPUT_STREAM
|
||||
|
||||
inherit
|
||||
GW_INPUT_STREAM
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_nino_input: like nino_input)
|
||||
do
|
||||
create last_string.make_empty
|
||||
set_nino_input (a_nino_input)
|
||||
end
|
||||
|
||||
feature {GW_NINO_APPLICATION} -- Nino
|
||||
|
||||
set_nino_input (i: like nino_input)
|
||||
do
|
||||
nino_input := i
|
||||
end
|
||||
|
||||
nino_input: HTTP_INPUT_STREAM
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
read_stream (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' bound characters
|
||||
-- or until end of file.
|
||||
-- Make result available in `last_string'.
|
||||
do
|
||||
nino_input.read_stream (nb_char)
|
||||
last_string := nino_input.last_string
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
last_string: STRING
|
||||
-- Last string read
|
||||
|
||||
;note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
@@ -0,0 +1,60 @@
|
||||
note
|
||||
description: "Summary description for {GW_NINO_OUTPUT_STREAM}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_NINO_OUTPUT_STREAM
|
||||
|
||||
inherit
|
||||
GW_OUTPUT_STREAM
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_nino_output: like nino_output)
|
||||
do
|
||||
set_nino_output (a_nino_output)
|
||||
end
|
||||
|
||||
feature {GW_NINO_APPLICATION} -- Nino
|
||||
|
||||
set_nino_output (o: like nino_output)
|
||||
do
|
||||
nino_output := o
|
||||
end
|
||||
|
||||
nino_output: HTTP_OUTPUT_STREAM
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
put_string (s: STRING_8)
|
||||
-- Send `s' to http client
|
||||
do
|
||||
debug ("nino")
|
||||
print (s)
|
||||
end
|
||||
nino_output.put_string (s)
|
||||
end
|
||||
|
||||
flush
|
||||
-- Flush the output stream
|
||||
do
|
||||
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
|
||||
1071
library/server/ewsgi/doc/cgi_spec_1.0.txt
Normal file
1071
library/server/ewsgi/doc/cgi_spec_1.0.txt
Normal file
File diff suppressed because it is too large
Load Diff
592
library/server/ewsgi/doc/cgi_spec_1.2.txt
Normal file
592
library/server/ewsgi/doc/cgi_spec_1.2.txt
Normal file
@@ -0,0 +1,592 @@
|
||||
|
||||
[unpublished] INTERNET-DRAFT Ken A L Coar
|
||||
draft-coar-cgi-v12-00.{html,txt} The Apache Group
|
||||
D.R.T. Robinson
|
||||
ESI
|
||||
29 May, 1998
|
||||
The WWW Common Gateway Interface
|
||||
Version 1.2
|
||||
|
||||
The revision history of this draft is being maintained using Web-based GUI notation, such as struck-through characters and colour-coded sections. The following legend describes how to determine the origin of a particular revision according to the colour of the text:
|
||||
|
||||
Black
|
||||
Revision 00, released 13 February 1998
|
||||
Green
|
||||
Revision 01, released [text]
|
||||
Abstract
|
||||
|
||||
The Common Gateway Interface (CGI) is a simple interface for running external programs, software or gateways under an information server in a platform-independent manner. Currently, the supported information servers are HTTP servers.
|
||||
|
||||
The interface has been in use by the World-Wide Web since 1993. This specification defines the "current practice" parameters of the 'CGI/1.1' interface developed and documented at the U.S. National Centre for Supercomputing Applications [NCSA-CGI], and the enhancements to that interface known as 'CGI/1.2', which is an extension of the 'CGI/1.1' interface developed and documented at the U.S. National Centre for Supercomputing Applications [NCSA-CGI]. This document also defines the use of the CGI/1.2 interface on the UnixNIX(R) and AmigaDOS(tm) systems.
|
||||
|
||||
Table of Contents
|
||||
|
||||
1 Introduction..............................................TBD
|
||||
1.1 Purpose................................................TBD
|
||||
1.1.1 Differences from CGI/1.1.............................TBD
|
||||
1.2 Requirements...........................................TBD
|
||||
1.3 Specifications.........................................TBD
|
||||
1.4 Terminology............................................TBD
|
||||
2 Notational Conventions and Generic Grammar................TBD
|
||||
2.1 Augmented BNF..........................................TBD
|
||||
2.2 Basic Rules............................................TBD
|
||||
3 Protocol Parameters.......................................TBD
|
||||
3.1 URL Encoding...........................................TBD
|
||||
3.2 The Script URI.........................................TBD
|
||||
4 EnvironmentRequest Metadata (Meta-Variables)..............TBD
|
||||
5 Invoking the Script.......................................TBD
|
||||
6 The CGI Script Command Line...............................TBD
|
||||
7 Data Input to the CGI Script..............................TBD
|
||||
8 Data Output from the CGI Script...........................TBD
|
||||
8.1 Non-Parsed Header Output...............................TBD
|
||||
8.2 Parsed Header Output...................................TBD
|
||||
9 Requirements for Servers..................................TBD
|
||||
10 Recommendations for Scripts..............................TBD
|
||||
11 System Specifications....................................TBD
|
||||
11.1 AmigaDOS..............................................TBD
|
||||
11.2 UnixNIX...............................................TBD
|
||||
12 Security Considerations..................................TBD
|
||||
12.1 Safe Methods..........................................TBD
|
||||
12.2 HTTP Header Fields Containing Sensitive Information...TBD
|
||||
12.3 Script Interference with the Server...................TBD
|
||||
13 Acknowledgments..........................................TBD
|
||||
14 References...............................................TBD
|
||||
15 Authors' Addresses.......................................TBD
|
||||
|
||||
1. Introduction
|
||||
|
||||
1.1. Purpose
|
||||
|
||||
Together the HTTP [3],[8] server and the CGI script are responsible for servicing a client request by sending back responses. The client request comprises a Universal Resource Identifier (URI) [1], a request method and various ancillary information about the request provided by the transport mechanism.
|
||||
|
||||
The CGI defines the abstract parameters, known as environment meta-variables, which describe the client's request. Together with a concrete programmer interface this specifies a platform-independent interface between the script and the HTTP server.
|
||||
|
||||
1.1.1. Differences From CGI/1.1
|
||||
|
||||
The following is a summary of the differences proposed between CGI/1.1 and CGI/1.2:
|
||||
|
||||
<EFBFBD>8.2
|
||||
The introduction of the Script-Control header field
|
||||
<EFBFBD>8.2
|
||||
The introduction of semantics permitting HTTP-style continuation lines in response header fields
|
||||
In the absence of a complete formal specification of CGI/1.1 "current practice", this document may be used as a reference for script developers writing CGI/1.1-compliant applications if none of the CGI/1.2-specific features are utilised.
|
||||
|
||||
1.2. Requirements
|
||||
|
||||
This specification uses the same words as RFC 1123 [5] to define the significance of each particular requirement. These are:
|
||||
|
||||
MUST
|
||||
This word or the adjective 'required' means that the item is an absolute requirement of the specification.
|
||||
SHOULD
|
||||
This word or the adjective 'recommended' means that there may exist valid reasons in particular circumstances to ignore this item, but the full implications should be understood and the case carefully weighed before choosing a different course.
|
||||
MAY
|
||||
This word or the adjective 'optional' means that this item is truly optional. One vendor may choose to include the item because a particular marketplace requires it or because it enhances the product, for example; another vendor may omit the same item.
|
||||
An implementation is not compliant if it fails to satisfy one or more of the 'must' requirements for the protocols it implements. An implementation that satisfies all of the 'must' and all of the 'should' requirements for its features is said to be 'unconditionally compliant'; one that satisfies all of the 'must' requirements but not all of the 'should' requirements for its features is said to be 'conditionally compliant'.
|
||||
|
||||
1.3. Specifications
|
||||
|
||||
Not all of the functions and features of the CGI are defined in the main part of this specification. The following phrases are used to describe the features which are not specified:
|
||||
|
||||
system defined
|
||||
The feature may differ between systems, but must be the same for different implementations using the same system. A system will usually identify a class of operating-systems. Some systems are defined in section 12 of this document. New systems may be defined by new specifications without revision of this document.
|
||||
implementation defined
|
||||
The behaviour of the feature may vary from implementation to implementation, but a particular implementation must document its behaviour.
|
||||
1.4. Terminology
|
||||
|
||||
This specification uses many terms defined in the HTTP/1.1 specification [8]; however, the following terms are used here in a sense which may not accord with their definitions in that document, or with their common meaning.
|
||||
|
||||
environment meta-variable
|
||||
A named parameter that carries information from the server to the script. It is not necessarily a variable in the operating-system's environment, although that is the most common implementation.
|
||||
script
|
||||
The software which is invoked by the server via this interface. It need not be a standalone program, but could be a dynamically-loaded or shared library, or even a subroutine in the server.
|
||||
server
|
||||
The application program which invokes the script in order to service requests.
|
||||
2. Notational Conventions and Generic Grammar
|
||||
|
||||
2.1. Augmented BNF
|
||||
|
||||
All of the mechanisms specified in this document are described in both prose and an augmented Backus-Naur Form (BNF) similar to that used by RFC 822 [6]. This augmented BNF contains the following constructs:
|
||||
|
||||
name = definition
|
||||
the definition by the equal character ("="). Whitespace is only significant in that continuation lines of a definition are indented.
|
||||
"literal"
|
||||
Quotation marks (") surround literal text, except for a literal quotation mark, which is surrounded by angle-brackets ("<" and ">"). Unless stated otherwise, the text is case-sensitive.
|
||||
rule1 | rule2
|
||||
Alternative rules are separated by a vertical bar ("|").
|
||||
(rule1 rule2 rule3)
|
||||
Elements enclosed in parentheses are treated as a single element.
|
||||
*rule
|
||||
A rule preceded by an asterisk ("*") may have zero or more occurrences. A rule preceded by an integer followed by an asterisk must occur at least the specified number of times.
|
||||
[rule]
|
||||
A element enclosed in square brackets ("[" and "]") is optional.
|
||||
2.2. Basic Rules
|
||||
|
||||
The following rules are used throughout this specification to describe basic parsing constructs.
|
||||
|
||||
alpha = lowalpha | hialpha
|
||||
lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h"
|
||||
| "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p"
|
||||
| "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x"
|
||||
| "y" | "z"
|
||||
hialpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H"
|
||||
| "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P"
|
||||
| "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X"
|
||||
| "Y" | "Z"
|
||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
|
||||
| "8" | "9"
|
||||
OCTET = <any 8-bit byte>
|
||||
CHAR = <any character>
|
||||
CTL = <any control character>
|
||||
SP = <space character>
|
||||
HT = <horizontal tab character>
|
||||
NL = <newline>
|
||||
LWSP = SP | HT | NL
|
||||
tspecial = "(" | ")" | "@" | "," | ";" | ":" | "\" | <">
|
||||
| "/" | "[" | "]" | "?" | "<" | ">" | "{" | "}"
|
||||
| SP | HT
|
||||
token = 1*<any CHAR except CTLs or tspecials>
|
||||
quoted-string = ( <"> *qdtext <"> ) | ( "<" *qatext ">")
|
||||
qdtext = <any CHAR except <"> and CTLs but including LWSP>
|
||||
qatext = <any CHAR except "<", ">" and CTLs but
|
||||
including LWSP>
|
||||
|
||||
Note that newline (NL) need not be a single character, but can be a character sequence.
|
||||
|
||||
3. Protocol Parameters
|
||||
|
||||
3.1. URL Encoding
|
||||
|
||||
Some variables and constructs used here are described as being 'URL-encoded'. This encoding is described in section 2.2 of RFC 1738 [4]. In a URL encoded string an escape sequence consists of a percent character ("%") followed by two hexadecimal digits, where the two hexadecimal digits form an octet. An escape sequence represents the graphic character which has the octet as its code within the US-ASCII [12] coded character set, if it exists. If no such graphic character exists, then the escape sequence represents the octet value itself.
|
||||
|
||||
An alternate "shortcut" encoding for representing the space character exists and is in common use. Scripts should be prepared to recognise both '+' and '%20' as an encoded space in a URL.
|
||||
|
||||
Note that some unsafe characters may have different semantics if they are encoded. The definition of which characters are unsafe depends on the context. See section 2.2 of RFC 1738 [4] for authoritative treatment of this issue.
|
||||
|
||||
3.2. The Script URI
|
||||
|
||||
A 'Script URI' can be defined; this describes the resource identified by the environment meta-variables. Often, this URI will be the same as the URI requested by the client (the 'Client URI'); however, it need not be. Instead, it could be a URI invented by the server, and so it can only be used in the context of the server and its CGI interface.
|
||||
|
||||
The script URI has the syntax of generic-RL as defined in section 2.1 of RFC 1808 [7], with the exception that object parameters and fragment identifiers are not permitted:
|
||||
|
||||
<scheme>://<host><port>/<path>?<query>
|
||||
The various components of the script URI are defined by some of the environment meta-variables (see below);
|
||||
|
||||
script-uri = protocol "://" SERVER_NAME ":" SERVER_PORT enc-script
|
||||
enc-path-info "?" QUERY_STRING
|
||||
|
||||
where 'protocol' is found from SERVER_PROTOCOL, 'enc-script' is a URL-encoded version of SCRIPT_NAME and 'enc-path-info' is a URL-encoded version of PATH_INFO.
|
||||
|
||||
4. Environment VariablesRequest Metadata (Meta-Variables)
|
||||
|
||||
Environment variables are usedEach CGI implementation must define a mechanism to pass data about the request from the server to the script. TheyThe meta-variables containing these data are accessed by the script in a system defined manner. In all cases, a missing environment meta-variable is equivalent to a zero-length (NULL) value, and vice versa. The representation of the characters in the environment meta-variables is system defined.
|
||||
|
||||
Case is not significant in the meta-variable names, in that there cannot be two different variables whose names differ in case only. Here they are shown using a canonical representation of capitals plus underscore ("_"). The actual representation of the names is system defined; for a particular system the representation may be defined differently tothan this.
|
||||
|
||||
The variables are:
|
||||
|
||||
AUTH_TYPE
|
||||
CONTENT_LENGTH
|
||||
CONTENT_TYPE
|
||||
GATEWAY_INTERFACE
|
||||
HTTP_*
|
||||
PATH_INFO
|
||||
PATH_TRANSLATED
|
||||
QUERY_STRING
|
||||
REMOTE_ADDR
|
||||
REMOTE_HOST
|
||||
REMOTE_IDENT
|
||||
REMOTE_USER
|
||||
REQUEST_METHOD
|
||||
SCRIPT_NAME
|
||||
SERVER_NAME
|
||||
SERVER_PORT
|
||||
SERVER_PROTOCOL
|
||||
SERVER_SOFTWARE
|
||||
|
||||
AUTH_TYPE
|
||||
This variable is specific to requests made with HTTP.
|
||||
If the script URI would require access authentication for external access, then this variable is found from the 'auth-scheme' token in the request, otherwise NULL.
|
||||
|
||||
AUTH_TYPE = "" | auth-scheme
|
||||
auth-scheme = "Basic" | token
|
||||
|
||||
HTTP access authentication schemes are described in section 11 of the HTTP/1.1 specification [8]. The auth-scheme is not case-sensitive.
|
||||
|
||||
CONTENT_LENGTH
|
||||
The size of the entity attached to the request, if any, in decimal number of octets. If no data isare attached, then NULL. The syntax is the same as the HTTP Content-Length header field (section 14.14, HTTP/1.1 specification [8]).
|
||||
CONTENT_LENGTH = "" | 1*digit
|
||||
|
||||
CONTENT_TYPE
|
||||
The Internet Media Type [9] of the attached entity. The syntax is the same as the HTTP Content-Type header field.
|
||||
CONTENT_TYPE = "" | media-type
|
||||
media-type = type "/" subtype *( ";" parameter)
|
||||
type = token
|
||||
subtype = token
|
||||
parameter = attribute "=" value
|
||||
attribute = token
|
||||
value = token | quoted-string
|
||||
|
||||
The type, subtype and parameter attribute names are not case-sensitive. Parameter values may be case sensitive. Media types and their use in HTTP are described section 3.7 of the HTTP/1.1 specification [8]. Example:
|
||||
|
||||
application/x-www-form-urlencoded
|
||||
|
||||
There is no default value for this variable. If and only if it is unset, then the script may attempt to determine the media type from the data received. If the type remains unknown, then the script may choose to either assume a content-type of application/octet-stream or reject the request with either a 406 ("Not Acceptable") or 415 ("Unsupported Media Type") errorshould be assumed.
|
||||
|
||||
GATEWAY_INTERFACE
|
||||
The version of the CGI specification to which this server complies. Syntax:
|
||||
GATEWAY_INTERFACE = "CGI" "/" 1*digit "." 1*digit
|
||||
|
||||
Note that the major and minor numbers are treated as separate integers and hence each may be incremented higher than a single digit. Thus CGI/2.4 is a lower version than CGI/2.13 which in turn is lower than CGI/12.3. Leading zeros must be ignored by scripts and should never be generated by servers.
|
||||
|
||||
This document defines the 1.2 version of the CGI interface.
|
||||
|
||||
HTTP_*
|
||||
These variables are specific to requests made with HTTP. Interpretation of these variables may depends on the value of SERVER_PROTOCOL.
|
||||
Environment Meta-variables with names beginning with "HTTP_" contain header data read from the client, if the protocol used was HTTP. The HTTP header field name is converted to upper case, has all occurrences of "-" replaced with "_" and has "HTTP_" prepended to give the environment meta-variable name. The header data may be presented as sent by the client, or may be rewritten in ways which do not change its semantics. If multiple header fields with the same field-name are received then they must be rewritten as a single header field having the same semantics. Similarly, a header field that is received on more than one line must be merged onto a single line. The server must, if necessary, change the representation of the data (for example, the character set) to be appropriate for a CGI environment meta-variable.
|
||||
|
||||
The server is not required to create environment meta-variables for all the header fields that it receives. In particular, it may remove any header fields carrying authentication information, such as "Authorization"; and it may remove header fields whose value is available to the script via other variables, such as "Content-Length" and "Content-Type".
|
||||
|
||||
PATH_INFO
|
||||
A path to be interpreted by the CGI script. It identifies the resource or sub-resource to be returned by the CGI script. The syntax and semantics are similar to a decoded HTTP URL 'hpath' token (defined in RFC 1738 [4]), with the exception that a PATH_INFO of "/" represents a single void path segment. Otherwise, the leading "/" character is not part of the path.
|
||||
PATH_INFO = "" | ( "/" path )
|
||||
path = segment *( "/" segment )
|
||||
segment = *pchar
|
||||
pchar = <any CHAR except "/">
|
||||
|
||||
The PATH_INFO string is the trailing part of the <path> component of the script URI that follows the SCRIPT_NAME part of the path.
|
||||
|
||||
PATH_TRANSLATED
|
||||
The OS path to the file that the server would attempt to access were the client to request the absolute URL containing the path PATH_INFO. I.e., for a request of
|
||||
protocol "://" SERVER_NAME ":" SERVER_PORT enc-path-info
|
||||
|
||||
where 'enc-path-info' is a URL-encoded version of PATH_INFO. If PATH_INFO is NULL then PATH_TRANSLATED is set to NULL.
|
||||
PATH_TRANSLATED = *CHAR
|
||||
|
||||
PATH_TRANSLATED need not be supported by the server. The server may choose to set PATH_TRANSLATED to NULL for reasons of security, or because the path would not be interpretable by a CGI script; such as the object it represented was internal to the server and not visible in the file-system; or for any other reason.
|
||||
|
||||
The algorithm the server uses to derive PATH_TRANSLATED is obviously implementation defined; CGI scripts which use this variable may suffer limited portability.
|
||||
|
||||
QUERY_STRING
|
||||
A URL-encoded search string; the <query> part of the script URI.
|
||||
QUERY_STRING = query-string
|
||||
query-string = *qchar
|
||||
qchar = unreserved | escape | reserved
|
||||
unreserved = alpha | digit | safe | extra
|
||||
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "="
|
||||
safe = "$" | "-" | "_" | "." | "+"
|
||||
extra = "!" | "*" | "'" | "(" | ")" | ","
|
||||
escape = "%" hex hex
|
||||
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" | "a"
|
||||
| "b" | "c" | "d" | "e" | "f"
|
||||
|
||||
The URL syntax for a search string is described in RFC 1738 [4].
|
||||
|
||||
REMOTE_ADDR
|
||||
The IP address of the agent sending the request to the server. This is not necessarily that of the client.
|
||||
REMOTE_ADDR = hostnumber
|
||||
hostnumber = digits "." digits "." digits "." digits
|
||||
digits = 1*digit
|
||||
|
||||
REMOTE_HOST
|
||||
The fully qualified domain name of the agent sending the request to the server, if available, otherwise NULL. Not necessarily that of the client. Fully qualified domain names take the form as described in section 3.5 of RFC 1034 [10] and section 2.1 of RFC 1123 [5]; a sequence of domain labels separated by ".", each domain label starting and ending with an alphanumerical character and possibly also containing "-" characters. The rightmost domain label will never start with a digit. Domain names are not case sensitive.
|
||||
REMOTE_HOST = "" | hostname
|
||||
hostname = *( domainlabel ".") toplabel
|
||||
domainlabel = alphadigit [ *alphahypdigit alphadigit ]
|
||||
toplabel = alpha [ *alphahypdigit alphadigit ]
|
||||
alphahypdigit = alphadigit | "-"
|
||||
alphadigit = alpha | digit
|
||||
|
||||
REMOTE_IDENT
|
||||
The identity information reported about the connection by a RFC 1413 [11] request to the remote agent, if available. The server may choose not to support this feature, or not to request the data for efficiency reasons.
|
||||
REMOTE_IDENT = *CHAR
|
||||
|
||||
The data returned isare not appropriate for use as authentication information.
|
||||
|
||||
REMOTE_USER
|
||||
This variable is specific to requests made with HTTP.
|
||||
If AUTH_TYPE is "Basic", then the user-ID sent by the client. If AUTH_TYPE is NULL, then NULL, otherwise undefined.
|
||||
|
||||
REMOTE_USER = "" | userid | *OCTET
|
||||
userid = token
|
||||
|
||||
REQUEST_METHOD
|
||||
This variable is specific to requests made with HTTP.
|
||||
The method with which the request was made, as described in section 5.1.1 of the HTTP/1.0 specification [3] and section 5.1.1 of the HTTP/1.1 specification [8].
|
||||
|
||||
REQUEST_METHOD = http-method
|
||||
http-method = "GET" | "HEAD" | "POST" | "PUT" | "DELETE"
|
||||
| extension-method
|
||||
extension-method = token
|
||||
|
||||
The method is case sensitive. Note that of the new methods defined by the HTTP/1.1 specification [8], OPTIONS and TRACE are not appropriate for the CGI/1.2 environment.
|
||||
|
||||
SCRIPT_NAME
|
||||
A URL path that could identify the CGI script (rather then the particular CGI output). The syntax and semantics are identical to a decoded HTTP URL 'hpath' token [4].
|
||||
SCRIPT_NAME = "" | ( "/" [ path ] )
|
||||
|
||||
The leading "/" is not part of the path. It is optional if the path is NULL.
|
||||
|
||||
The SCRIPT_NAME string is some leading part of the <path> component of the script URI derived in some implementation defined manner.
|
||||
|
||||
SERVER_NAME
|
||||
The name for this server, as used in the <host> part of the script URI. Thus either a fully qualified domain name, or an IP address.
|
||||
SERVER_NAME = hostname | hostnumber
|
||||
|
||||
SERVER_PORT
|
||||
The port on which this request was received, as used in the <port> part of the script URI.
|
||||
SERVER_PORT = 1*digit
|
||||
|
||||
SERVER_PROTOCOL
|
||||
The name and revision of the information protocol this request came in with. This is not necessarily the same as the protocol version used by the server in its response.
|
||||
SERVER_PROTOCOL = HTTP-Version | extension-version
|
||||
HTTP-Version = "HTTP" "/" 1*digit "." 1*digit
|
||||
extension-version = protocol "/" 1*digit "." 1*digit
|
||||
protocol = 1*( alpha | digit | "+" | "-" | "." )
|
||||
|
||||
'protocol' is a version of the <scheme> part of the script URI, and is not case sensitive. By convention, 'protocol' is in upper case.
|
||||
|
||||
SERVER_SOFTWARE
|
||||
The name and version of the information server software answering the request (and running the gateway).
|
||||
SERVER_SOFTWARE = *CHAR
|
||||
|
||||
5. Invoking the Script
|
||||
|
||||
This script is invoked in a system defined manner. Unless specified otherwise, this will be by treating the file containing the script as an executable program, and running it as a child process of the server.
|
||||
|
||||
6. The CGI Script Command Line
|
||||
|
||||
Some systems support a method for supplying an array of strings to the CGI script. This is only used in the case of an 'indexed' query. This is identified by a "GET" or "HEAD" HTTP request with a URL search string not containing any unencoded "=" characters. For such a request, the server should parse the search string into words, using the rules:
|
||||
|
||||
search-string = search-word *( "+" search-word )
|
||||
search-word = 1*schar
|
||||
schar = xunreserved | escape | xreserved
|
||||
xunreserved = alpha | digit | xsafe | extra
|
||||
xsafe = "$" | "-" | "_" | "."
|
||||
xreserved = ";" | "/" | "?" | ":" | "@" | "&"
|
||||
|
||||
After parsing, each word is URL-decoded, optionally encoded in a system defined manner and then the argument list is set to the list of words.
|
||||
|
||||
If the server cannot create any part of the argument list, then the server should generate no command line information. For example, the number of arguments may be greater than operating system or server limitations, or one of the words may not be representable as an argument.
|
||||
|
||||
7. Data Input to the CGI Script
|
||||
|
||||
As there may be a data entity attached to the request, there must be a system defined method for the script to read thisthese data. Unless defined otherwise, this will be via the 'standard input' file descriptor.
|
||||
|
||||
There will be at least CONTENT_LENGTH bytes available for the script to read. The script is not obliged to read the data, but it must not attempt to read more than CONTENT_LENGTH bytes, even if more data isare available.
|
||||
|
||||
For non-parsed header (NPH) scripts (see below), the server should attempt to ensure that the script input comes directly from the client, with minimal buffering. For all scripts the data will be as supplied by the client.
|
||||
|
||||
8. Data Output from the CGI Script
|
||||
|
||||
There must be a system defined method for the script to send data back to the server or client; a script will always return some data. Unless defined otherwise, this will be via the 'standard output' file descriptor.
|
||||
|
||||
There are two forms of output that the script can give; non-parsed header (NPH) output, and parsed header output. A server is only required to support the latter; distinguishing between the two types of output (or scripts) is implementation defined.
|
||||
|
||||
8.1. Non-Parsed Header Output
|
||||
|
||||
The script must return a complete HTTP response message, as described in Section 6 of the HTTP specifications [3],[8]. The script shouldmust use the SERVER_PROTOCOL variable to determine the appropriate format for a response. Note that this allows an HTTP/0.9 response to an HTTP/1.0 request, for example.
|
||||
|
||||
The server should attempt to ensure that the script output is sent directly to the client, with minimal internal and no transport-visible buffering.
|
||||
|
||||
8.2. Parsed Header Output
|
||||
|
||||
The script returns a CGI response message as follows.:
|
||||
|
||||
CGI-Response = *( CGI-Header | HTTP-Header ) NL [ Entity-Body ]
|
||||
CGI-Header = Content-type
|
||||
| Location
|
||||
| Status
|
||||
| Script-Control
|
||||
| extension-header
|
||||
|
||||
The response comprises a header and a body, separated by a blank line. The header fields are either CGI header fields to be interpreted by the server, or HTTP headers to be included in the response returned to the client if the request method is HTTP. At least one CGI-Header must be supplied, but no CGI header field can be repeated with the same field-name. If a body is supplied, then a Content-type header field is required, otherwise the script must send a Location or Status header field. If a Location header field is returned, then no HTTP-Headers may be supplied.
|
||||
|
||||
The CGI header fields have the generic syntax:
|
||||
|
||||
generic-header = field-name ":" [ field-value ] NL
|
||||
field-name = 1*<any CHAR, excluding CTLs, SP and ":">
|
||||
field-value = *( field-content | LWSP )
|
||||
field-content = *( token | tspecial | quoted-string )
|
||||
|
||||
The field-name is not case sensitive; a NULL field value is equivalent to the header field not being sent.
|
||||
|
||||
Content-Type
|
||||
The Internet Media Type [9] of the entity body, which is to be sent unmodified to the client.
|
||||
Content-Type = "Content-Type" ":" media-type NL
|
||||
|
||||
This is actually an HTTP-Header rather than a CGI-header field, but it is listed here because of its importance in the CGI dialogue as a member of the "one of these is required" set of header fields.
|
||||
|
||||
Location
|
||||
This is used to specify to the server that the script is returning a reference to a document rather than an actual document.
|
||||
Location = "Location" ":"
|
||||
( fragment-URI | rel-URL-abs-path ) NL
|
||||
fragment-URI = URI [ # fragmentid ]
|
||||
URI = scheme ":" *qchar
|
||||
fragmentid = *qchar
|
||||
rel-URL-abs-path = "/" [ hpath ] [ "?" query-string ]
|
||||
hpath = fpsegment *( "/" psegment )
|
||||
fpsegment = 1*hchar
|
||||
psegment = *hchar
|
||||
hchar = alpha | digit | safe | extra
|
||||
| ":" | "@" | "& | "="
|
||||
|
||||
The lLocation value is either an absolute URI with optional fragment, as defined in RFC 1630 [1], or an absolute path and optional query-string. If an absolute URI is returned by the script, then the server will generate a '302 redirect' HTTP response message, and if no entity body is supplied by the script, then the server will produce one. If the Location value is a path, then the server will generate the response that it would have produced in response to a request containing the URL
|
||||
|
||||
protocol "://" SERVER_NAME ":" SERVER_PORT rel-URL-abs-path
|
||||
|
||||
The location header field may only be sent if the REQUEST_METHOD is HEAD or GET.
|
||||
|
||||
Status
|
||||
The Status header field is used to indicate to the server what status code the server must use in the response message. It should not be sent if the script returns a Location header field.
|
||||
Status = "Status" ":" digit digit digit SP reason-phrase NL
|
||||
reason-phrase = *<CHAR, excluding CTLs, NL>
|
||||
|
||||
The valid status codes are listed in section 6.1.1 of the HTTP/1.0 specifications [3]. If the SERVER_PROTOCOL is "HTTP/1.1", then the status codes defined in the HTTP/1.1 specification [8] may be used. If the script does not return a Status header field, then "200 OK" should be assumed.
|
||||
|
||||
If a script is being used to handle a particular error or condition encountered by the server, such as a 404 Not Found error, the script should use the Status CGI header field to propagate the error condition back to the client. E.g., in the example mentioned it should include a "Status: 404 Not Found" in the header data returned to the server.
|
||||
|
||||
Script-Control
|
||||
The Script-Control header field is used to inform the server of special requirements the script may have.
|
||||
Script-Control = "Script-Control" ":" 1#control-directive NL
|
||||
control-directive = "no-abort"
|
||||
| extension-directive
|
||||
extension-directive = *<CHAR, excluding CTLs, NL>
|
||||
|
||||
The meanings of the different script control directives are:
|
||||
|
||||
no-abort
|
||||
The presence of this directive informs the server that the server MUST NOT abort the script, which will manage its own termination. This is useful when a script's activity includes performing an operation which might result in data corruption if prematurely interrupted.
|
||||
If the script does not return a Script-Control header field, then the server is free to manage the script as it deems appropriate (e.g., killing the CGI process if the request is aborted by the client, or if the script neglects to respond within an arbitrary time interval selected by the server).
|
||||
|
||||
HTTP header fields
|
||||
The script may return any other header fields defined by the specification for the SERVER_PROTOCOL (HTTP/1.0 [3] or HTTP/1.1 [8]). The server must translate the header data from the CGI header field syntax to the HTTP header field syntax if these differ. For example, the character sequence for newline (such as Unix's ASCII NL) used by CGI scripts may not be the same as that used by HTTP (ASCII CR followed by LF). The server must also resolve any conflicts between header fields returned by the script and header fields that it would otherwise send itself.
|
||||
9. Requirements for Servers
|
||||
|
||||
Servers must support the standard mechanism (described below) which allows the script author to determine what URL to use in documents which reference the script. Specifically, what URL to use in order to achieve particular settings of the environment meta-variables. This mechanism is as follows:
|
||||
|
||||
The value for SCRIPT_NAME is governed by the server configuration and the location of the script in the OS file-system. Given this, any access to the partial URL
|
||||
|
||||
SCRIPT_NAME extra-path ? query-information
|
||||
|
||||
where extra-path is either NULL or begins with a "/" and satisfies any other server requirements, will cause the CGI script to be executed with PATH_INFO set to the decoded extra-path, and QUERY_STRING set to query-information (not decoded).
|
||||
|
||||
Servers may reject with error 404 any requests that would result in an encoded "/" being decoded into PATH_INFO or SCRIPT_NAME, as this might represent a loss of information to the script.
|
||||
|
||||
Although the server and the CGI script need not be consistent in their handling of URL paths (client URLs and the PATH_INFO data, respectively), server authors may wish to impose consistency. So the server implementation should define its behaviour for the following cases:
|
||||
|
||||
define any restrictions on allowed characters, in particular whether ASCII NUL is permitted;
|
||||
define any restrictions on allowed path segments, in particular whether non-terminal NULL segments are permitted;
|
||||
define the behaviour for "." or ".." path segments; i.e., whether they are prohibited, treated as ordinary path segments or interpreted in accordance with the relative URL specification [7];
|
||||
define any limits of the implementation, including limits on path or search string lengths, and limits on the volume of header data the server will parse.
|
||||
Servers may generate the script URI in any way from the client URI, or from any other data (but the behaviour should be documented).
|
||||
|
||||
10. Recommendations for Scripts
|
||||
|
||||
Scripts should reject unexpected methods (such as DELETE etc.) with error 405 Method Not Allowed. If the script does not intend processing the PATH_INFO data, then it should reject the request with 404 Not Found if PATH_INFO is not NULL.
|
||||
|
||||
If the output of a form is being processed, check that CONTENT_TYPE is "application/x-www-form-urlencoded" [2].
|
||||
|
||||
If parsing PATH_INFO, PATH_TRANSLATED or SCRIPT_NAME then be careful of void path segments ("//") and special path segments ("." and ".."). They should either be removed from the path before use in OS system calls, or the request should be rejected with 404 Not Found. It is very unlikely that any other use could be made of these.
|
||||
|
||||
As it is impossible for the script to determine the client URI that initiated this request without knowledge of the specific server in use, the script should not return text/html documents containing relative URL links without including a <BASE> tag in the document.
|
||||
|
||||
When returning header fields, the script should try to send the CGI header fields as soon as possible, and preferably before any HTTP header fields. This may help reduce the server's memory requirements.
|
||||
|
||||
11. System Specifications
|
||||
|
||||
11.1. AmigaDOS
|
||||
|
||||
The implementation of the CGI on an AmigaDOS operating system platform should use environment variables as the mechanism of providing request metadata to CGI scripts.
|
||||
|
||||
Environment variables
|
||||
These are accessed by the DOS library routine GetVar. The flags argument should be 0. Case is ignored, but upper case is recommended for compatibility with case-sensitive systems.
|
||||
The current working directory
|
||||
The current working directory for the script is set to the directory containing the script.
|
||||
Character set
|
||||
The US-ASCII character set is used for the definition of environment variable names and header field names; the newline (NL) sequence is LF; servers should also accept CR LF as a newline.
|
||||
11.2. UnixNIX
|
||||
|
||||
The implementation of the CGI on a UNIX operating system platform should use environment variables as the mechanism of providing request metadata to CGI scripts.
|
||||
|
||||
For Unix compatible operating systems, the following are defined:
|
||||
|
||||
Environment variables
|
||||
These are accessed by the C library routine getenv.
|
||||
The command line
|
||||
This is accessed using the the argc and argv arguments to main(). The words have any characters which are 'active' in the Bourne shell escaped with a backslash.
|
||||
The current working directory
|
||||
The current working directory for the script isshould be set to the directory containing the script.
|
||||
Character set
|
||||
The US-ASCII character set is used for the definition of environment variable names and header field names; the newline (NL) sequence is LF; servers should also accept CR LF as a newline.
|
||||
12. Security Considerations
|
||||
|
||||
12.1. Safe Methods
|
||||
|
||||
As discussed in the security considerations of the HTTP specifications [3],[8], the convention has been established that the GET and HEAD methods should be 'safe'; they should cause no side-effects and only have the significance of resource retrieval.
|
||||
|
||||
12.2. HTTP Header Fields Containing Sensitive Information
|
||||
|
||||
Some HTTP header fields may carry sensitive information which the server should not pass on to the script unless explicitly configured to do so. For example, if the server protects the script using the Basic authentication scheme, then the client will send an Authorization header field containing a username and password. If the server, rather than the script, validates this information then the password should not be passed on to the script via the HTTP_AUTHORIZATION environment meta-variable.
|
||||
|
||||
12.3. Script Interference with the Server
|
||||
|
||||
The most common implementation of CGI invokes the script as a child process using the same user and group as the server process. It should therefore be ensured that the script cannot interfere with the server process, its configuration, or documents.
|
||||
|
||||
If the script is executed by calling a function linked in to the server software (either at compile-time or run-time) then precautions should be taken to protect the core memory of the server, or to ensure that untrusted code cannot be executed.
|
||||
|
||||
13. Acknowledgements
|
||||
|
||||
This work is based on a draft published in 1997 by David R. Robinson in 1997, which in turn was based on the original CGI interface that arose out of discussions on the www-talk mailing list. In particular, Rob McCool, John Franks, Ari Luotonen, George Phillips and Tony Sanders deserve special recognition for their efforts in defining and implementing the early versions of this interface.
|
||||
|
||||
This document has also greatly benefited from the comments and suggestions made by Chris Adie, Dave Kristol, and Mike Meyer, David Morris, and Harald Alvestrand.
|
||||
|
||||
14. References
|
||||
|
||||
[1]
|
||||
Berners-Lee, T., 'Universal Resource Identifiers in WWW: A Unifying Syntax for the Expression of Names and Addresses of Objects on the Network as used in the World-Wide Web', RFC 1630, CERN, June 1994.
|
||||
[2]
|
||||
Berners-Lee, T. and Connolly, D., 'Hypertext Markup Language - 2.0', RFC 1866, MIT/W3C, November 1995.
|
||||
[3]
|
||||
Berners-Lee, T., Fielding, R. T. and Frystyk, H., 'Hypertext Transfer Protocol -- HTTP/1.0', RFC 1945, MIT/LCS, UC Irvine, May 1996.
|
||||
[4]
|
||||
Berners-Lee, T., Masinter, L. and McCahill, M., Editors, 'Uniform Resource Locators (URL)', RFC 1738, CERN, Xerox Corporation, University of Minnesota, December 1994.
|
||||
[5]
|
||||
Braden, R., Editor, 'Requirements for Internet Hosts -- Application and Support', STD 3, RFC 1123, IETF, October 1989.
|
||||
[6]
|
||||
Crocker, D.H., 'Standard for the Format of ARPA Internet Text Messages', STD 11, RFC 822, University of Delaware, August 1982.
|
||||
[7]
|
||||
Fielding, R., 'Relative Uniform Resource Locators', RFC 1808, UC Irving, June 1995.
|
||||
[8]
|
||||
Fielding, R., Gettys, J., Mogul, J., Frystyk, H. and Berners-Lee, T., 'Hypertext Transfer Protocol -- HTTP/1.1', RFC 2068, UC Irving, DEC, MIT/LCS, January 1997.
|
||||
[9]
|
||||
Freed, N. and Borenstein N., 'Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types', RFC 2046, Innosoft, First Virtual, November 1996.
|
||||
[10]
|
||||
Mockapetris, P., 'Domain Names - Concepts and Facilities', STD 13, RFC 1034, ISI, November 1987.
|
||||
[11]
|
||||
St. Johns, M., 'Identification Protocol', RFC 1431, US Department of Defense, February 1993.
|
||||
[12]
|
||||
'Coded Character Set -- 7-bit American Standard Code for Information Interchange', ANSI X3.4-1986.
|
||||
15. Authors' Addresses
|
||||
|
||||
Ken A L Coar
|
||||
MeepZor Consulting
|
||||
26B Bay Ridge Drive
|
||||
Nashua, NH 03062
|
||||
U.S.A.
|
||||
|
||||
Tel: +1 (603) 891.2243
|
||||
Fax: not available
|
||||
Email: Ken.Coar@Golux.Com
|
||||
|
||||
David Robinson
|
||||
Electronic Share Information Ltd
|
||||
Mount Pleasant House
|
||||
2 Mount Pleasant
|
||||
Huntingdon Road
|
||||
Cambridge CB3 0RN
|
||||
UK
|
||||
|
||||
Tel: +44 (1223) 566926
|
||||
Fax: +44 (1223) 506288
|
||||
Email: drtr@esi.co.uk
|
||||
|
||||
18
library/server/ewsgi/ewsgi-safe.ecf
Normal file
18
library/server/ewsgi/ewsgi-safe.ecf
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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="ewsgi" uuid="D924DBE1-1231-434A-80EF-234BA09D1E30" library_target="ewsgi">
|
||||
<target name="ewsgi">
|
||||
<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" syntax="provisional">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<library name="error" location="..\..\error\error-safe.ecf"/>
|
||||
<library name="http" location="..\..\protocol\http\http-safe.ecf"/>
|
||||
<cluster name="interface" location="src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
18
library/server/ewsgi/ewsgi.ecf
Normal file
18
library/server/ewsgi/ewsgi.ecf
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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="ewsgi" uuid="D924DBE1-1231-434A-80EF-234BA09D1E30" library_target="ewsgi">
|
||||
<target name="ewsgi">
|
||||
<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="false" void_safety="none" syntax="provisional">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
|
||||
<library name="error" location="..\..\error\error-safe.ecf"/>
|
||||
<library name="http" location="..\..\protocol\http\http.ecf"/>
|
||||
<cluster name="interface" location="src\" recursive="true" />
|
||||
</target>
|
||||
</system>
|
||||
19
library/server/ewsgi/examples/hello_world/hello-safe.ecf
Normal file
19
library/server/ewsgi/examples/hello_world/hello-safe.ecf
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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="hello_world" uuid="734385F1-0D17-4B5F-9138-24DC8D4F06C6">
|
||||
<target name="hello_world">
|
||||
<root class="HELLO_WORLD" feature="make"/>
|
||||
<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" syntax="provisional">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
|
||||
<library name="connector_cgi" location="..\..\connectors\cgi\cgi-safe.ecf" readonly="false"/>
|
||||
<library name="connector_nino" location="..\..\connectors\nino\nino-safe.ecf" readonly="false"/>
|
||||
<library name="connector_libfcgi" location="..\..\connectors\libfcgi\libfcgi-safe.ecf" readonly="false"/>
|
||||
<cluster name="src" location="src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
58
library/server/ewsgi/examples/hello_world/src/hello_world.e
Normal file
58
library/server/ewsgi/examples/hello_world/src/hello_world.e
Normal file
@@ -0,0 +1,58 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
HELLO_WORLD
|
||||
|
||||
inherit
|
||||
GW_APPLICATION_IMP
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize `Current'.
|
||||
local
|
||||
conn: detachable GW_CONNECTOR
|
||||
nino_conn: GW_NINO_CONNECTOR
|
||||
do
|
||||
if is_nino then
|
||||
create nino_conn.make_with_base (Current, "/hello_world")
|
||||
if attached nino_conn.server.server_configuration as cfg then
|
||||
cfg.http_server_port := 8080
|
||||
cfg.force_single_threaded := True
|
||||
end
|
||||
conn := nino_conn
|
||||
elseif is_cgi then
|
||||
create {GW_CGI_CONNECTOR} conn.make (Current)
|
||||
elseif is_libfcgi then
|
||||
create {GW_LIBFCGI_CONNECTOR} conn.make (Current)
|
||||
else
|
||||
io.error.put_string ("Unsupported connector")
|
||||
end
|
||||
if conn /= Void then
|
||||
conn.launch
|
||||
end
|
||||
end
|
||||
|
||||
is_nino: BOOLEAN = True
|
||||
is_cgi: BOOLEAN = False
|
||||
is_libfcgi: BOOLEAN = False
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute (ctx: GW_REQUEST_CONTEXT)
|
||||
-- Execute the request
|
||||
do
|
||||
ctx.output.put_string ("Hello World!%N")
|
||||
if attached ctx.execution_variable ("REQUEST_COUNT") as rq_count then
|
||||
ctx.output.put_string ("Request #" + rq_count + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
10
library/server/ewsgi/license.lic
Normal file
10
library/server/ewsgi/license.lic
Normal 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
|
||||
]"
|
||||
629
library/server/ewsgi/src/context/gw_environment.e
Normal file
629
library/server/ewsgi/src/context/gw_environment.e
Normal file
@@ -0,0 +1,629 @@
|
||||
note
|
||||
description: "[
|
||||
|
||||
Interface for a request environment
|
||||
It includes CGI interface and a few extra values that are usually valuable
|
||||
|
||||
See http://ken.coar.org/cgi/draft-coar-cgi-v11-03.txt
|
||||
|
||||
2.2. Basic Rules
|
||||
|
||||
The following rules are used throughout this specification to
|
||||
describe basic parsing constructs.
|
||||
|
||||
alpha = lowalpha | hialpha
|
||||
alphanum = alpha | digit
|
||||
lowalpha = a | b | c | d | e | f | g | h
|
||||
| i | j | k | l | m | n | o | p
|
||||
| q | r | s | t | u | v | w | x
|
||||
| y | z
|
||||
hialpha = A | B | C | D | E | F | G | H
|
||||
| I | J | K | L | M | N | O | P
|
||||
| Q | R | S | T | U | V | W | X
|
||||
| Y | Z
|
||||
digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
||||
| 8 | 9
|
||||
hex = digit | A | B | C | D | E | F | a
|
||||
| b | c | d | e | f
|
||||
escaped = % hex hex
|
||||
OCTET = <any 8-bit sequence of data>
|
||||
CHAR = <any US-ASCII character (octets 0 - 127)>
|
||||
CTL = <any US-ASCII control character
|
||||
(octets 0 - 31) and DEL (127)>
|
||||
CR = <US-ASCII CR, carriage return (13)>
|
||||
LF = <US-ASCII LF, linefeed (10)>
|
||||
SP = <US-ASCII SP, space (32)>
|
||||
HT = <US-ASCII HT, horizontal tab (9)>
|
||||
NL = CR | LF
|
||||
LWSP = SP | HT | NL
|
||||
tspecial = ( | ) | "@" | , | ; | : | \ | "
|
||||
| / | [ | ] | ? | < | > | { | }
|
||||
| SP | HT | NL
|
||||
token = 1*<any CHAR except CTLs or tspecials>
|
||||
quoted-string = ( " *qdtext " ) | ( "<" *qatext ">")
|
||||
qdtext = <any CHAR except %" and CTLs but including LWSP>
|
||||
qatext = <any CHAR except "<", ">" and CTLs but including LWSP>
|
||||
mark = - | _ | . | ! | ~ | * | ' | ( | )
|
||||
unreserved = alphanum | mark
|
||||
reserved = ; | / | ? | : | @ | & | = | $ | ,
|
||||
uric = reserved | unreserved | escaped
|
||||
|
||||
Note that newline (NL) need not be a single character, but can
|
||||
be a character sequence.
|
||||
|
||||
3.2. The Script-URI
|
||||
|
||||
The 'Script-URI' is defined as the URI of the resource
|
||||
identified by the metavariables. Often, this URI will be the
|
||||
same as the URI requested by the client (the 'Client-URI');
|
||||
however, it need not be. Instead, it could be a URI invented
|
||||
by the server, and so it can only be used in the context of
|
||||
the server and its CGI interface.
|
||||
|
||||
The Script-URI has the syntax of generic-RL as defined in
|
||||
section 2.1 of RFC 1808 [7], with the exception that object
|
||||
parameters and fragment identifiers are not permitted:
|
||||
|
||||
<scheme>://<host><port>/<path>?<query>
|
||||
|
||||
The various components of the Script-URI are defined by some
|
||||
of the metavariables (see section 4 below);
|
||||
|
||||
script-uri = protocol "://" SERVER_NAME ":" SERVER_PORT enc-script
|
||||
enc-path-info "?" QUERY_STRING
|
||||
|
||||
where 'protocol' is obtained from SERVER_PROTOCOL,
|
||||
'enc-script' is a URL-encoded version of SCRIPT_NAME and
|
||||
'enc-path-info' is a URL-encoded version of PATH_INFO. See
|
||||
section 4.6 for more information about the PATH_INFO
|
||||
metavariable.
|
||||
|
||||
Note that the scheme and the protocol are not identical; for
|
||||
instance, a resource accessed via an SSL mechanism may have a
|
||||
Client-URI with a scheme of "https" rather than "http".
|
||||
CGI/1.1 provides no means for the script to reconstruct this,
|
||||
and therefore the Script-URI includes the base protocol used.
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred
|
||||
class
|
||||
GW_ENVIRONMENT
|
||||
|
||||
inherit
|
||||
GW_VARIABLES [STRING_8]
|
||||
|
||||
ITERABLE [STRING_8]
|
||||
|
||||
feature -- Access
|
||||
|
||||
table: HASH_TABLE [STRING, STRING]
|
||||
-- These variables are specific to requests made with HTTP.
|
||||
-- Interpretation of these variables may depend on the value of
|
||||
-- SERVER_PROTOCOL.
|
||||
--
|
||||
-- Environment variables with names beginning with "HTTP_" contain
|
||||
-- header data read from the client, if the protocol used was HTTP.
|
||||
-- The HTTP header name is converted to upper case, has all
|
||||
-- occurrences of "-" replaced with "_" and has "HTTP_" prepended to
|
||||
-- give the environment variable name. The header data may be
|
||||
-- presented as sent by the client, or may be rewritten in ways which
|
||||
-- do not change its semantics. If multiple headers with the same
|
||||
-- field-name are received then they must be rewritten as a single
|
||||
-- header having the same semantics. Similarly, a header that is
|
||||
-- received on more than one line must be merged onto a single line.
|
||||
-- The server must, if necessary, change the representation of the
|
||||
-- data (for example, the character set) to be appropriate for a CGI
|
||||
-- environment variable.
|
||||
--
|
||||
-- The server is not required to create environment variables for all
|
||||
-- the headers that it receives. In particular, it may remove any
|
||||
-- headers carrying authentication information, such as
|
||||
-- "Authorization"; it may remove headers whose value is available to
|
||||
-- the script via other variables, such as "Content-Length" and
|
||||
-- "Content-Type".
|
||||
--
|
||||
-- For convenience it might also include the following CGI entries
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access: table
|
||||
|
||||
new_cursor: HASH_TABLE_ITERATION_CURSOR [STRING_8, STRING_8]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
create Result.make (table)
|
||||
end
|
||||
|
||||
feature -- Common Gateway Interface - 1.1 8 January 1996
|
||||
|
||||
auth_type: detachable STRING
|
||||
-- This variable is specific to requests made via the "http"
|
||||
-- scheme.
|
||||
--
|
||||
-- If the Script-URI required access authentication for external
|
||||
-- access, then the server MUST set the value of this variable
|
||||
-- from the 'auth-scheme' token in the request's "Authorization"
|
||||
-- header field. Otherwise it is set to NULL.
|
||||
--
|
||||
-- AUTH_TYPE = "" | auth-scheme
|
||||
-- auth-scheme = "Basic" | "Digest" | token
|
||||
--
|
||||
-- HTTP access authentication schemes are described in section 11
|
||||
-- of the HTTP/1.1 specification [8]. The auth-scheme is not
|
||||
-- case-sensitive.
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts if the
|
||||
-- request header included an "Authorization" field that was
|
||||
-- authenticated.
|
||||
deferred
|
||||
end
|
||||
|
||||
content_length: detachable STRING
|
||||
-- This metavariable is set to the size of the message-body
|
||||
-- entity attached to the request, if any, in decimal number of
|
||||
-- octets. If no data are attached, then this metavariable is
|
||||
-- either NULL or not defined. The syntax is the same as for the
|
||||
-- HTTP "Content-Length" header field (section 14.14, HTTP/1.1
|
||||
-- specification [8]).
|
||||
--
|
||||
-- CONTENT_LENGTH = "" | 1*digit
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts if the
|
||||
-- request was accompanied by a message-body entity.
|
||||
deferred
|
||||
end
|
||||
|
||||
content_length_value: INTEGER
|
||||
-- Integer value related to `content_length"
|
||||
deferred
|
||||
end
|
||||
|
||||
content_type: detachable STRING
|
||||
-- If the request includes a message-body, CONTENT_TYPE is set to
|
||||
-- the Internet Media Type [9] of the attached entity if the type
|
||||
-- was provided via a "Content-type" field in the request header,
|
||||
-- or if the server can determine it in the absence of a supplied
|
||||
-- "Content-type" field. The syntax is the same as for the HTTP
|
||||
-- "Content-Type" header field.
|
||||
--
|
||||
-- CONTENT_TYPE = "" | media-type
|
||||
-- media-type = type "/" subtype *( ";" parameter)
|
||||
-- type = token
|
||||
-- subtype = token
|
||||
-- parameter = attribute "=" value
|
||||
-- attribute = token
|
||||
-- value = token | quoted-string
|
||||
--
|
||||
-- The type, subtype, and parameter attribute names are not
|
||||
-- case-sensitive. Parameter values MAY be case sensitive. Media
|
||||
-- types and their use in HTTP are described in section 3.7 of
|
||||
-- the HTTP/1.1 specification [8].
|
||||
--
|
||||
-- Example:
|
||||
--
|
||||
-- application/x-www-form-urlencoded
|
||||
--
|
||||
-- There is no default value for this variable. If and only if it
|
||||
-- is unset, then the script MAY attempt to determine the media
|
||||
-- type from the data received. If the type remains unknown, then
|
||||
-- the script MAY choose to either assume a content-type of
|
||||
-- application/octet-stream or reject the request with a 415
|
||||
-- ("Unsupported Media Type") error. See section 7.2.1.3 for more
|
||||
-- information about returning error status values.
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts if a
|
||||
-- "Content-Type" field was present in the original request
|
||||
-- header. If the server receives a request with an attached
|
||||
-- entity but no "Content-Type" header field, it MAY attempt to
|
||||
-- determine the correct datatype, or it MAY omit this
|
||||
-- metavariable when communicating the request information to the
|
||||
-- script.
|
||||
deferred
|
||||
end
|
||||
|
||||
gateway_interface: STRING
|
||||
-- This metavariable is set to the dialect of CGI being used by
|
||||
-- the server to communicate with the script. Syntax:
|
||||
--
|
||||
-- GATEWAY_INTERFACE = "CGI" "/" major "." minor
|
||||
-- major = 1*digit
|
||||
-- minor = 1*digit
|
||||
--
|
||||
-- Note that the major and minor numbers are treated as separate
|
||||
-- integers and hence each may be more than a single digit. Thus
|
||||
-- CGI/2.4 is a lower version than CGI/2.13 which in turn is
|
||||
-- lower than CGI/12.3. Leading zeros in either the major or the
|
||||
-- minor number MUST be ignored by scripts and SHOULD NOT be
|
||||
-- generated by servers.
|
||||
--
|
||||
-- This document defines the 1.1 version of the CGI interface
|
||||
-- ("CGI/1.1").
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
--
|
||||
-- The version of the CGI specification to which this server
|
||||
-- complies. Syntax:
|
||||
--
|
||||
-- GATEWAY_INTERFACE = "CGI" "/" 1*digit "." 1*digit
|
||||
--
|
||||
-- Note that the major and minor numbers are treated as separate
|
||||
-- integers and that each may be incremented higher than a single
|
||||
-- digit. Thus CGI/2.4 is a lower version than CGI/2.13 which in
|
||||
-- turn is lower than CGI/12.3. Leading zeros must be ignored by
|
||||
-- scripts and should never be generated by servers.
|
||||
deferred
|
||||
end
|
||||
|
||||
path_info: STRING assign update_path_info
|
||||
-- The PATH_INFO metavariable specifies a path to be interpreted
|
||||
-- by the CGI script. It identifies the resource or sub-resource
|
||||
-- to be returned by the CGI script, and it is derived from the
|
||||
-- portion of the URI path following the script name but
|
||||
-- preceding any query data. The syntax and semantics are similar
|
||||
-- to a decoded HTTP URL 'path' token (defined in RFC 2396 [4]),
|
||||
-- with the exception that a PATH_INFO of "/" represents a single
|
||||
-- void path segment.
|
||||
--
|
||||
-- PATH_INFO = "" | ( "/" path )
|
||||
-- path = segment *( "/" segment )
|
||||
-- segment = *pchar
|
||||
-- pchar = <any CHAR except "/">
|
||||
--
|
||||
-- The PATH_INFO string is the trailing part of the <path>
|
||||
-- component of the Script-URI (see section 3.2) that follows the
|
||||
-- SCRIPT_NAME portion of the path.
|
||||
--
|
||||
-- Servers MAY impose their own restrictions and limitations on
|
||||
-- what values they will accept for PATH_INFO, and MAY reject or
|
||||
-- edit any values they consider objectionable before passing
|
||||
-- them to the script.
|
||||
--
|
||||
-- Servers MUST make this URI component available to CGI scripts.
|
||||
-- The PATH_INFO value is case-sensitive, and the server MUST
|
||||
-- preserve the case of the PATH_INFO element of the URI when
|
||||
-- making it available to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
path_translated: detachable STRING
|
||||
-- PATH_TRANSLATED is derived by taking any path-info component
|
||||
-- of the request URI (see section 6.1.6), decoding it (see
|
||||
-- section 3.1), parsing it as a URI in its own right, and
|
||||
-- performing any virtual-to-physical translation appropriate to
|
||||
-- map it onto the server's document repository structure. If the
|
||||
-- request URI includes no path-info component, the
|
||||
-- PATH_TRANSLATED metavariable SHOULD NOT be defined.
|
||||
--
|
||||
--
|
||||
-- PATH_TRANSLATED = *CHAR
|
||||
--
|
||||
-- For a request such as the following:
|
||||
--
|
||||
-- http://somehost.com/cgi-bin/somescript/this%2eis%2epath%2einfo
|
||||
--
|
||||
-- the PATH_INFO component would be decoded, and the result
|
||||
-- parsed as though it were a request for the following:
|
||||
--
|
||||
-- http://somehost.com/this.is.the.path.info
|
||||
--
|
||||
-- This would then be translated to a location in the server's
|
||||
-- document repository, perhaps a filesystem path something like
|
||||
-- this:
|
||||
--
|
||||
-- /usr/local/www/htdocs/this.is.the.path.info
|
||||
--
|
||||
-- The result of the translation is the value of PATH_TRANSLATED.
|
||||
--
|
||||
-- The value of PATH_TRANSLATED may or may not map to a valid
|
||||
-- repository location. Servers MUST preserve the case of the
|
||||
-- path-info segment if and only if the underlying repository
|
||||
-- supports case-sensitive names. If the repository is only
|
||||
-- case-aware, case-preserving, or case-blind with regard to
|
||||
-- document names, servers are not required to preserve the case
|
||||
-- of the original segment through the translation.
|
||||
--
|
||||
-- The translation algorithm the server uses to derive
|
||||
-- PATH_TRANSLATED is implementation defined; CGI scripts which
|
||||
-- use this variable may suffer limited portability.
|
||||
--
|
||||
-- Servers SHOULD provide this metavariable to scripts if and
|
||||
-- only if the request URI includes a path-info component.
|
||||
deferred
|
||||
end
|
||||
|
||||
query_string: STRING
|
||||
-- A URL-encoded string; the <query> part of the Script-URI. (See
|
||||
-- section 3.2.)
|
||||
--
|
||||
-- QUERY_STRING = query-string
|
||||
-- query-string = *uric
|
||||
|
||||
-- The URL syntax for a query string is described in section 3 of
|
||||
-- RFC 2396 [4].
|
||||
--
|
||||
-- Servers MUST supply this value to scripts. The QUERY_STRING
|
||||
-- value is case-sensitive. If the Script-URI does not include a
|
||||
-- query component, the QUERY_STRING metavariable MUST be defined
|
||||
-- as an empty string ("").
|
||||
deferred
|
||||
end
|
||||
|
||||
remote_addr: STRING
|
||||
-- The IP address of the client sending the request to the
|
||||
-- server. This is not necessarily that of the user agent (such
|
||||
-- as if the request came through a proxy).
|
||||
--
|
||||
-- REMOTE_ADDR = hostnumber
|
||||
-- hostnumber = ipv4-address | ipv6-address
|
||||
|
||||
-- The definitions of ipv4-address and ipv6-address are provided
|
||||
-- in Appendix B of RFC 2373 [13].
|
||||
--
|
||||
-- Servers MUST supply this value to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
remote_host: detachable STRING
|
||||
-- The fully qualified domain name of the client sending the
|
||||
-- request to the server, if available, otherwise NULL. (See
|
||||
-- section 6.1.9.) Fully qualified domain names take the form as
|
||||
-- described in section 3.5 of RFC 1034 [10] and section 2.1 of
|
||||
-- RFC 1123 [5]. Domain names are not case sensitive.
|
||||
--
|
||||
-- Servers SHOULD provide this information to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
remote_ident: detachable STRING
|
||||
-- The identity information reported about the connection by a
|
||||
-- RFC 1413 [11] request to the remote agent, if available.
|
||||
-- Servers MAY choose not to support this feature, or not to
|
||||
-- request the data for efficiency reasons.
|
||||
--
|
||||
-- REMOTE_IDENT = *CHAR
|
||||
--
|
||||
-- The data returned may be used for authentication purposes, but
|
||||
-- the level of trust reposed in them should be minimal.
|
||||
--
|
||||
-- Servers MAY supply this information to scripts if the RFC1413
|
||||
-- [11] lookup is performed.
|
||||
deferred
|
||||
end
|
||||
|
||||
remote_user: detachable STRING
|
||||
-- If the request required authentication using the "Basic"
|
||||
-- mechanism (i.e., the AUTH_TYPE metavariable is set to
|
||||
-- "Basic"), then the value of the REMOTE_USER metavariable is
|
||||
-- set to the user-ID supplied. In all other cases the value of
|
||||
-- this metavariable is undefined.
|
||||
--
|
||||
-- REMOTE_USER = *OCTET
|
||||
--
|
||||
-- This variable is specific to requests made via the HTTP
|
||||
-- protocol.
|
||||
--
|
||||
-- Servers SHOULD provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
request_method: STRING
|
||||
-- The REQUEST_METHOD metavariable is set to the method with
|
||||
-- which the request was made, as described in section 5.1.1 of
|
||||
-- the HTTP/1.0 specification [3] and section 5.1.1 of the
|
||||
-- HTTP/1.1 specification [8].
|
||||
--
|
||||
-- REQUEST_METHOD = http-method
|
||||
-- http-method = "GET" | "HEAD" | "POST" | "PUT" | "DELETE"
|
||||
-- | "OPTIONS" | "TRACE" | extension-method
|
||||
-- extension-method = token
|
||||
--
|
||||
-- The method is case sensitive. CGI/1.1 servers MAY choose to
|
||||
-- process some methods directly rather than passing them to
|
||||
-- scripts.
|
||||
--
|
||||
-- This variable is specific to requests made with HTTP.
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
script_name: STRING
|
||||
-- The SCRIPT_NAME metavariable is set to a URL path that could
|
||||
-- identify the CGI script (rather than the script's output). The
|
||||
-- syntax and semantics are identical to a decoded HTTP URL
|
||||
-- 'path' token (see RFC 2396 [4]).
|
||||
--
|
||||
-- SCRIPT_NAME = "" | ( "/" [ path ] )
|
||||
--
|
||||
-- The SCRIPT_NAME string is some leading part of the <path>
|
||||
-- component of the Script-URI derived in some implementation
|
||||
-- defined manner. No PATH_INFO or QUERY_STRING segments (see
|
||||
-- sections 6.1.6 and 6.1.8) are included in the SCRIPT_NAME
|
||||
-- value.
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
server_name: STRING
|
||||
-- The SERVER_NAME metavariable is set to the name of the server,
|
||||
-- as derived from the <host> part of the Script-URI (see section
|
||||
-- 3.2).
|
||||
--
|
||||
-- SERVER_NAME = hostname | hostnumber
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
server_port: INTEGER
|
||||
-- The SERVER_PORT metavariable is set to the port on which the
|
||||
-- request was received, as used in the <port> part of the
|
||||
-- Script-URI.
|
||||
--
|
||||
-- SERVER_PORT = 1*digit
|
||||
--
|
||||
-- If the <port> portion of the script-URI is blank, the actual
|
||||
-- port number upon which the request was received MUST be
|
||||
-- supplied.
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
server_protocol: STRING
|
||||
-- The SERVER_PROTOCOL metavariable is set to the name and
|
||||
-- revision of the information protocol with which the request
|
||||
-- arrived. This is not necessarily the same as the protocol
|
||||
-- version used by the server in its response to the client.
|
||||
--
|
||||
-- SERVER_PROTOCOL = HTTP-Version | extension-version
|
||||
-- | extension-token
|
||||
-- HTTP-Version = "HTTP" "/" 1*digit "." 1*digit
|
||||
-- extension-version = protocol "/" 1*digit "." 1*digit
|
||||
-- protocol = 1*( alpha | digit | "+" | "-" | "." )
|
||||
-- extension-token = token
|
||||
--
|
||||
-- 'protocol' is a version of the <scheme> part of the
|
||||
-- Script-URI, but is not identical to it. For example, the
|
||||
-- scheme of a request may be "https" while the protocol remains
|
||||
-- "http". The protocol is not case sensitive, but by convention,
|
||||
-- 'protocol' is in upper case.
|
||||
--
|
||||
-- A well-known extension token value is "INCLUDED", which
|
||||
-- signals that the current document is being included as part of
|
||||
-- a composite document, rather than being the direct target of
|
||||
-- the client request.
|
||||
--
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
server_software: STRING
|
||||
-- The SERVER_SOFTWARE metavariable is set to the name and
|
||||
-- version of the information server software answering the
|
||||
-- request (and running the gateway).
|
||||
--
|
||||
-- SERVER_SOFTWARE = 1*product
|
||||
-- product = token [ "/" product-version ]
|
||||
-- product-version = token
|
||||
|
||||
-- Servers MUST provide this metavariable to scripts.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- HTTP_*
|
||||
|
||||
http_accept_charset: detachable STRING
|
||||
-- Contents of the Accept-Charset: header from the current request, if there is one.
|
||||
-- Example: 'iso-8859-1,*,utf-8'.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_accept_encoding: detachable STRING
|
||||
-- Contents of the Accept-Encoding: header from the current request, if there is one.
|
||||
-- Example: 'gzip'.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_accept_language: detachable STRING
|
||||
-- Contents of the Accept-Language: header from the current request, if there is one.
|
||||
-- Example: 'en'.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_connection: detachable STRING
|
||||
-- Contents of the Connection: header from the current request, if there is one.
|
||||
-- Example: 'Keep-Alive'.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_host: detachable STRING
|
||||
-- Contents of the Host: header from the current request, if there is one.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_referer: detachable STRING
|
||||
-- The address of the page (if any) which referred the user agent to the current page.
|
||||
-- This is set by the user agent.
|
||||
-- Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature.
|
||||
-- In short, it cannot really be trusted.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_user_agent: detachable STRING
|
||||
-- Contents of the User-Agent: header from the current request, if there is one.
|
||||
-- This is a string denoting the user agent being which is accessing the page.
|
||||
-- A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
|
||||
-- Among other things, you can use this value to tailor your page's
|
||||
-- output to the capabilities of the user agent.
|
||||
deferred
|
||||
end
|
||||
|
||||
http_authorization: detachable STRING
|
||||
-- Contents of the Authorization: header from the current request, if there is one.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Extra
|
||||
|
||||
request_uri: STRING
|
||||
-- The URI which was given in order to access this page; for instance, '/index.html'.
|
||||
deferred
|
||||
end
|
||||
|
||||
orig_path_info: detachable STRING
|
||||
-- Original version of `path_info' before processed by Current environment
|
||||
deferred
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT} -- Element change
|
||||
|
||||
set_orig_path_info (s: STRING)
|
||||
-- Set ORIG_PATH_INFO to `s'
|
||||
require
|
||||
s_attached: s /= Void
|
||||
deferred
|
||||
ensure
|
||||
same_orig_path_info: orig_path_info ~ variable ({GW_ENVIRONMENT_NAMES}.orig_path_info)
|
||||
end
|
||||
|
||||
unset_orig_path_info
|
||||
-- Unset ORIG_PATH_INFO
|
||||
deferred
|
||||
ensure
|
||||
unset: not has_variable ({GW_ENVIRONMENT_NAMES}.orig_path_info)
|
||||
end
|
||||
|
||||
update_path_info (a_path_info: like path_info)
|
||||
-- Updated PATH_INFO
|
||||
deferred
|
||||
ensure
|
||||
same_path_info: path_info ~ variable ({GW_ENVIRONMENT_NAMES}.path_info)
|
||||
end
|
||||
|
||||
invariant
|
||||
server_name_not_empty: not server_name.is_empty
|
||||
server_port_set: server_port /= 0
|
||||
request_method_attached: request_method /= Void
|
||||
path_info_attached: path_info /= Void
|
||||
query_string_attached: query_string /= Void
|
||||
remote_addr_attached: remote_addr /= Void
|
||||
|
||||
path_info_identical: path_info ~ variable ({GW_ENVIRONMENT_NAMES}.path_info)
|
||||
|
||||
;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
|
||||
292
library/server/ewsgi/src/context/gw_environment_variables.e
Normal file
292
library/server/ewsgi/src/context/gw_environment_variables.e
Normal file
@@ -0,0 +1,292 @@
|
||||
note
|
||||
description: "Summary description for {GW_ENVIRONMENT_VARIABLES}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_ENVIRONMENT_VARIABLES
|
||||
|
||||
inherit
|
||||
GW_ENVIRONMENT
|
||||
redefine
|
||||
update_path_info
|
||||
end
|
||||
|
||||
create
|
||||
make_with_variables
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_variables (a_vars: HASH_TABLE [STRING, STRING])
|
||||
-- Fill with variable from `a_vars'
|
||||
local
|
||||
s: detachable STRING
|
||||
do
|
||||
create empty_string.make_empty
|
||||
|
||||
create table.make (a_vars.count)
|
||||
from
|
||||
a_vars.start
|
||||
until
|
||||
a_vars.after
|
||||
loop
|
||||
table.force (a_vars.item_for_iteration, a_vars.key_for_iteration)
|
||||
a_vars.forth
|
||||
end
|
||||
|
||||
--| QUERY_STRING
|
||||
query_string := variable_or_default ({GW_ENVIRONMENT_NAMES}.query_string, empty_string, False)
|
||||
|
||||
--| REQUEST_METHOD
|
||||
request_method := variable_or_default ({GW_ENVIRONMENT_NAMES}.request_method, empty_string, False)
|
||||
|
||||
--| CONTENT_TYPE
|
||||
s := variable ({GW_ENVIRONMENT_NAMES}.content_type)
|
||||
if s /= Void and then not s.is_empty then
|
||||
content_type := s
|
||||
else
|
||||
content_type := Void
|
||||
end
|
||||
|
||||
--| CONTENT_LENGTH
|
||||
s := variable ({GW_ENVIRONMENT_NAMES}.content_length)
|
||||
content_length := s
|
||||
if s /= Void and then s.is_integer then
|
||||
content_length_value := s.to_integer
|
||||
else
|
||||
--| content_length := 0
|
||||
end
|
||||
|
||||
--| PATH_INFO
|
||||
path_info := variable_or_default ({GW_ENVIRONMENT_NAMES}.path_info, empty_string, False)
|
||||
|
||||
--| SERVER_NAME
|
||||
server_name := variable_or_default ({GW_ENVIRONMENT_NAMES}.server_name, empty_string, False)
|
||||
|
||||
--| SERVER_PORT
|
||||
s := variable ({GW_ENVIRONMENT_NAMES}.server_port)
|
||||
if s /= Void and then s.is_integer then
|
||||
server_port := s.to_integer
|
||||
else
|
||||
server_port := 80
|
||||
end
|
||||
|
||||
--| SCRIPT_NAME
|
||||
script_name := variable_or_default ({GW_ENVIRONMENT_NAMES}.script_name, empty_string, False)
|
||||
|
||||
--| REMOTE_ADDR
|
||||
remote_addr := variable_or_default ({GW_ENVIRONMENT_NAMES}.remote_addr, empty_string, False)
|
||||
|
||||
--| REMOTE_HOST
|
||||
remote_host := variable_or_default ({GW_ENVIRONMENT_NAMES}.remote_host, empty_string, False)
|
||||
|
||||
--| REQUEST_URI
|
||||
request_uri := variable_or_default ({GW_ENVIRONMENT_NAMES}.request_uri, empty_string, False)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
table: HASH_TABLE [STRING, STRING]
|
||||
|
||||
feature -- Access
|
||||
|
||||
variable (a_name: STRING): detachable STRING
|
||||
do
|
||||
Result := table.item (a_name)
|
||||
end
|
||||
|
||||
has_variable (a_name: STRING): BOOLEAN
|
||||
do
|
||||
Result := table.has_key (a_name)
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT, GW_APPLICATION, GW_CONNECTOR} -- Element change
|
||||
|
||||
set_variable (a_name: STRING; a_value: STRING)
|
||||
do
|
||||
table.force (a_value, a_name)
|
||||
end
|
||||
|
||||
unset_variable (a_name: STRING)
|
||||
do
|
||||
table.remove (a_name)
|
||||
end
|
||||
|
||||
feature -- Common Gateway Interface - 1.1 8 January 1996
|
||||
|
||||
auth_type: detachable STRING
|
||||
|
||||
content_length: detachable STRING
|
||||
|
||||
content_length_value: INTEGER
|
||||
|
||||
content_type: detachable STRING
|
||||
|
||||
gateway_interface: STRING
|
||||
do
|
||||
Result := variable_or_default ({GW_ENVIRONMENT_NAMES}.gateway_interface, "", False)
|
||||
end
|
||||
|
||||
path_info: STRING
|
||||
-- <Precursor/>
|
||||
--
|
||||
--| For instance, if the current script was accessed via the URL
|
||||
--| http://www.example.com/eiffel/path_info.exe/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.
|
||||
--|
|
||||
--| Note that is the PATH_INFO variable does not exists, the `path_info' value will be empty
|
||||
|
||||
path_translated: detachable STRING
|
||||
do
|
||||
Result := variable ({GW_ENVIRONMENT_NAMES}.path_translated)
|
||||
end
|
||||
|
||||
query_string: STRING
|
||||
|
||||
remote_addr: STRING
|
||||
|
||||
remote_host: STRING
|
||||
|
||||
remote_ident: detachable STRING
|
||||
do
|
||||
Result := variable ({GW_ENVIRONMENT_NAMES}.remote_ident)
|
||||
end
|
||||
|
||||
remote_user: detachable STRING
|
||||
do
|
||||
Result := variable ({GW_ENVIRONMENT_NAMES}.remote_user)
|
||||
end
|
||||
|
||||
request_method: STRING
|
||||
|
||||
script_name: STRING
|
||||
|
||||
server_name: STRING
|
||||
|
||||
server_port: INTEGER
|
||||
|
||||
server_protocol: STRING
|
||||
do
|
||||
Result := variable_or_default ({GW_ENVIRONMENT_NAMES}.server_protocol, "HTTP/1.0", True)
|
||||
end
|
||||
|
||||
server_software: STRING
|
||||
do
|
||||
Result := variable_or_default ({GW_ENVIRONMENT_NAMES}.server_software, "Unknown Server", True)
|
||||
end
|
||||
|
||||
feature -- HTTP_*
|
||||
|
||||
http_accept: detachable STRING
|
||||
-- Contents of the Accept: header from the current request, if there is one.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept)
|
||||
end
|
||||
|
||||
http_accept_charset: detachable STRING
|
||||
-- Contents of the Accept-Charset: header from the current request, if there is one.
|
||||
-- Example: 'iso-8859-1,*,utf-8'.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept_charset)
|
||||
end
|
||||
|
||||
http_accept_encoding: detachable STRING
|
||||
-- Contents of the Accept-Encoding: header from the current request, if there is one.
|
||||
-- Example: 'gzip'.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept_encoding)
|
||||
end
|
||||
|
||||
http_accept_language: detachable STRING
|
||||
-- Contents of the Accept-Language: header from the current request, if there is one.
|
||||
-- Example: 'en'.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_accept_language)
|
||||
end
|
||||
|
||||
http_connection: detachable STRING
|
||||
-- Contents of the Connection: header from the current request, if there is one.
|
||||
-- Example: 'Keep-Alive'.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_connection)
|
||||
end
|
||||
|
||||
http_host: detachable STRING
|
||||
-- Contents of the Host: header from the current request, if there is one.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_host)
|
||||
end
|
||||
|
||||
http_referer: detachable STRING
|
||||
-- The address of the page (if any) which referred the user agent to the current page.
|
||||
-- This is set by the user agent.
|
||||
-- Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature.
|
||||
-- In short, it cannot really be trusted.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_referer)
|
||||
end
|
||||
|
||||
http_user_agent: detachable STRING
|
||||
-- Contents of the User-Agent: header from the current request, if there is one.
|
||||
-- This is a string denoting the user agent being which is accessing the page.
|
||||
-- A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
|
||||
-- Among other things, you can use this value to tailor your page's
|
||||
-- output to the capabilities of the user agent.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_user_agent)
|
||||
end
|
||||
|
||||
http_authorization: detachable STRING
|
||||
-- Contents of the Authorization: header from the current request, if there is one.
|
||||
do
|
||||
Result := table.item ({GW_ENVIRONMENT_NAMES}.http_authorization)
|
||||
end
|
||||
|
||||
feature -- Extra
|
||||
|
||||
request_uri: STRING
|
||||
-- The URI which was given in order to access this page; for instance, '/index.html'.
|
||||
|
||||
orig_path_info: detachable STRING
|
||||
-- Original version of `path_info' before processed by Current environment
|
||||
|
||||
feature {GW_REQUEST_CONTEXT} -- Update
|
||||
|
||||
set_orig_path_info (s: STRING)
|
||||
do
|
||||
orig_path_info := s
|
||||
set_variable ({GW_ENVIRONMENT_NAMES}.orig_path_info, s)
|
||||
end
|
||||
|
||||
unset_orig_path_info
|
||||
do
|
||||
orig_path_info := Void
|
||||
unset_variable ({GW_ENVIRONMENT_NAMES}.orig_path_info)
|
||||
end
|
||||
|
||||
update_path_info (a_path_info: like path_info)
|
||||
do
|
||||
path_info := a_path_info
|
||||
set_variable ({GW_ENVIRONMENT_NAMES}.path_info, a_path_info)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
empty_string: STRING
|
||||
-- Reusable empty string
|
||||
|
||||
invariant
|
||||
empty_string_unchanged: empty_string.is_empty
|
||||
|
||||
;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
|
||||
56
library/server/ewsgi/src/context/gw_execution_variables.e
Normal file
56
library/server/ewsgi/src/context/gw_execution_variables.e
Normal file
@@ -0,0 +1,56 @@
|
||||
note
|
||||
description: "Summary description for {HTTPD_EXECUTION_VARIABLES}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_EXECUTION_VARIABLES
|
||||
|
||||
inherit
|
||||
GW_VARIABLES [STRING_32]
|
||||
undefine
|
||||
copy, is_equal
|
||||
end
|
||||
|
||||
HASH_TABLE [STRING_32, STRING]
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Status report
|
||||
|
||||
variable (a_name: STRING): detachable STRING_32
|
||||
do
|
||||
Result := item (a_name)
|
||||
end
|
||||
|
||||
has_variable (a_name: STRING): BOOLEAN
|
||||
do
|
||||
Result := has (a_name)
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT, GW_APPLICATION, GW_CONNECTOR} -- Element change
|
||||
|
||||
set_variable (a_name: STRING; a_value: STRING_32)
|
||||
do
|
||||
force (a_value, a_name)
|
||||
end
|
||||
|
||||
unset_variable (a_name: STRING)
|
||||
do
|
||||
remove (a_name)
|
||||
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
|
||||
244
library/server/ewsgi/src/context/gw_request_context.e
Normal file
244
library/server/ewsgi/src/context/gw_request_context.e
Normal file
@@ -0,0 +1,244 @@
|
||||
note
|
||||
description: "[
|
||||
Server request context of the httpd request
|
||||
|
||||
You can create your own descendant of this class to
|
||||
add/remove specific value or processing
|
||||
|
||||
This object is created by {GW_APPLICATION}.new_request_context
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_REQUEST_CONTEXT
|
||||
|
||||
feature -- Access: Input/Output
|
||||
|
||||
input: GW_INPUT_STREAM
|
||||
-- Server input channel
|
||||
deferred
|
||||
end
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
-- Server output channel
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access: global variable
|
||||
|
||||
variables: HASH_TABLE [STRING_32, STRING_32]
|
||||
-- Table containing all the various variables
|
||||
-- Warning: this is computed each time, if you change the content of other containers
|
||||
-- this won't update this Result's content, unless you query it again
|
||||
local
|
||||
vars: HASH_TABLE [STRING_GENERAL, STRING_GENERAL]
|
||||
do
|
||||
create Result.make (100)
|
||||
|
||||
vars := execution_variables
|
||||
from
|
||||
vars.start
|
||||
until
|
||||
vars.after
|
||||
loop
|
||||
Result.put (vars.item_for_iteration, vars.key_for_iteration)
|
||||
vars.forth
|
||||
end
|
||||
|
||||
vars := environment.table
|
||||
from
|
||||
vars.start
|
||||
until
|
||||
vars.after
|
||||
loop
|
||||
Result.put (vars.item_for_iteration, vars.key_for_iteration)
|
||||
vars.forth
|
||||
end
|
||||
|
||||
vars := parameters.table
|
||||
from
|
||||
vars.start
|
||||
until
|
||||
vars.after
|
||||
loop
|
||||
Result.put (vars.item_for_iteration, vars.key_for_iteration)
|
||||
vars.forth
|
||||
end
|
||||
|
||||
vars := form_fields.table
|
||||
from
|
||||
vars.start
|
||||
until
|
||||
vars.after
|
||||
loop
|
||||
Result.put (vars.item_for_iteration, vars.key_for_iteration)
|
||||
vars.forth
|
||||
end
|
||||
|
||||
vars := cookies_variables
|
||||
from
|
||||
vars.start
|
||||
until
|
||||
vars.after
|
||||
loop
|
||||
Result.put (vars.item_for_iteration, vars.key_for_iteration)
|
||||
vars.forth
|
||||
end
|
||||
end
|
||||
|
||||
variable (n8: STRING_8): detachable STRING_32
|
||||
-- Variable named `n' from any of the variables container
|
||||
-- and following a specific order
|
||||
-- execution, environment, get, post, cookies
|
||||
local
|
||||
s: detachable STRING_GENERAL
|
||||
do
|
||||
s := execution_variable (n8)
|
||||
if s = Void then
|
||||
s := environment_variable (n8)
|
||||
if s = Void then
|
||||
s := parameter (n8)
|
||||
if s = Void then
|
||||
s := form_field (n8)
|
||||
if s = Void then
|
||||
s := cookies_variable (n8)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if s /= Void then
|
||||
Result := s.as_string_32
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access: environment extra values
|
||||
|
||||
request_time: detachable DATE_TIME
|
||||
-- Request time (UTC)
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access: environment variables
|
||||
|
||||
environment: GW_ENVIRONMENT
|
||||
-- Environment variables
|
||||
deferred
|
||||
end
|
||||
|
||||
environment_variable (a_name: STRING): detachable STRING
|
||||
-- Environment variable related to `a_name'
|
||||
require
|
||||
a_name_valid: a_name /= Void and then not a_name.is_empty
|
||||
do
|
||||
Result := environment.variable (a_name)
|
||||
end
|
||||
|
||||
feature -- Access: execution variables
|
||||
|
||||
execution_variables: GW_EXECUTION_VARIABLES
|
||||
-- Execution variables set by the application
|
||||
deferred
|
||||
end
|
||||
|
||||
execution_variable (a_name: STRING): detachable STRING_32
|
||||
-- Execution variable related to `a_name'
|
||||
require
|
||||
a_name_valid: a_name /= Void and then not a_name.is_empty
|
||||
do
|
||||
Result := execution_variables.variable (a_name)
|
||||
end
|
||||
|
||||
feature -- URL Parameters
|
||||
|
||||
parameter (n: STRING): detachable STRING_32
|
||||
-- Parameter for name `n'.
|
||||
do
|
||||
Result := parameters.variable (n)
|
||||
end
|
||||
|
||||
parameters: GW_REQUEST_VARIABLES
|
||||
-- Variables extracted from QUERY_STRING
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Form fields and related
|
||||
|
||||
form_field (n: STRING): detachable STRING_32
|
||||
-- Field for name `n'.
|
||||
do
|
||||
Result := form_fields.variable (n)
|
||||
end
|
||||
|
||||
form_fields: GW_REQUEST_VARIABLES
|
||||
-- Variables sent by POST request
|
||||
deferred
|
||||
end
|
||||
|
||||
uploaded_files: HASH_TABLE [TUPLE [name: STRING; type: STRING; tmp_name: STRING; tmp_basename: STRING; error: INTEGER; size: INTEGER], STRING]
|
||||
-- Table of uploaded files information
|
||||
--| name: original path from the user
|
||||
--| type: content type
|
||||
--| tmp_name: path to temp file that resides on server
|
||||
--| tmp_base_name: basename of `tmp_name'
|
||||
--| error: if /= 0 , there was an error : TODO ...
|
||||
--| size: size of the file given by the http request
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Cookies
|
||||
|
||||
cookies_variable (n: STRING): detachable STRING
|
||||
-- Field for name `n'.
|
||||
do
|
||||
Result := cookies_variables.item (n)
|
||||
end
|
||||
|
||||
cookies_variables: HASH_TABLE [STRING, STRING]
|
||||
-- Expanded cookies variable
|
||||
deferred
|
||||
end
|
||||
|
||||
cookies: HASH_TABLE [GW_COOKIE, STRING]
|
||||
-- Cookies Information
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Uploaded File Handling
|
||||
|
||||
move_uploaded_file (a_filename: STRING; a_destination: STRING): BOOLEAN
|
||||
-- Move uploaded file `a_filename' to `a_destination'
|
||||
--| if this is not an uploaded file, do not move it.
|
||||
require
|
||||
a_filename_valid: a_filename /= Void and then not a_filename.is_empty
|
||||
a_destination_valid: a_destination /= Void and then not a_destination.is_empty
|
||||
deferred
|
||||
end
|
||||
|
||||
is_uploaded_file (a_filename: STRING): BOOLEAN
|
||||
-- Is `a_filename' a file uploaded via HTTP POST
|
||||
deferred
|
||||
end
|
||||
|
||||
feature {NONE} -- Temporary File handling
|
||||
|
||||
delete_uploaded_file (a_filename: STRING)
|
||||
-- Delete file `a_filename'
|
||||
require
|
||||
a_filename_valid: a_filename /= Void and then not a_filename.is_empty
|
||||
deferred
|
||||
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
|
||||
150
library/server/ewsgi/src/context/gw_request_variables.e
Normal file
150
library/server/ewsgi/src/context/gw_request_variables.e
Normal file
@@ -0,0 +1,150 @@
|
||||
note
|
||||
description: "[
|
||||
Variables/field related to the current request.
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_REQUEST_VARIABLES
|
||||
|
||||
inherit
|
||||
GW_VARIABLES [STRING_32]
|
||||
|
||||
ITERABLE [STRING_32]
|
||||
|
||||
create
|
||||
make,
|
||||
make_from_urlencoded
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (n: INTEGER)
|
||||
do
|
||||
create table.make (n)
|
||||
table.compare_objects
|
||||
end
|
||||
|
||||
make_from_urlencoded (a_content: STRING; decoding: BOOLEAN)
|
||||
do
|
||||
make (a_content.occurrences ('&') + 1)
|
||||
import_urlencoded (a_content, decoding)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
count: INTEGER
|
||||
-- Variables count
|
||||
do
|
||||
Result := table.count
|
||||
end
|
||||
|
||||
variable (a_name: STRING): detachable STRING_32
|
||||
do
|
||||
Result := table.item (a_name)
|
||||
end
|
||||
|
||||
has_variable (a_name: STRING): BOOLEAN
|
||||
do
|
||||
Result := table.has (a_name)
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT, GW_APPLICATION, GW_CONNECTOR} -- Element change
|
||||
|
||||
set_variable (a_name: STRING; a_value: STRING_32)
|
||||
do
|
||||
table.force (a_value, a_name)
|
||||
end
|
||||
|
||||
unset_variable (a_name: STRING)
|
||||
do
|
||||
table.remove (a_name)
|
||||
end
|
||||
|
||||
feature -- Import urlencoded
|
||||
|
||||
import_urlencoded (a_content: STRING; decoding: BOOLEAN)
|
||||
-- Import `a_content'
|
||||
local
|
||||
-- n, p, i, j: INTEGER
|
||||
-- s: STRING
|
||||
-- l_name,l_value: STRING_32
|
||||
do
|
||||
-- FIXME
|
||||
-- n := a_content.count
|
||||
-- if n > 0 then
|
||||
-- from
|
||||
-- p := 1
|
||||
-- until
|
||||
-- p = 0
|
||||
-- loop
|
||||
-- i := a_content.index_of ('&', p)
|
||||
-- if i = 0 then
|
||||
-- s := a_content.substring (p, n)
|
||||
-- p := 0
|
||||
-- else
|
||||
-- s := a_content.substring (p, i - 1)
|
||||
-- p := i + 1
|
||||
-- end
|
||||
-- if not s.is_empty then
|
||||
-- j := s.index_of ('=', 1)
|
||||
-- if j > 0 then
|
||||
-- l_name := s.substring (1, j - 1)
|
||||
-- l_value := s.substring (j + 1, s.count)
|
||||
-- if decoding then
|
||||
-- l_name := url_encoder.decoded_string (l_name)
|
||||
-- l_value := url_encoder.decoded_string (l_value)
|
||||
-- end
|
||||
-- add_variable (l_value, l_name)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
feature -- Access: table
|
||||
|
||||
new_cursor: HASH_TABLE_ITERATION_CURSOR [STRING_32, STRING_32]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
create Result.make (table)
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT} -- Element change
|
||||
|
||||
add_variable (v: STRING_32; k: STRING_32)
|
||||
-- Added `k,v' to variables table
|
||||
-- Not exported to common client
|
||||
-- Simulate Read Only Access
|
||||
require
|
||||
k_attached: k /= Void
|
||||
v_attached: v /= Void
|
||||
do
|
||||
table.force (v, k)
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT} -- Element change
|
||||
|
||||
table: HASH_TABLE [STRING_32, STRING_32]
|
||||
-- Variables table
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
-- url_encoder: URL_ENCODER
|
||||
-- once
|
||||
-- create Result
|
||||
-- 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
|
||||
77
library/server/ewsgi/src/context/gw_variables.e
Normal file
77
library/server/ewsgi/src/context/gw_variables.e
Normal file
@@ -0,0 +1,77 @@
|
||||
note
|
||||
description : "[
|
||||
Interface to access the variable stored in a container
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_VARIABLES [G -> STRING_GENERAL]
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_variable (a_name: STRING): BOOLEAN
|
||||
-- Has variable associated with `a_name'
|
||||
require
|
||||
a_name_not_empty: a_name /= Void and then not a_name.is_empty
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
variable (a_name: STRING): detachable G
|
||||
-- Value for variable associated with `a_name'
|
||||
-- If not found, return Void
|
||||
require
|
||||
a_name_not_empty: a_name /= Void and then not a_name.is_empty
|
||||
deferred
|
||||
end
|
||||
|
||||
variable_or_default (a_name: STRING; a_default: G; use_default_when_empty: BOOLEAN): G
|
||||
-- Value for variable `a_name'
|
||||
-- If not found, return `a_default'
|
||||
require
|
||||
a_name_not_empty: a_name /= Void and then not a_name.is_empty
|
||||
do
|
||||
if attached variable (a_name) as s then
|
||||
if use_default_when_empty and then s.is_empty then
|
||||
Result := a_default
|
||||
else
|
||||
Result := s
|
||||
end
|
||||
else
|
||||
Result := a_default
|
||||
end
|
||||
end
|
||||
|
||||
feature {GW_REQUEST_CONTEXT, GW_APPLICATION, GW_CONNECTOR} -- Element change
|
||||
|
||||
set_variable (a_name: STRING; a_value: G)
|
||||
require
|
||||
a_name_not_empty: a_name /= Void and then not a_name.is_empty
|
||||
deferred
|
||||
ensure
|
||||
variable_set: has_variable (a_name) and then variable (a_name) ~ a_value
|
||||
end
|
||||
|
||||
unset_variable (a_name: STRING)
|
||||
require
|
||||
a_name_not_empty: a_name /= Void and then not a_name.is_empty
|
||||
deferred
|
||||
ensure
|
||||
variable_unset: not has_variable (a_name)
|
||||
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
|
||||
40
library/server/ewsgi/src/gw_application.e
Normal file
40
library/server/ewsgi/src/gw_application.e
Normal file
@@ -0,0 +1,40 @@
|
||||
note
|
||||
description: "Summary description for {GW_APPLICATION}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_APPLICATION
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM)
|
||||
-- Process request with environment `env', and i/o streams `a_input' and `a_output'
|
||||
do
|
||||
execute (new_request_context (env, a_input, a_output))
|
||||
end
|
||||
|
||||
execute (ctx: GW_REQUEST_CONTEXT)
|
||||
-- Execute the request
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM): GW_REQUEST_CONTEXT
|
||||
deferred
|
||||
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
|
||||
44
library/server/ewsgi/src/gw_connector.e
Normal file
44
library/server/ewsgi/src/gw_connector.e
Normal file
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description: "Summary description for {GW_CONNECTOR}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_CONNECTOR
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_app: like application)
|
||||
do
|
||||
application := a_app
|
||||
initialize
|
||||
end
|
||||
|
||||
initialize
|
||||
-- Initialize connector
|
||||
do
|
||||
end
|
||||
|
||||
feature {NONE} -- Access
|
||||
|
||||
application: GW_APPLICATION
|
||||
-- Gateway Application
|
||||
|
||||
feature -- Server
|
||||
|
||||
launch
|
||||
deferred
|
||||
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
|
||||
76
library/server/ewsgi/src/gw_cookie.e
Normal file
76
library/server/ewsgi/src/gw_cookie.e
Normal file
@@ -0,0 +1,76 @@
|
||||
note
|
||||
description: "[
|
||||
Contains all information of a rfc2109 cookie that was read from the request header
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_COOKIE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
convert
|
||||
value: {READABLE_STRING_8, STRING_8, READABLE_STRING_GENERAL, STRING_GENERAL}
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: STRING; a_value: STRING)
|
||||
-- Creates current.
|
||||
require
|
||||
a_name_not_empty: a_name /= Void and then not a_name.is_empty
|
||||
a_value_not_empty: a_value /= Void and then not a_value.is_empty
|
||||
do
|
||||
name := a_name
|
||||
value := a_value
|
||||
ensure
|
||||
a_name_set: name = a_name
|
||||
a_value_set: value = a_value
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING
|
||||
-- Required. The name of the state information ("cookie") is NAME,
|
||||
-- and its value is VALUE. NAMEs that begin with $ are reserved for
|
||||
-- other uses and must not be used by applications.
|
||||
|
||||
value: STRING
|
||||
-- The VALUE is opaque to the user agent and may be anything the
|
||||
-- origin server chooses to send, possibly in a server-selected
|
||||
-- printable ASCII encoding. "Opaque" implies that the content is of
|
||||
-- interest and relevance only to the origin server. The content
|
||||
-- may, in fact, be readable by anyone that examines the Set-Cookie
|
||||
-- header.
|
||||
|
||||
feature -- Query
|
||||
|
||||
variables: detachable HASH_TABLE [STRING, STRING]
|
||||
-- Potential variable contained in the encoded cookie's value.
|
||||
|
||||
feature -- Status report
|
||||
|
||||
value_is_string (s: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Is `value' same string as `s'
|
||||
do
|
||||
Result := s.same_string (value)
|
||||
end
|
||||
|
||||
invariant
|
||||
name_attached: name /= Void
|
||||
value_attached: value /= Void
|
||||
|
||||
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
|
||||
89
library/server/ewsgi/src/gw_environment_names.e
Normal file
89
library/server/ewsgi/src/gw_environment_names.e
Normal file
@@ -0,0 +1,89 @@
|
||||
note
|
||||
description: "Summary description for {GW_ENVIRONMENT_NAMES}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_ENVIRONMENT_NAMES
|
||||
|
||||
feature -- Access
|
||||
|
||||
request_uri: STRING = "REQUEST_URI"
|
||||
|
||||
request_method: STRING = "REQUEST_METHOD"
|
||||
|
||||
query_string: STRING = "QUERY_STRING"
|
||||
|
||||
content_type: STRING = "CONTENT_TYPE"
|
||||
|
||||
content_length: STRING = "CONTENT_LENGTH"
|
||||
|
||||
path_info: STRING = "PATH_INFO"
|
||||
|
||||
path_translated: STRING = "PATH_TRANSLATED"
|
||||
|
||||
http_user_agent: STRING = "HTTP_USER_AGENT"
|
||||
|
||||
http_authorization: STRING = "HTTP_AUTHORIZATION"
|
||||
|
||||
http_host: STRING = "HTTP_HOST"
|
||||
|
||||
http_cookie: STRING = "HTTP_COOKIE"
|
||||
|
||||
http_from: STRING = "HTTP_FROM"
|
||||
|
||||
http_accept: STRING = "HTTP_ACCEPT"
|
||||
|
||||
http_accept_charset: STRING = "HTTP_ACCEPT_CHARSET"
|
||||
|
||||
http_accept_encoding: STRING = "HTTP_ACCEPT_ENCODING"
|
||||
|
||||
http_accept_language: STRING = "HTTP_ACCEPT_LANGUAGE"
|
||||
|
||||
http_connection: STRING = "HTTP_CONNECTION"
|
||||
|
||||
http_referer: STRING = "HTTP_REFERER"
|
||||
|
||||
gateway_interface: STRING = "GATEWAY_INTERFACE"
|
||||
|
||||
auth_type: STRING = "AUTH_TYPE"
|
||||
|
||||
remote_host: STRING = "REMOTE_HOST"
|
||||
|
||||
remote_addr: STRING = "REMOTE_ADDR"
|
||||
|
||||
remote_ident: STRING = "REMOTE_IDENT"
|
||||
|
||||
remote_user: STRING = "REMOTE_USER"
|
||||
|
||||
script_name: STRING = "SCRIPT_NAME"
|
||||
|
||||
server_name: STRING = "SERVER_NAME"
|
||||
|
||||
server_port: STRING = "SERVER_PORT"
|
||||
|
||||
server_protocol: STRING = "SERVER_PROTOCOL"
|
||||
|
||||
server_software: STRING = "SERVER_SOFTWARE"
|
||||
|
||||
feature -- Extra names
|
||||
|
||||
request_time: STRING = "REQUEST_TIME"
|
||||
|
||||
self: STRING = "SELF"
|
||||
|
||||
orig_path_info: STRING = "ORIG_PATH_INFO"
|
||||
|
||||
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
|
||||
66
library/server/ewsgi/src/gw_error.e
Normal file
66
library/server/ewsgi/src/gw_error.e
Normal file
@@ -0,0 +1,66 @@
|
||||
note
|
||||
description: "Summary description for {GW_ERROR}."
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_ERROR
|
||||
|
||||
inherit
|
||||
ERROR
|
||||
|
||||
HTTP_STATUS_CODE_MESSAGES
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_code: INTEGER)
|
||||
do
|
||||
code := a_code
|
||||
name := "HTTP Error"
|
||||
if attached http_status_code_message (a_code) as m then
|
||||
name := m
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
code: INTEGER
|
||||
|
||||
name: STRING
|
||||
|
||||
message: detachable STRING_32
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_message (m: like message)
|
||||
-- Set `message' to `m'
|
||||
require
|
||||
m_attached: m /= Void
|
||||
do
|
||||
message := m
|
||||
end
|
||||
|
||||
feature -- Visitor
|
||||
|
||||
process (a_visitor: ERROR_VISITOR)
|
||||
-- Process Current using `a_visitor'.
|
||||
do
|
||||
a_visitor.process_error (Current)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-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
|
||||
50
library/server/ewsgi/src/implementation/gw_application_imp.e
Normal file
50
library/server/ewsgi/src/implementation/gw_application_imp.e
Normal file
@@ -0,0 +1,50 @@
|
||||
note
|
||||
description: "Summary description for {GW_APPLICATION_IMP} "
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_APPLICATION_IMP
|
||||
|
||||
inherit
|
||||
GW_APPLICATION
|
||||
redefine
|
||||
process
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
request_count: INTEGER
|
||||
-- Request count
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM)
|
||||
-- Process request with environment `env', and i/o streams `a_input' and `a_output'
|
||||
do
|
||||
request_count := request_count + 1
|
||||
Precursor (env, a_input, a_output)
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM): GW_REQUEST_CONTEXT
|
||||
do
|
||||
create {GW_REQUEST_CONTEXT_IMP} Result.make (env, a_input, a_output)
|
||||
Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT")
|
||||
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
|
||||
818
library/server/ewsgi/src/implementation/gw_request_context_imp.e
Normal file
818
library/server/ewsgi/src/implementation/gw_request_context_imp.e
Normal file
@@ -0,0 +1,818 @@
|
||||
note
|
||||
description: "[
|
||||
Server request context of the httpd request
|
||||
|
||||
You can create your own descendant of this class to
|
||||
add/remove specific value or processing
|
||||
|
||||
This object is created by {GW_APPLICATION}.new_request_context
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_REQUEST_CONTEXT_IMP
|
||||
|
||||
inherit
|
||||
GW_REQUEST_CONTEXT
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (env: GW_ENVIRONMENT; a_input: like input; a_output: like output)
|
||||
require
|
||||
env_attached: env /= Void
|
||||
do
|
||||
create error_handler.make
|
||||
input := a_input
|
||||
output := a_output
|
||||
environment := env
|
||||
content_length := env.content_length_value
|
||||
create execution_variables.make (10)
|
||||
create uploaded_files.make (0)
|
||||
|
||||
raw_post_data_recorded := True
|
||||
|
||||
initialize
|
||||
analyze
|
||||
end
|
||||
|
||||
initialize
|
||||
-- Specific initialization
|
||||
local
|
||||
p: INTEGER
|
||||
dt: DATE_TIME
|
||||
env: like environment
|
||||
do
|
||||
env := environment
|
||||
--| Here one can set its own environment entries if needed
|
||||
|
||||
--| do not use `force', to avoid overwriting existing variable
|
||||
if attached env.request_uri as rq_uri then
|
||||
p := rq_uri.index_of ('?', 1)
|
||||
if p > 0 then
|
||||
env.set_variable (rq_uri.substring (1, p-1), {GW_ENVIRONMENT_NAMES}.self)
|
||||
else
|
||||
env.set_variable (rq_uri, {GW_ENVIRONMENT_NAMES}.self)
|
||||
end
|
||||
end
|
||||
if env.variable ({GW_ENVIRONMENT_NAMES}.request_time) = Void then
|
||||
env.set_variable (date_time_utilities.unix_time_stamp (Void).out, {GW_ENVIRONMENT_NAMES}.request_time)
|
||||
end
|
||||
end
|
||||
|
||||
analyze
|
||||
-- Analyze context, set various attributes and validate values
|
||||
do
|
||||
extract_variables
|
||||
end
|
||||
|
||||
feature -- Access: Input/Output
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
-- Server output channel
|
||||
|
||||
input: GW_INPUT_STREAM
|
||||
-- Server input channel
|
||||
|
||||
feature -- Status
|
||||
|
||||
raw_post_data_recorded: BOOLEAN assign set_raw_post_data_recorded
|
||||
-- Record RAW POST DATA in environment variables
|
||||
-- otherwise just forget about it
|
||||
-- Default: true
|
||||
--| warning: you might keep in memory big amount of memory ...
|
||||
|
||||
feature -- Error handling
|
||||
|
||||
has_error: BOOLEAN
|
||||
do
|
||||
Result := error_handler.has_error
|
||||
end
|
||||
|
||||
error_handler: ERROR_HANDLER
|
||||
-- Error handler
|
||||
-- By default initialized to new handler
|
||||
|
||||
feature -- Access: environment variables
|
||||
|
||||
environment: GW_ENVIRONMENT
|
||||
-- Environment variables
|
||||
|
||||
content_length: INTEGER
|
||||
-- Extracted Content-Length value
|
||||
|
||||
feature -- Access: execution variables
|
||||
|
||||
execution_variables: GW_EXECUTION_VARIABLES
|
||||
-- Execution variables set by the application
|
||||
|
||||
feature -- URL parameters
|
||||
|
||||
parameters: GW_REQUEST_VARIABLES
|
||||
local
|
||||
vars: like internal_parameters
|
||||
p,e: INTEGER
|
||||
rq_uri: like environment.request_uri
|
||||
s: detachable STRING
|
||||
do
|
||||
vars := internal_parameters
|
||||
if vars = Void then
|
||||
s := environment.query_string
|
||||
if s = Void then
|
||||
rq_uri := environment.request_uri
|
||||
p := rq_uri.index_of ('?', 1)
|
||||
if p > 0 then
|
||||
e := rq_uri.index_of ('#', p + 1)
|
||||
if e = 0 then
|
||||
e := rq_uri.count
|
||||
else
|
||||
e := e - 1
|
||||
end
|
||||
s := rq_uri.substring (p+1, e)
|
||||
end
|
||||
end
|
||||
if s /= Void and then not s.is_empty then
|
||||
create vars.make_from_urlencoded (s, True)
|
||||
else
|
||||
create vars.make (0)
|
||||
end
|
||||
internal_parameters := vars
|
||||
end
|
||||
Result := vars
|
||||
end
|
||||
|
||||
feature -- Form fields and related
|
||||
|
||||
form_fields: GW_REQUEST_VARIABLES
|
||||
local
|
||||
vars: like internal_form_fields
|
||||
s: STRING
|
||||
n: INTEGER
|
||||
l_type: detachable STRING
|
||||
do
|
||||
vars := internal_form_fields
|
||||
if vars = Void then
|
||||
n := content_length
|
||||
if n > 0 then
|
||||
l_type := environment.content_type
|
||||
if
|
||||
l_type /= Void and then
|
||||
l_type.starts_with ({HTTP_CONSTANTS}.multipart_form)
|
||||
then
|
||||
create vars.make (5)
|
||||
--| FIXME: optimization ... fetch the input data progressively, otherwise we might run out of memory ...
|
||||
s := form_input_data (n)
|
||||
analyze_multipart_form (l_type, s, vars)
|
||||
else
|
||||
s := form_input_data (n)
|
||||
create vars.make_from_urlencoded (s, True)
|
||||
end
|
||||
if raw_post_data_recorded then
|
||||
vars.add_variable (s, "RAW_POST_DATA")
|
||||
end
|
||||
else
|
||||
create vars.make (0)
|
||||
end
|
||||
internal_form_fields := vars
|
||||
end
|
||||
Result := vars
|
||||
end
|
||||
|
||||
uploaded_files: HASH_TABLE [TUPLE [name: STRING; type: STRING; tmp_name: STRING; tmp_basename: STRING; error: INTEGER; size: INTEGER], STRING]
|
||||
-- Table of uploaded files information
|
||||
--| name: original path from the user
|
||||
--| type: content type
|
||||
--| tmp_name: path to temp file that resides on server
|
||||
--| tmp_base_name: basename of `tmp_name'
|
||||
--| error: if /= 0 , there was an error : TODO ...
|
||||
--| size: size of the file given by the http request
|
||||
|
||||
feature -- Cookies
|
||||
|
||||
cookies_variables: HASH_TABLE [STRING, STRING]
|
||||
-- Expanded cookies variable
|
||||
local
|
||||
l_cookies: like cookies
|
||||
do
|
||||
l_cookies := cookies
|
||||
create Result.make (l_cookies.count)
|
||||
from
|
||||
l_cookies.start
|
||||
until
|
||||
l_cookies.after
|
||||
loop
|
||||
if attached l_cookies.item_for_iteration.variables as vars then
|
||||
from
|
||||
vars.start
|
||||
until
|
||||
vars.after
|
||||
loop
|
||||
Result.force (vars.item_for_iteration, vars.key_for_iteration)
|
||||
vars.forth
|
||||
end
|
||||
else
|
||||
check same_name: l_cookies.key_for_iteration.same_string (l_cookies.item_for_iteration.name) end
|
||||
Result.force (l_cookies.item_for_iteration.value, l_cookies.key_for_iteration)
|
||||
end
|
||||
l_cookies.forth
|
||||
end
|
||||
end
|
||||
|
||||
cookies: HASH_TABLE [GW_COOKIE, STRING]
|
||||
-- Cookies Information
|
||||
local
|
||||
i,j,p,n: INTEGER
|
||||
l_cookies: like internal_cookies
|
||||
k,v: STRING
|
||||
do
|
||||
l_cookies := internal_cookies
|
||||
if l_cookies = Void then
|
||||
if attached environment_variable ({GW_ENVIRONMENT_NAMES}.http_cookie) as s then
|
||||
create l_cookies.make (5)
|
||||
from
|
||||
n := s.count
|
||||
p := 1
|
||||
i := 1
|
||||
until
|
||||
p < 1
|
||||
loop
|
||||
i := s.index_of ('=', p)
|
||||
if i > 0 then
|
||||
j := s.index_of (';', i)
|
||||
if j = 0 then
|
||||
j := n + 1
|
||||
k := s.substring (p, i - 1)
|
||||
v := s.substring (i + 1, n)
|
||||
|
||||
p := 0 -- force termination
|
||||
else
|
||||
k := s.substring (p, i - 1)
|
||||
v := s.substring (i + 1, j - 1)
|
||||
p := j + 1
|
||||
end
|
||||
l_cookies.put (create {GW_COOKIE}.make (k,v), k)
|
||||
end
|
||||
end
|
||||
else
|
||||
create l_cookies.make (0)
|
||||
end
|
||||
internal_cookies := l_cookies
|
||||
end
|
||||
Result := l_cookies
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
-- script_absolute_url (a_path: STRING): STRING
|
||||
-- -- Absolute Url for the script if any, extended by `a_path'
|
||||
-- do
|
||||
-- Result := script_url (a_path)
|
||||
-- if attached http_host as h then
|
||||
-- Result.prepend (h)
|
||||
-- else
|
||||
-- --| Issue ??
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- script_url (a_path: STRING): STRING
|
||||
-- -- Url relative to script name if any, extended by `a_path'
|
||||
-- require
|
||||
-- a_path_attached: a_path /= Void
|
||||
-- local
|
||||
-- l_base_url: like script_url_base
|
||||
-- i,m,n: INTEGER
|
||||
-- l_rq_uri: like request_uri
|
||||
-- do
|
||||
-- l_base_url := script_url_base
|
||||
-- if l_base_url = Void then
|
||||
-- if attached environment.script_name as l_script_name then
|
||||
-- l_rq_uri := request_uri
|
||||
-- if l_rq_uri.starts_with (l_script_name) then
|
||||
-- l_base_url := l_script_name
|
||||
-- else
|
||||
-- --| Handle Rewrite url engine, to have clean path
|
||||
-- from
|
||||
-- i := 1
|
||||
-- m := l_rq_uri.count
|
||||
-- n := l_script_name.count
|
||||
-- until
|
||||
-- i > m or i > n or l_rq_uri[i] /= l_script_name[i]
|
||||
-- loop
|
||||
-- i := i + 1
|
||||
-- end
|
||||
-- if i > 1 then
|
||||
-- if l_rq_uri[i-1] = '/' then
|
||||
-- i := i -1
|
||||
-- end
|
||||
-- l_base_url := l_rq_uri.substring (1, i - 1)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- if l_base_url = Void then
|
||||
-- create l_base_url.make_empty
|
||||
-- end
|
||||
-- script_url_base := l_base_url
|
||||
-- end
|
||||
-- Result := l_base_url + a_path
|
||||
-- end
|
||||
|
||||
-- script_url_base: detachable STRING
|
||||
-- -- URL base of potential script
|
||||
|
||||
feature -- Access environment information
|
||||
|
||||
request_time: detachable DATE_TIME
|
||||
-- Request time (UTC)
|
||||
do
|
||||
if
|
||||
attached environment.variable ({GW_ENVIRONMENT_NAMES}.request_time) as t and then
|
||||
t.is_integer_64
|
||||
then
|
||||
Result := date_time_utilities.unix_time_stamp_to_date_time (t.to_integer_64)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_raw_post_data_recorded (b: BOOLEAN)
|
||||
-- Set `raw_post_data_recorded' to `b'
|
||||
do
|
||||
raw_post_data_recorded := b
|
||||
end
|
||||
|
||||
set_error_handler (ehdl: like error_handler)
|
||||
-- Set `error_handler' to `ehdl'
|
||||
do
|
||||
error_handler := ehdl
|
||||
end
|
||||
|
||||
update_path_info (env: GW_ENVIRONMENT)
|
||||
-- Fix and update PATH_INFO value if needed
|
||||
local
|
||||
l_path_info: STRING
|
||||
do
|
||||
l_path_info := env.path_info
|
||||
--| Warning
|
||||
--| on IIS: we might have PATH_INFO = /sample.exe/foo/bar
|
||||
--| on apache: PATH_INFO = /foo/bar
|
||||
--| So, we might need to check with SCRIPT_NAME and remove it on IIS
|
||||
--| store original PATH_INFO in ORIG_PATH_INFO
|
||||
if l_path_info.is_empty then
|
||||
env.unset_orig_path_info
|
||||
else
|
||||
env.set_orig_path_info (l_path_info)
|
||||
if attached env.script_name as l_script_name then
|
||||
if l_path_info.starts_with (l_script_name) then
|
||||
env.path_info := l_path_info.substring (l_script_name.count + 1 , l_path_info.count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Uploaded File Handling
|
||||
|
||||
move_uploaded_file (a_filename: STRING; a_destination: STRING): BOOLEAN
|
||||
-- Move uploaded file `a_filename' to `a_destination'
|
||||
--| if this is not an uploaded file, do not move it.
|
||||
local
|
||||
f: RAW_FILE
|
||||
do
|
||||
if is_uploaded_file (a_filename) then
|
||||
create f.make (a_filename)
|
||||
if f.exists then
|
||||
f.change_name (a_destination)
|
||||
Result := True
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
is_uploaded_file (a_filename: STRING): BOOLEAN
|
||||
-- Is `a_filename' a file uploaded via HTTP Form
|
||||
local
|
||||
l_files: like uploaded_files
|
||||
do
|
||||
l_files := uploaded_files
|
||||
if not l_files.is_empty then
|
||||
from
|
||||
l_files.start
|
||||
until
|
||||
l_files.after or Result
|
||||
loop
|
||||
if l_files.item_for_iteration.tmp_name.same_string (a_filename) then
|
||||
Result := True
|
||||
end
|
||||
l_files.forth
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Temporary File handling
|
||||
|
||||
delete_uploaded_file (a_filename: STRING)
|
||||
-- Delete file `a_filename'
|
||||
local
|
||||
f: RAW_FILE
|
||||
do
|
||||
if is_uploaded_file (a_filename) then
|
||||
create f.make (a_filename)
|
||||
if f.exists and then f.is_writable then
|
||||
f.delete
|
||||
else
|
||||
error_handler.add_custom_error (0, "Can not delete file", "Can not delete file %""+ a_filename +"%"")
|
||||
end
|
||||
else
|
||||
error_handler.add_custom_error (0, "Not uploaded file", "This file %""+ a_filename +"%" is not an uploaded file.")
|
||||
end
|
||||
end
|
||||
|
||||
save_uploaded_file (a_content: STRING; a_filename: STRING): detachable TUPLE [name: STRING; basename: STRING]
|
||||
-- Save uploaded file content to `a_filename'
|
||||
local
|
||||
bn: STRING
|
||||
l_safe_name: STRING
|
||||
f: RAW_FILE
|
||||
dn: STRING
|
||||
fn: FILE_NAME
|
||||
d: DIRECTORY
|
||||
n: INTEGER
|
||||
rescued: BOOLEAN
|
||||
do
|
||||
if not rescued then
|
||||
dn := (create {EXECUTION_ENVIRONMENT}).current_working_directory
|
||||
create d.make (dn)
|
||||
if d.exists and then d.is_writable then
|
||||
l_safe_name := safe_filename (a_filename)
|
||||
from
|
||||
create fn.make_from_string (dn)
|
||||
bn := "tmp-" + l_safe_name
|
||||
fn.set_file_name (bn)
|
||||
create f.make (fn.string)
|
||||
n := 0
|
||||
until
|
||||
not f.exists
|
||||
or else n > 1_000
|
||||
loop
|
||||
n := n + 1
|
||||
fn.make_from_string (dn)
|
||||
bn := "tmp-" + n.out + "-" + l_safe_name
|
||||
fn.set_file_name (bn)
|
||||
f.make (fn.string)
|
||||
end
|
||||
|
||||
if not f.exists or else f.is_writable then
|
||||
f.open_write
|
||||
f.put_string (a_content)
|
||||
f.close
|
||||
Result := [f.name, bn]
|
||||
else
|
||||
Result := Void
|
||||
end
|
||||
else
|
||||
error_handler.add_custom_error (0, "Directory not writable", "Can not create file in directory %""+ dn +"%"")
|
||||
end
|
||||
else
|
||||
Result := Void
|
||||
end
|
||||
rescue
|
||||
rescued := True
|
||||
retry
|
||||
end
|
||||
|
||||
safe_filename (fn: STRING): STRING
|
||||
local
|
||||
c: CHARACTER
|
||||
i, n, p: INTEGER
|
||||
l_accentued, l_non_accentued: STRING
|
||||
do
|
||||
l_accentued := "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
||||
l_non_accentued := "AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy"
|
||||
|
||||
--| Compute safe filename, to avoid creating impossible filename, or dangerous one
|
||||
from
|
||||
i := 1
|
||||
n := fn.count
|
||||
create Result.make (n)
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
c := fn[i]
|
||||
inspect c
|
||||
when '.', '-', '_' then
|
||||
Result.extend (c)
|
||||
when 'A' .. 'Z', 'a' .. 'z', '0' .. '9' then
|
||||
Result.extend (c)
|
||||
else
|
||||
p := l_accentued.index_of (c, 1)
|
||||
if p > 0 then
|
||||
Result.extend (l_non_accentued[p])
|
||||
else
|
||||
Result.extend ('-')
|
||||
end
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: Form analyzer
|
||||
|
||||
analyze_multipart_form (t: STRING; s: STRING; vars: like form_fields)
|
||||
-- Analyze multipart form content
|
||||
--| FIXME[2011-06-21]: integrate eMIME parser library
|
||||
require
|
||||
t_attached: t /= Void
|
||||
s_attached: s /= Void
|
||||
vars_attached: vars /= Void
|
||||
local
|
||||
p,i,next_b: INTEGER
|
||||
l_boundary_prefix: STRING
|
||||
l_boundary: STRING
|
||||
l_boundary_len: INTEGER
|
||||
m: STRING
|
||||
is_crlf: BOOLEAN
|
||||
do
|
||||
p := t.substring_index ("boundary=", 1)
|
||||
if p > 0 then
|
||||
l_boundary := t.substring (p + 9, t.count)
|
||||
p := s.substring_index (l_boundary, 1)
|
||||
if p > 1 then
|
||||
l_boundary_prefix := s.substring (1, p - 1)
|
||||
l_boundary := l_boundary_prefix + l_boundary
|
||||
else
|
||||
create l_boundary_prefix.make_empty
|
||||
end
|
||||
l_boundary_len := l_boundary.count
|
||||
--| Let's support either %R%N and %N ...
|
||||
--| Since both cases might occurs (for instance, our implementation of CGI does not have %R%N)
|
||||
--| then let's be as flexible as possible on this.
|
||||
is_crlf := s[l_boundary_len + 1] = '%R'
|
||||
from
|
||||
i := 1 + l_boundary_len + 1
|
||||
if is_crlf then
|
||||
i := i + 1 --| +1 = CR = %R
|
||||
end
|
||||
next_b := i
|
||||
until
|
||||
i = 0
|
||||
loop
|
||||
next_b := s.substring_index (l_boundary, i)
|
||||
if next_b > 0 then
|
||||
if is_crlf then
|
||||
m := s.substring (i, next_b - 1 - 2) --| 2 = CR LF = %R %N
|
||||
else
|
||||
m := s.substring (i, next_b - 1 - 1) --| 1 = LF = %N
|
||||
end
|
||||
analyze_multipart_form_input (m, vars)
|
||||
i := next_b + l_boundary_len + 1
|
||||
if is_crlf then
|
||||
i := i + 1 --| +1 = CR = %R
|
||||
end
|
||||
else
|
||||
if is_crlf then
|
||||
i := i + 1
|
||||
end
|
||||
m := s.substring (i - 1, s.count)
|
||||
m.right_adjust
|
||||
if not l_boundary_prefix.same_string (m) then
|
||||
error_handler.add_custom_error (0, "Invalid form data", "Invalid ending for form data from input")
|
||||
end
|
||||
i := next_b
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
analyze_multipart_form_input (s: STRING; vars_post: like form_fields)
|
||||
-- Analyze multipart entry
|
||||
require
|
||||
s_not_empty: s /= Void and then not s.is_empty
|
||||
local
|
||||
n, i,p, b,e: INTEGER
|
||||
l_name, l_filename, l_content_type: detachable STRING
|
||||
l_header: detachable STRING
|
||||
l_content: detachable STRING
|
||||
l_line: detachable STRING
|
||||
do
|
||||
from
|
||||
p := 1
|
||||
n := s.count
|
||||
until
|
||||
p > n or l_header /= Void
|
||||
loop
|
||||
inspect s[p]
|
||||
when '%R' then -- CR
|
||||
if
|
||||
n >= p + 3 and then
|
||||
s[p+1] = '%N' and then -- LF
|
||||
s[p+2] = '%R' and then -- CR
|
||||
s[p+3] = '%N' -- LF
|
||||
then
|
||||
l_header := s.substring (1, p + 1)
|
||||
l_content := s.substring (p + 4, n)
|
||||
end
|
||||
when '%N' then
|
||||
if
|
||||
n >= p + 1 and then
|
||||
s[p+1] = '%N'
|
||||
then
|
||||
l_header := s.substring (1, p)
|
||||
l_content := s.substring (p + 2, n)
|
||||
end
|
||||
else
|
||||
end
|
||||
p := p + 1
|
||||
end
|
||||
if l_header /= Void and l_content /= Void then
|
||||
from
|
||||
i := 1
|
||||
n := l_header.count
|
||||
until
|
||||
i = 0 or i > n
|
||||
loop
|
||||
l_line := Void
|
||||
b := i
|
||||
p := l_header.index_of ('%N', b)
|
||||
if p > 0 then
|
||||
if l_header[p - 1] = '%R' then
|
||||
p := p - 1
|
||||
i := p + 2
|
||||
else
|
||||
i := p + 1
|
||||
end
|
||||
end
|
||||
if p > 0 then
|
||||
l_line := l_header.substring (b, p - 1)
|
||||
if l_line.starts_with ("Content-Disposition: form-data") then
|
||||
p := l_line.substring_index ("name=", 1)
|
||||
if p > 0 then
|
||||
p := p + 4 --| 4 = ("name=").count - 1
|
||||
if l_line.valid_index (p+1) and then l_line[p+1] = '%"' then
|
||||
p := p + 1
|
||||
e := l_line.index_of ('"', p + 1)
|
||||
else
|
||||
e := l_line.index_of (';', p + 1)
|
||||
if e = 0 then
|
||||
e := l_line.count
|
||||
end
|
||||
end
|
||||
l_name := l_header.substring (p + 1, e - 1)
|
||||
end
|
||||
|
||||
p := l_line.substring_index ("filename=", 1)
|
||||
if p > 0 then
|
||||
p := p + 8 --| 8 = ("filename=").count - 1
|
||||
if l_line.valid_index (p+1) and then l_line[p+1] = '%"' then
|
||||
p := p + 1
|
||||
e := l_line.index_of ('"', p + 1)
|
||||
else
|
||||
e := l_line.index_of (';', p + 1)
|
||||
if e = 0 then
|
||||
e := l_line.count
|
||||
end
|
||||
end
|
||||
l_filename := l_header.substring (p + 1, e - 1)
|
||||
end
|
||||
elseif l_line.starts_with ("Content-Type: ") then
|
||||
l_content_type := l_line.substring (15, l_line.count)
|
||||
end
|
||||
else
|
||||
i := 0
|
||||
end
|
||||
end
|
||||
if l_name /= Void then
|
||||
if l_filename /= Void then
|
||||
if l_content_type = Void then
|
||||
l_content_type := default_content_type
|
||||
end
|
||||
if attached save_uploaded_file (l_content, l_filename) as l_saved_fn_info then
|
||||
uploaded_files.force ([l_filename, l_content_type, l_saved_fn_info.name, l_saved_fn_info.basename, 0, l_content.count], l_name)
|
||||
else
|
||||
uploaded_files.force ([l_filename, l_content_type, "", "", -1, l_content.count], l_name)
|
||||
end
|
||||
else
|
||||
vars_post.add_variable (l_content, l_name)
|
||||
end
|
||||
else
|
||||
error_handler.add_custom_error (0, "unamed multipart entry", Void)
|
||||
end
|
||||
else
|
||||
error_handler.add_custom_error (0, "missformed multipart entry", Void)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Internal value
|
||||
|
||||
default_content_type: STRING = "text/plain"
|
||||
-- Default content type
|
||||
|
||||
form_input_data (nb: INTEGER): STRING
|
||||
-- data from input form
|
||||
local
|
||||
n: INTEGER
|
||||
t: STRING
|
||||
do
|
||||
from
|
||||
n := nb
|
||||
create Result.make (n)
|
||||
if n > 1_024 then
|
||||
n := 1_024
|
||||
end
|
||||
until
|
||||
n <= 0
|
||||
loop
|
||||
read_input (n)
|
||||
t := last_input_string
|
||||
Result.append_string (t)
|
||||
if t.count < n then
|
||||
n := 0
|
||||
end
|
||||
n := nb - t.count
|
||||
end
|
||||
end
|
||||
|
||||
internal_parameters: detachable like parameters
|
||||
-- cached value for `parameters'
|
||||
|
||||
internal_form_fields: detachable like form_fields
|
||||
-- cached value for `form_fields'
|
||||
|
||||
internal_cookies: detachable like cookies
|
||||
-- cached value for `cookies'
|
||||
|
||||
feature {NONE} -- I/O: implementation
|
||||
|
||||
read_input (nb: INTEGER)
|
||||
-- Read `nb' bytes from `input'
|
||||
do
|
||||
input.read_stream (nb)
|
||||
end
|
||||
|
||||
last_input_string: STRING
|
||||
-- Last string read from `input'
|
||||
do
|
||||
Result := input.last_string
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
report_bad_request_error (a_message: detachable STRING)
|
||||
-- Report error
|
||||
local
|
||||
e: GW_ERROR
|
||||
do
|
||||
create e.make ({HTTP_STATUS_CODE}.bad_request)
|
||||
if a_message /= Void then
|
||||
e.set_message (a_message)
|
||||
end
|
||||
error_handler.add_error (e)
|
||||
end
|
||||
|
||||
extract_variables
|
||||
-- Extract relevant environment variables
|
||||
local
|
||||
s: detachable STRING
|
||||
do
|
||||
s := environment.request_uri
|
||||
if s.is_empty then
|
||||
report_bad_request_error ("Missing URI")
|
||||
end
|
||||
if not has_error then
|
||||
s := environment.request_method
|
||||
if s.is_empty then
|
||||
report_bad_request_error ("Missing request method")
|
||||
end
|
||||
end
|
||||
if not has_error then
|
||||
s := environment.http_host
|
||||
if s = Void or else s.is_empty then
|
||||
report_bad_request_error ("Missing host header")
|
||||
end
|
||||
end
|
||||
if not has_error then
|
||||
update_path_info (environment)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: utilities
|
||||
|
||||
date_time_utilities: HTTP_DATE_TIME_UTILITIES
|
||||
-- Utilities classes related to date and time.
|
||||
once
|
||||
create Result
|
||||
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
|
||||
40
library/server/ewsgi/src/stream/gw_input_stream.e
Normal file
40
library/server/ewsgi/src/stream/gw_input_stream.e
Normal file
@@ -0,0 +1,40 @@
|
||||
note
|
||||
description : "[
|
||||
Objects that represents the input stream
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_INPUT_STREAM
|
||||
|
||||
feature -- Access
|
||||
|
||||
last_string: STRING_8
|
||||
-- Last read string from stream
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
read_stream (n: INTEGER)
|
||||
require
|
||||
n_positive: n > 0
|
||||
deferred
|
||||
ensure
|
||||
at_max_n: last_string.count <= n
|
||||
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
|
||||
37
library/server/ewsgi/src/stream/gw_output_stream.e
Normal file
37
library/server/ewsgi/src/stream/gw_output_stream.e
Normal file
@@ -0,0 +1,37 @@
|
||||
note
|
||||
description : "[
|
||||
Objects that represents the output stream
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_OUTPUT_STREAM
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
put_string (s: STRING_8)
|
||||
-- Write `s' into the output stream
|
||||
require
|
||||
s_not_empty: s /= Void and then not s.is_empty
|
||||
deferred
|
||||
end
|
||||
|
||||
flush
|
||||
-- Flush the output stream
|
||||
deferred
|
||||
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
|
||||
Reference in New Issue
Block a user