Updated WGI specification to ease future migration to unicode support.
Use STRING_TABLE, and better interface of READABLE_STRING_GENERAL,
this way the signature are more flexible for unicode keys.
Note that for now, unicode environment variables are not correctly supported in WGI
especially the value of the variables.
Any layer on top of EWGSI suffers from the same issues.
Better exception handling
+ code cleaning
This commit is contained in:
@@ -61,9 +61,11 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
|
if not rescued then
|
||||||
rescued := True
|
rescued := True
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2013, Eiffel Software and others"
|
copyright: "2011-2013, Eiffel Software and others"
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ feature -- Server
|
|||||||
|
|
||||||
feature -- Execution
|
feature -- Execution
|
||||||
|
|
||||||
process_fcgi_request (vars: HASH_TABLE [STRING, STRING]; a_input: like input; a_output: like output)
|
process_fcgi_request (vars: STRING_TABLE [READABLE_STRING_8]; a_input: like input; a_output: like output)
|
||||||
local
|
local
|
||||||
req: WGI_REQUEST_FROM_TABLE
|
req: WGI_REQUEST_FROM_TABLE
|
||||||
res: detachable WGI_RESPONSE_STREAM
|
res: detachable WGI_RESPONSE_STREAM
|
||||||
@@ -82,9 +82,11 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
|
if not rescued then
|
||||||
rescued := True
|
rescued := True
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Input/Output
|
feature -- Input/Output
|
||||||
|
|
||||||
|
|||||||
@@ -127,20 +127,28 @@ feature -- Server
|
|||||||
server.setup (l_http_handler)
|
server.setup (l_http_handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
process_request (env: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_socket: TCP_STREAM_SOCKET)
|
process_request (env: STRING_TABLE [READABLE_STRING_8]; a_headers_text: STRING; a_socket: TCP_STREAM_SOCKET)
|
||||||
local
|
local
|
||||||
req: WGI_REQUEST_FROM_TABLE
|
req: WGI_REQUEST_FROM_TABLE
|
||||||
res: detachable WGI_NINO_RESPONSE_STREAM
|
res: detachable WGI_NINO_RESPONSE_STREAM
|
||||||
|
retried: BOOLEAN
|
||||||
do
|
do
|
||||||
|
if not retried then
|
||||||
create req.make (env, create {WGI_NINO_INPUT_STREAM}.make (a_socket), Current)
|
create req.make (env, create {WGI_NINO_INPUT_STREAM}.make (a_socket), Current)
|
||||||
create res.make (create {WGI_NINO_OUTPUT_STREAM}.make (a_socket), create {WGI_NINO_ERROR_STREAM}.make_stderr (a_socket.descriptor.out))
|
create res.make (create {WGI_NINO_OUTPUT_STREAM}.make (a_socket), create {WGI_NINO_ERROR_STREAM}.make_stderr (a_socket.descriptor.out))
|
||||||
req.set_meta_string_variable ("RAW_HEADER_DATA", a_headers_text)
|
req.set_meta_string_variable ("RAW_HEADER_DATA", a_headers_text)
|
||||||
service.execute (req, res)
|
service.execute (req, res)
|
||||||
res.push
|
res.push
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
if not retried then
|
||||||
|
retried := True
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -61,24 +61,24 @@ feature -- Request processing
|
|||||||
process_request (a_handler: HTTP_CONNECTION_HANDLER; a_socket: TCP_STREAM_SOCKET)
|
process_request (a_handler: HTTP_CONNECTION_HANDLER; a_socket: TCP_STREAM_SOCKET)
|
||||||
-- Process request ...
|
-- Process request ...
|
||||||
local
|
local
|
||||||
env: HASH_TABLE [STRING, STRING]
|
env: STRING_TABLE [READABLE_STRING_8]
|
||||||
p: INTEGER
|
p: INTEGER
|
||||||
l_request_uri, l_script_name, l_query_string, l_path_info: STRING
|
l_request_uri, l_script_name, l_query_string, l_path_info: STRING
|
||||||
l_server_name, l_server_port: detachable STRING
|
l_server_name, l_server_port: detachable STRING
|
||||||
a_headers_map: HASH_TABLE [STRING, STRING]
|
l_headers_map: HASH_TABLE [STRING, STRING]
|
||||||
vn: STRING
|
vn: STRING
|
||||||
|
|
||||||
e: EXECUTION_ENVIRONMENT
|
e: EXECUTION_ENVIRONMENT
|
||||||
do
|
do
|
||||||
l_request_uri := a_handler.uri
|
l_request_uri := a_handler.uri
|
||||||
a_headers_map := a_handler.request_header_map
|
l_headers_map := a_handler.request_header_map
|
||||||
create e
|
create e
|
||||||
if attached e.starting_environment_variables as vars then
|
if attached e.starting_environment_variables as vars then
|
||||||
create env.make (vars.count)
|
create env.make_equal (vars.count)
|
||||||
across
|
across
|
||||||
vars as c
|
vars as c
|
||||||
loop
|
loop
|
||||||
env.force (c.item.to_string_8, c.key.to_string_8)
|
env.force (c.item.to_string_8, c.key)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
create env.make (0)
|
create env.make (0)
|
||||||
@@ -86,11 +86,11 @@ feature -- Request processing
|
|||||||
|
|
||||||
--| for Any Abc-Def-Ghi add (or replace) the HTTP_ABC_DEF_GHI variable to `env'
|
--| for Any Abc-Def-Ghi add (or replace) the HTTP_ABC_DEF_GHI variable to `env'
|
||||||
from
|
from
|
||||||
a_headers_map.start
|
l_headers_map.start
|
||||||
until
|
until
|
||||||
a_headers_map.after
|
l_headers_map.after
|
||||||
loop
|
loop
|
||||||
create vn.make_from_string (a_headers_map.key_for_iteration.as_upper)
|
create vn.make_from_string (l_headers_map.key_for_iteration.as_upper)
|
||||||
vn.replace_substring_all ("-", "_")
|
vn.replace_substring_all ("-", "_")
|
||||||
if
|
if
|
||||||
vn.starts_with ("CONTENT_") and then
|
vn.starts_with ("CONTENT_") and then
|
||||||
@@ -100,8 +100,8 @@ feature -- Request processing
|
|||||||
else
|
else
|
||||||
vn.prepend ("HTTP_")
|
vn.prepend ("HTTP_")
|
||||||
end
|
end
|
||||||
add_environment_variable (a_headers_map.item_for_iteration, vn, env)
|
add_environment_variable (l_headers_map.item_for_iteration, vn, env)
|
||||||
a_headers_map.forth
|
l_headers_map.forth
|
||||||
end
|
end
|
||||||
|
|
||||||
--| Specific cases
|
--| Specific cases
|
||||||
@@ -114,7 +114,7 @@ feature -- Request processing
|
|||||||
l_script_name := l_request_uri.string
|
l_script_name := l_request_uri.string
|
||||||
l_query_string := ""
|
l_query_string := ""
|
||||||
end
|
end
|
||||||
if attached a_headers_map.item ("Host") as l_host then
|
if attached l_headers_map.item ("Host") as l_host then
|
||||||
check has_host: env.has ("HTTP_HOST") end
|
check has_host: env.has ("HTTP_HOST") end
|
||||||
-- set_environment_variable (l_host, "HTTP_HOST", env)
|
-- set_environment_variable (l_host, "HTTP_HOST", env)
|
||||||
p := l_host.index_of (':', 1)
|
p := l_host.index_of (':', 1)
|
||||||
@@ -129,7 +129,7 @@ feature -- Request processing
|
|||||||
check host_available: False end
|
check host_available: False end
|
||||||
end
|
end
|
||||||
|
|
||||||
if attached a_headers_map.item ("Authorization") as l_authorization then
|
if attached l_headers_map.item ("Authorization") as l_authorization then
|
||||||
check has_authorization: env.has ("HTTP_AUTHORIZATION") end
|
check has_authorization: env.has ("HTTP_AUTHORIZATION") end
|
||||||
-- set_environment_variable (l_authorization, "HTTP_AUTHORIZATION", env)
|
-- set_environment_variable (l_authorization, "HTTP_AUTHORIZATION", env)
|
||||||
p := l_authorization.index_of (' ', 1)
|
p := l_authorization.index_of (' ', 1)
|
||||||
@@ -174,7 +174,7 @@ feature -- Request processing
|
|||||||
callback.process_request (env, a_handler.request_header, a_socket)
|
callback.process_request (env, a_handler.request_header, a_socket)
|
||||||
end
|
end
|
||||||
|
|
||||||
add_environment_variable (a_value: detachable STRING; a_var_name: STRING; env: HASH_TABLE [STRING, STRING])
|
add_environment_variable (a_value: detachable STRING; a_var_name: READABLE_STRING_GENERAL; env: STRING_TABLE [READABLE_STRING_8])
|
||||||
-- Add variable `a_var_name => a_value' to `env'
|
-- Add variable `a_var_name => a_value' to `env'
|
||||||
do
|
do
|
||||||
if a_value /= Void then
|
if a_value /= Void then
|
||||||
@@ -188,7 +188,7 @@ feature -- Request processing
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
set_environment_variable (a_value: detachable STRING; a_var_name: STRING; env: HASH_TABLE [STRING, STRING])
|
set_environment_variable (a_value: detachable STRING; a_var_name: READABLE_STRING_GENERAL; env: STRING_TABLE [READABLE_STRING_8])
|
||||||
-- Add variable `a_var_name => a_value' to `env'
|
-- Add variable `a_var_name => a_value' to `env'
|
||||||
do
|
do
|
||||||
if a_value /= Void then
|
if a_value /= Void then
|
||||||
@@ -197,7 +197,7 @@ feature -- Request processing
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -88,14 +88,14 @@ feature -- Access: Input
|
|||||||
|
|
||||||
feature -- Access: CGI meta variables
|
feature -- Access: CGI meta variables
|
||||||
|
|
||||||
meta_variable (a_name: READABLE_STRING_8): detachable READABLE_STRING_8
|
meta_variable (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_8
|
||||||
-- Environment variable related to `a_name'
|
-- Environment variable related to `a_name'
|
||||||
require
|
require
|
||||||
a_name_valid: a_name /= Void and then not a_name.is_empty
|
a_name_valid: a_name /= Void and then not a_name.is_empty
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
meta_string_variable (a_name: READABLE_STRING_8): detachable READABLE_STRING_8
|
meta_string_variable (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_8
|
||||||
-- Environment variable related to `a_name'
|
-- Environment variable related to `a_name'
|
||||||
require
|
require
|
||||||
a_name_valid: a_name /= Void and then not a_name.is_empty
|
a_name_valid: a_name /= Void and then not a_name.is_empty
|
||||||
@@ -105,7 +105,7 @@ feature -- Access: CGI meta variables
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
meta_variables: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
|
meta_variables: STRING_TABLE [READABLE_STRING_8]
|
||||||
-- These variables are specific to requests made with HTTP.
|
-- These variables are specific to requests made with HTTP.
|
||||||
-- Interpretation of these variables may depend on the value of
|
-- Interpretation of these variables may depend on the value of
|
||||||
-- SERVER_PROTOCOL.
|
-- SERVER_PROTOCOL.
|
||||||
@@ -635,7 +635,7 @@ invariant
|
|||||||
path_info_identical: path_info ~ meta_string_variable ({WGI_META_NAMES}.path_info)
|
path_info_identical: path_info ~ meta_string_variable ({WGI_META_NAMES}.path_info)
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -138,8 +138,6 @@ feature -- Input
|
|||||||
nb_large_enough: nb > 0
|
nb_large_enough: nb > 0
|
||||||
local
|
local
|
||||||
s: like last_string
|
s: like last_string
|
||||||
i, end_pos: INTEGER
|
|
||||||
l_count: INTEGER
|
|
||||||
n: INTEGER
|
n: INTEGER
|
||||||
l_remaining: INTEGER
|
l_remaining: INTEGER
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -61,16 +61,16 @@ feature -- EWSGI access
|
|||||||
|
|
||||||
feature -- Access: CGI meta parameters
|
feature -- Access: CGI meta parameters
|
||||||
|
|
||||||
meta_variables: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
|
meta_variables: STRING_TABLE [READABLE_STRING_8]
|
||||||
-- CGI Environment parameters
|
-- CGI Environment parameters
|
||||||
|
|
||||||
meta_variable (a_name: READABLE_STRING_8): detachable READABLE_STRING_8
|
meta_variable (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_8
|
||||||
-- CGI meta variable related to `a_name'
|
-- CGI meta variable related to `a_name'
|
||||||
do
|
do
|
||||||
Result := meta_variables.item (a_name)
|
Result := meta_variables.item (a_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
meta_string_variable_or_default (a_name: READABLE_STRING_8; a_default: READABLE_STRING_8; use_default_when_empty: BOOLEAN): READABLE_STRING_8
|
meta_string_variable_or_default (a_name: READABLE_STRING_GENERAL; a_default: READABLE_STRING_8; use_default_when_empty: BOOLEAN): READABLE_STRING_8
|
||||||
-- Value for meta parameter `a_name'
|
-- Value for meta parameter `a_name'
|
||||||
-- If not found, return `a_default'
|
-- If not found, return `a_default'
|
||||||
require
|
require
|
||||||
@@ -86,14 +86,14 @@ feature -- Access: CGI meta parameters
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
set_meta_string_variable (a_name: READABLE_STRING_8; a_value: READABLE_STRING_8)
|
set_meta_string_variable (a_name: READABLE_STRING_GENERAL; a_value: READABLE_STRING_8)
|
||||||
do
|
do
|
||||||
meta_variables.force (a_value, a_name)
|
meta_variables.force (a_value, a_name)
|
||||||
ensure
|
ensure
|
||||||
param_set: attached meta_variable (a_name) as val and then val ~ a_value
|
param_set: attached meta_variable (a_name) as val and then val ~ a_value
|
||||||
end
|
end
|
||||||
|
|
||||||
unset_meta_variable (a_name: READABLE_STRING_8)
|
unset_meta_variable (a_name: READABLE_STRING_GENERAL)
|
||||||
do
|
do
|
||||||
meta_variables.remove (a_name)
|
meta_variables.remove (a_name)
|
||||||
ensure
|
ensure
|
||||||
@@ -268,7 +268,7 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO
|
|||||||
-- Fill with variable from `a_vars'
|
-- Fill with variable from `a_vars'
|
||||||
local
|
local
|
||||||
s: like meta_string_variable
|
s: like meta_string_variable
|
||||||
table: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
|
table: STRING_TABLE [READABLE_STRING_8]
|
||||||
l_query_string: like query_string
|
l_query_string: like query_string
|
||||||
l_request_uri: detachable STRING_32
|
l_request_uri: detachable STRING_32
|
||||||
l_empty_string: like empty_string
|
l_empty_string: like empty_string
|
||||||
@@ -276,15 +276,14 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO
|
|||||||
create {STRING_8} l_empty_string.make_empty
|
create {STRING_8} l_empty_string.make_empty
|
||||||
empty_string := l_empty_string
|
empty_string := l_empty_string
|
||||||
|
|
||||||
create table.make (a_vars.count)
|
create table.make_equal (a_vars.count)
|
||||||
table.compare_objects
|
|
||||||
meta_variables := table
|
meta_variables := table
|
||||||
from
|
from
|
||||||
a_vars.start
|
a_vars.start
|
||||||
until
|
until
|
||||||
a_vars.after
|
a_vars.after
|
||||||
loop
|
loop
|
||||||
table.force (a_vars.item_for_iteration.to_string_8, a_vars.key_for_iteration.to_string_8)
|
table.force (a_vars.item_for_iteration.to_string_8, a_vars.key_for_iteration)
|
||||||
a_vars.forth
|
a_vars.forth
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -446,7 +445,7 @@ invariant
|
|||||||
empty_string_unchanged: empty_string.is_empty
|
empty_string_unchanged: empty_string.is_empty
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
Reference in New Issue
Block a user