Apply prefix renaming from the specification

Reduced the number of EWSGI classes
This commit is contained in:
Jocelyn Fiat
2011-07-27 15:56:44 +02:00
parent e5fb3f8328
commit e883163fe9
12 changed files with 53 additions and 52 deletions

View 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

View 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

View 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