Apply prefix renaming from the specification
Reduced the number of EWSGI classes
This commit is contained in:
@@ -9,7 +9,7 @@ deferred class
|
||||
GW_APPLICATION_IMP
|
||||
|
||||
inherit
|
||||
GW_APPLICATION
|
||||
EWSGI_APPLICATION
|
||||
redefine
|
||||
process,
|
||||
rescue_execute
|
||||
@@ -22,14 +22,14 @@ feature -- Access
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM)
|
||||
process (env: EWSGI_ENVIRONMENT; a_input: EWSGI_INPUT_STREAM; a_output: EWSGI_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
|
||||
|
||||
rescue_execute (req: detachable GW_REQUEST; res: detachable GW_RESPONSE; a_exception: detachable EXCEPTION)
|
||||
rescue_execute (req: detachable EWSGI_REQUEST; res: detachable EWSGI_RESPONSE; a_exception: detachable EXCEPTION)
|
||||
-- Operation processed on rescue of `execute'
|
||||
do
|
||||
if
|
||||
@@ -44,13 +44,13 @@ feature -- Execution
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_request (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST
|
||||
new_request (env: EWSGI_ENVIRONMENT; a_input: EWSGI_INPUT_STREAM): EWSGI_REQUEST
|
||||
do
|
||||
create {GW_REQUEST_IMP} Result.make (env, a_input)
|
||||
Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT")
|
||||
end
|
||||
|
||||
new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
||||
new_response (req: EWSGI_REQUEST; a_output: EWSGI_OUTPUT_STREAM): EWSGI_RESPONSE
|
||||
do
|
||||
create {GW_RESPONSE_IMP} Result.make (a_output)
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ note
|
||||
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
|
||||
This object is created by {EWSGI_APPLICATION}.new_request
|
||||
]"
|
||||
legal: "See notice at end of class."
|
||||
status: "See notice at end of class."
|
||||
@@ -16,14 +16,14 @@ class
|
||||
GW_REQUEST_IMP
|
||||
|
||||
inherit
|
||||
GW_REQUEST
|
||||
EWSGI_REQUEST
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (env: GW_ENVIRONMENT; a_input: like input)
|
||||
make (env: EWSGI_ENVIRONMENT; a_input: like input)
|
||||
require
|
||||
env_attached: env /= Void
|
||||
do
|
||||
@@ -53,13 +53,13 @@ feature {NONE} -- Initialization
|
||||
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)
|
||||
env.set_variable (rq_uri.substring (1, p-1), {EWSGI_ENVIRONMENT_NAMES}.self)
|
||||
else
|
||||
env.set_variable (rq_uri, {GW_ENVIRONMENT_NAMES}.self)
|
||||
env.set_variable (rq_uri, {EWSGI_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)
|
||||
if env.variable ({EWSGI_ENVIRONMENT_NAMES}.request_time) = Void then
|
||||
env.set_variable (date_time_utilities.unix_time_stamp (Void).out, {EWSGI_ENVIRONMENT_NAMES}.request_time)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,7 +71,7 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Access: Input
|
||||
|
||||
input: GW_INPUT_STREAM
|
||||
input: EWSGI_INPUT_STREAM
|
||||
-- Server input channel
|
||||
|
||||
feature -- Status
|
||||
@@ -95,7 +95,7 @@ feature -- Error handling
|
||||
|
||||
feature -- Access: environment variables
|
||||
|
||||
environment: GW_ENVIRONMENT
|
||||
environment: EWSGI_ENVIRONMENT
|
||||
-- Environment variables
|
||||
|
||||
environment_variable (a_name: STRING): detachable STRING
|
||||
@@ -202,7 +202,7 @@ feature -- Form fields and related
|
||||
Result := form_fields.variable (a_name)
|
||||
end
|
||||
|
||||
uploaded_files: HASH_TABLE [GW_UPLOADED_FILE_DATA, STRING]
|
||||
uploaded_files: HASH_TABLE [EWSGI_UPLOADED_FILE_DATA, STRING]
|
||||
-- Table of uploaded files information
|
||||
--| name: original path from the user
|
||||
--| type: content type
|
||||
@@ -248,7 +248,7 @@ feature -- Cookies
|
||||
Result := cookies_variables.item (a_name)
|
||||
end
|
||||
|
||||
cookies: HASH_TABLE [GW_COOKIE, STRING]
|
||||
cookies: HASH_TABLE [EWSGI_COOKIE, STRING]
|
||||
-- Cookies Information
|
||||
local
|
||||
i,j,p,n: INTEGER
|
||||
@@ -257,7 +257,7 @@ feature -- Cookies
|
||||
do
|
||||
l_cookies := internal_cookies
|
||||
if l_cookies = Void then
|
||||
if attached environment_variable ({GW_ENVIRONMENT_NAMES}.http_cookie) as s then
|
||||
if attached environment_variable ({EWSGI_ENVIRONMENT_NAMES}.http_cookie) as s then
|
||||
create l_cookies.make (5)
|
||||
from
|
||||
n := s.count
|
||||
@@ -280,7 +280,7 @@ feature -- Cookies
|
||||
v := s.substring (i + 1, j - 1)
|
||||
p := j + 1
|
||||
end
|
||||
l_cookies.put (create {GW_COOKIE}.make (k,v), k)
|
||||
l_cookies.put (create {EWSGI_COOKIE}.make (k,v), k)
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -385,7 +385,7 @@ feature -- Access extra information
|
||||
-- Request time (UTC)
|
||||
do
|
||||
if
|
||||
attached environment.variable ({GW_ENVIRONMENT_NAMES}.request_time) as t and then
|
||||
attached environment.variable ({EWSGI_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)
|
||||
@@ -466,7 +466,7 @@ feature -- Element change
|
||||
error_handler := ehdl
|
||||
end
|
||||
|
||||
update_path_info (env: GW_ENVIRONMENT)
|
||||
update_path_info (env: EWSGI_ENVIRONMENT)
|
||||
-- Fix and update PATH_INFO value if needed
|
||||
local
|
||||
l_path_info: STRING
|
||||
@@ -513,7 +513,7 @@ feature -- Uploaded File Handling
|
||||
|
||||
feature {NONE} -- Temporary File handling
|
||||
|
||||
delete_uploaded_file (uf: GW_UPLOADED_FILE_DATA)
|
||||
delete_uploaded_file (uf: EWSGI_UPLOADED_FILE_DATA)
|
||||
-- Delete file `a_filename'
|
||||
require
|
||||
uf_valid: uf /= Void
|
||||
@@ -536,7 +536,7 @@ feature {NONE} -- Temporary File handling
|
||||
end
|
||||
end
|
||||
|
||||
save_uploaded_file (a_content: STRING; a_up_fn_info: GW_UPLOADED_FILE_DATA)
|
||||
save_uploaded_file (a_content: STRING; a_up_fn_info: EWSGI_UPLOADED_FILE_DATA)
|
||||
-- Save uploaded file content to `a_filename'
|
||||
local
|
||||
bn: STRING
|
||||
@@ -703,7 +703,7 @@ feature {NONE} -- Implementation: Form analyzer
|
||||
l_header: detachable STRING
|
||||
l_content: detachable STRING
|
||||
l_line: detachable STRING
|
||||
l_up_file_info: GW_UPLOADED_FILE_DATA
|
||||
l_up_file_info: EWSGI_UPLOADED_FILE_DATA
|
||||
do
|
||||
from
|
||||
p := 1
|
||||
|
||||
@@ -8,12 +8,12 @@ class
|
||||
GW_IN_MEMORY_RESPONSE
|
||||
|
||||
inherit
|
||||
GW_RESPONSE
|
||||
EWSGI_RESPONSE
|
||||
redefine
|
||||
commit
|
||||
end
|
||||
|
||||
create {GW_APPLICATION}
|
||||
create {EWSGI_APPLICATION}
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
@@ -104,9 +104,9 @@ feature -- Header output operation
|
||||
header := h
|
||||
end
|
||||
|
||||
feature {GW_APPLICATION} -- Commit
|
||||
feature {EWSGI_APPLICATION} -- Commit
|
||||
|
||||
commit (a_output: GW_OUTPUT_STREAM)
|
||||
commit (a_output: EWSGI_OUTPUT_STREAM)
|
||||
do
|
||||
a_output.put_status_line (status_code)
|
||||
a_output.put_string (header.string)
|
||||
|
||||
@@ -8,7 +8,7 @@ deferred class
|
||||
GW_IN_MEMORY_RESPONSE_APPLICATION
|
||||
|
||||
inherit
|
||||
GW_APPLICATION
|
||||
EWSGI_APPLICATION
|
||||
redefine
|
||||
process
|
||||
end
|
||||
@@ -20,7 +20,7 @@ feature -- Access
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM)
|
||||
process (env: EWSGI_ENVIRONMENT; a_input: EWSGI_INPUT_STREAM; a_output: EWSGI_OUTPUT_STREAM)
|
||||
-- Process request with environment `env', and i/o streams `a_input' and `a_output'
|
||||
do
|
||||
request_count := request_count + 1
|
||||
@@ -29,13 +29,13 @@ feature -- Execution
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_request (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST
|
||||
new_request (env: EWSGI_ENVIRONMENT; a_input: EWSGI_INPUT_STREAM): EWSGI_REQUEST
|
||||
do
|
||||
create {GW_REQUEST_IMP} Result.make (env, a_input)
|
||||
Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT")
|
||||
end
|
||||
|
||||
new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE
|
||||
new_response (req: EWSGI_REQUEST; a_output: EWSGI_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE
|
||||
do
|
||||
create {GW_IN_MEMORY_RESPONSE} Result.make
|
||||
end
|
||||
|
||||
292
library/server/ewsgi/src/request/gw_environment_variables.e
Normal file
292
library/server/ewsgi/src/request/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
|
||||
EWSGI_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 ({EWSGI_ENVIRONMENT_NAMES}.query_string, empty_string, False)
|
||||
|
||||
--| REQUEST_METHOD
|
||||
request_method := variable_or_default ({EWSGI_ENVIRONMENT_NAMES}.request_method, empty_string, False)
|
||||
|
||||
--| CONTENT_TYPE
|
||||
s := variable ({EWSGI_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 ({EWSGI_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 ({EWSGI_ENVIRONMENT_NAMES}.path_info, empty_string, False)
|
||||
|
||||
--| SERVER_NAME
|
||||
server_name := variable_or_default ({EWSGI_ENVIRONMENT_NAMES}.server_name, empty_string, False)
|
||||
|
||||
--| SERVER_PORT
|
||||
s := variable ({EWSGI_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 ({EWSGI_ENVIRONMENT_NAMES}.script_name, empty_string, False)
|
||||
|
||||
--| REMOTE_ADDR
|
||||
remote_addr := variable_or_default ({EWSGI_ENVIRONMENT_NAMES}.remote_addr, empty_string, False)
|
||||
|
||||
--| REMOTE_HOST
|
||||
remote_host := variable_or_default ({EWSGI_ENVIRONMENT_NAMES}.remote_host, empty_string, False)
|
||||
|
||||
--| REQUEST_URI
|
||||
request_uri := variable_or_default ({EWSGI_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 {EWSGI_REQUEST, EWSGI_APPLICATION, EWSGI_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 ({EWSGI_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 ({EWSGI_ENVIRONMENT_NAMES}.path_translated)
|
||||
end
|
||||
|
||||
query_string: STRING
|
||||
|
||||
remote_addr: STRING
|
||||
|
||||
remote_host: STRING
|
||||
|
||||
remote_ident: detachable STRING
|
||||
do
|
||||
Result := variable ({EWSGI_ENVIRONMENT_NAMES}.remote_ident)
|
||||
end
|
||||
|
||||
remote_user: detachable STRING
|
||||
do
|
||||
Result := variable ({EWSGI_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 ({EWSGI_ENVIRONMENT_NAMES}.server_protocol, "HTTP/1.0", True)
|
||||
end
|
||||
|
||||
server_software: STRING
|
||||
do
|
||||
Result := variable_or_default ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 ({EWSGI_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 {EWSGI_REQUEST} -- Update
|
||||
|
||||
set_orig_path_info (s: STRING)
|
||||
do
|
||||
orig_path_info := s
|
||||
set_variable ({EWSGI_ENVIRONMENT_NAMES}.orig_path_info, s)
|
||||
end
|
||||
|
||||
unset_orig_path_info
|
||||
do
|
||||
orig_path_info := Void
|
||||
unset_variable ({EWSGI_ENVIRONMENT_NAMES}.orig_path_info)
|
||||
end
|
||||
|
||||
update_path_info (a_path_info: like path_info)
|
||||
do
|
||||
path_info := a_path_info
|
||||
set_variable ({EWSGI_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/request/gw_execution_variables.e
Normal file
56
library/server/ewsgi/src/request/gw_execution_variables.e
Normal file
@@ -0,0 +1,56 @@
|
||||
note
|
||||
description: "Summary description for {GW_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
|
||||
EWSGI_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 {EWSGI_REQUEST, EWSGI_APPLICATION, EWSGI_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
|
||||
147
library/server/ewsgi/src/request/gw_request_variables.e
Normal file
147
library/server/ewsgi/src/request/gw_request_variables.e
Normal file
@@ -0,0 +1,147 @@
|
||||
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
|
||||
EWSGI_VARIABLES [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 {EWSGI_REQUEST, EWSGI_APPLICATION, EWSGI_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
|
||||
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 {EWSGI_REQUEST} -- 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 {EWSGI_REQUEST} -- 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
|
||||
@@ -8,9 +8,9 @@ class
|
||||
GW_BUFFERED_RESPONSE
|
||||
|
||||
inherit
|
||||
GW_RESPONSE
|
||||
EWSGI_RESPONSE
|
||||
|
||||
create {GW_APPLICATION}
|
||||
create {EWSGI_APPLICATION}
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
@@ -22,7 +22,7 @@ feature {NONE} -- Initialization
|
||||
create buffer.make (a_buffer_size)
|
||||
end
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
output: EWSGI_OUTPUT_STREAM
|
||||
|
||||
buffer: STRING_8
|
||||
|
||||
@@ -143,9 +143,9 @@ feature {NONE} -- Implementation
|
||||
buffer_flushed: buffer_count = 0 and buffer.count = 0
|
||||
end
|
||||
|
||||
feature {GW_APPLICATION} -- Commit
|
||||
feature {EWSGI_APPLICATION} -- Commit
|
||||
|
||||
commit (a_output: GW_OUTPUT_STREAM)
|
||||
commit (a_output: EWSGI_OUTPUT_STREAM)
|
||||
do
|
||||
flush_buffer
|
||||
a_output.flush
|
||||
|
||||
@@ -8,9 +8,9 @@ class
|
||||
GW_RESPONSE_IMP
|
||||
|
||||
inherit
|
||||
GW_RESPONSE
|
||||
EWSGI_RESPONSE
|
||||
|
||||
create {GW_APPLICATION}
|
||||
create {EWSGI_APPLICATION}
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
@@ -20,9 +20,9 @@ feature {NONE} -- Initialization
|
||||
output := a_output
|
||||
end
|
||||
|
||||
feature {GW_APPLICATION} -- Commit
|
||||
feature {EWSGI_APPLICATION} -- Commit
|
||||
|
||||
commit (a_output_stream: GW_OUTPUT_STREAM)
|
||||
commit (a_output_stream: EWSGI_OUTPUT_STREAM)
|
||||
-- Commit the current response
|
||||
do
|
||||
a_output_stream.flush
|
||||
@@ -94,7 +94,7 @@ feature -- Header output operation
|
||||
|
||||
feature {NONE} -- Implementation: Access
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
output: EWSGI_OUTPUT_STREAM
|
||||
-- Server output channel
|
||||
|
||||
;note
|
||||
|
||||
Reference in New Issue
Block a user