Merge branch 'fix_cgi_value' of github.com:jocelyn/EWF
This commit is contained in:
@@ -28,20 +28,16 @@ feature -- Basic operations
|
||||
-- Execute the filter
|
||||
local
|
||||
s: STRING_8
|
||||
dbg: WSF_DEBUG_OUTPUT
|
||||
do
|
||||
create s.make (2048)
|
||||
if attached req.content_type as l_type then
|
||||
s.append ("[length=")
|
||||
s.append_natural_64 (req.content_length_value)
|
||||
s.append_character (']')
|
||||
s.append_character (' ')
|
||||
s.append (l_type.debug_output)
|
||||
s.append_character ('%N')
|
||||
end
|
||||
create dbg.make
|
||||
dbg.set_is_verbose (False)
|
||||
|
||||
append_iterable_to ("Path parameters", req.path_parameters, s)
|
||||
append_iterable_to ("Query parameters", req.query_parameters, s)
|
||||
append_iterable_to ("Form parameters", req.form_parameters, s)
|
||||
dbg.append_content_information_to (req, res, s)
|
||||
dbg.append_path_parameters_to (req, res, s)
|
||||
dbg.append_query_parameters_to (req, res, s)
|
||||
dbg.append_form_parameters_to (req, res, s)
|
||||
|
||||
if not s.is_empty then
|
||||
s.prepend ("**DEBUG**%N")
|
||||
@@ -84,8 +80,8 @@ feature -- Basic operations
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2013, Eiffel Software"
|
||||
license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
licensing_options: "http://www.eiffel.com/licensing"
|
||||
copying: "[
|
||||
This file is part of Eiffel Software's Eiffel Development Environment.
|
||||
|
||||
@@ -15,20 +15,6 @@ inherit
|
||||
|
||||
WSF_SELF_DOCUMENTED_HANDLER
|
||||
|
||||
SHARED_HTML_ENCODER
|
||||
|
||||
SHARED_WSF_PERCENT_ENCODER
|
||||
rename
|
||||
percent_encoder as url_encoder
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
SHARED_EXECUTION_ENVIRONMENT
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_hidden
|
||||
@@ -58,109 +44,62 @@ feature -- Documentation
|
||||
Result.add_description ("Debug handler (mainly to return request information)")
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
feature -- Access
|
||||
|
||||
execute_starts_with (a_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
s: STRING_8
|
||||
p: WSF_PAGE_RESPONSE
|
||||
v: STRING_8
|
||||
l_len: INTEGER
|
||||
dbg: WSF_DEBUG_INFORMATION
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
create s.make (2048)
|
||||
s.append ("**DEBUG**%N")
|
||||
req.set_raw_input_data_recorded (True)
|
||||
s.append ("= EWF DEBUG =")
|
||||
s.append ("%N")
|
||||
|
||||
append_iterable_to ("Meta variables:", req.meta_variables, s)
|
||||
s.append_character ('%N')
|
||||
create dbg.make
|
||||
dbg.set_is_verbose (True)
|
||||
dbg.append_cgi_variables_to (req, res, s)
|
||||
dbg.append_information_to (req, res, s)
|
||||
|
||||
append_iterable_to ("Path parameters", req.path_parameters, s)
|
||||
s.append_character ('%N')
|
||||
s.append ("= END =")
|
||||
s.append ("%N")
|
||||
|
||||
append_iterable_to ("Query parameters", req.query_parameters, s)
|
||||
s.append_character ('%N')
|
||||
|
||||
append_iterable_to ("Form parameters", req.form_parameters, s)
|
||||
s.append_character ('%N')
|
||||
|
||||
if attached req.content_type as l_type then
|
||||
s.append ("Content: type=" + l_type.debug_output)
|
||||
s.append (" length=")
|
||||
s.append_natural_64 (req.content_length_value)
|
||||
s.append_character ('%N')
|
||||
create v.make (req.content_length_value.to_integer_32)
|
||||
req.read_input_data_into (v)
|
||||
across
|
||||
v.split ('%N') as v_cursor
|
||||
loop
|
||||
s.append (" |")
|
||||
s.append (v_cursor.item)
|
||||
s.append_character ('%N')
|
||||
end
|
||||
end
|
||||
|
||||
create p.make_with_body (s)
|
||||
p.header.put_content_type_text_plain
|
||||
res.send (p)
|
||||
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
append_iterable_to (a_title: READABLE_STRING_8; it: detachable ITERABLE [WSF_VALUE]; s: STRING_8)
|
||||
local
|
||||
n: INTEGER
|
||||
t: READABLE_STRING_8
|
||||
v: READABLE_STRING_8
|
||||
do
|
||||
s.append (a_title)
|
||||
s.append_character (':')
|
||||
if it /= Void then
|
||||
across it as c loop
|
||||
n := n + 1
|
||||
end
|
||||
if n = 0 then
|
||||
s.append (" empty")
|
||||
s.append_character ('%N')
|
||||
else
|
||||
s.append_character ('%N')
|
||||
across
|
||||
it as c
|
||||
loop
|
||||
s.append (" - ")
|
||||
s.append (c.item.url_encoded_name)
|
||||
t := c.item.generating_type
|
||||
if t.same_string ("WSF_STRING") then
|
||||
else
|
||||
s.append_character (' ')
|
||||
s.append_character ('{')
|
||||
s.append (t)
|
||||
s.append_character ('}')
|
||||
end
|
||||
s.append_character ('=')
|
||||
v := c.item.string_representation.as_string_8
|
||||
if v.has ('%N') then
|
||||
s.append_character ('%N')
|
||||
across
|
||||
v.split ('%N') as v_cursor
|
||||
loop
|
||||
s.append (" |")
|
||||
s.append (v_cursor.item)
|
||||
s.append_character ('%N')
|
||||
end
|
||||
else
|
||||
s.append (v)
|
||||
s.append_character ('%N')
|
||||
if {PLATFORM}.is_windows and req.wgi_connector.name.is_case_insensitive_equal ("cgi") then
|
||||
--| FIXME: the CGI connector add %R for any single %N character, so update the Content-Length accordingly.
|
||||
-- Dirty hack to handle correctly CGI on Windows, since it seems "abc%N" will be sent as "abc%R%N"
|
||||
l_len := 0
|
||||
across s as ic loop
|
||||
if ic.item = '%R' then
|
||||
l_len := l_len + 1
|
||||
ic.forth
|
||||
if
|
||||
not ic.after and then
|
||||
ic.item = '%N'
|
||||
then
|
||||
l_len := l_len + 1
|
||||
end
|
||||
elseif ic.item = '%N' then
|
||||
l_len := l_len + 2 -- %R will be added by the CGI connector...
|
||||
else
|
||||
l_len := l_len + 1
|
||||
end
|
||||
end
|
||||
else
|
||||
s.append (" none")
|
||||
s.append_character ('%N')
|
||||
l_len := s.count
|
||||
end
|
||||
|
||||
p.header.put_content_length (l_len)
|
||||
p.header.put_content_type_utf_8_text_plain
|
||||
res.send (p)
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
397
library/server/wsf/extension/wsf_debug_information.e
Normal file
397
library/server/wsf/extension/wsf_debug_information.e
Normal file
@@ -0,0 +1,397 @@
|
||||
note
|
||||
description: "[
|
||||
Object used to output information from WSF_REQUEST objects
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_DEBUG_INFORMATION
|
||||
|
||||
inherit
|
||||
ANY
|
||||
|
||||
SHARED_HTML_ENCODER
|
||||
|
||||
SHARED_WSF_PERCENT_ENCODER
|
||||
rename
|
||||
percent_encoder as url_encoder
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
SHARED_EXECUTION_ENVIRONMENT
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
WSF_REQUEST_EXPORTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
is_verbose := True
|
||||
end
|
||||
|
||||
feature -- Settings
|
||||
|
||||
is_verbose: BOOLEAN
|
||||
-- Has verbose output (default: True)?
|
||||
|
||||
feature -- Settings change
|
||||
|
||||
set_is_verbose (b: BOOLEAN)
|
||||
-- Set `is_verbose' to `b'.
|
||||
do
|
||||
is_verbose := b
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
|
||||
append_connector_informations_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
a_output.append ("Eiffel Web Server Gateway Interface (WGI):")
|
||||
a_output.append (" implementation=%"")
|
||||
a_output.append (req.wgi_implementation)
|
||||
a_output.append ("%"")
|
||||
a_output.append (" version=")
|
||||
a_output.append (req.wgi_version)
|
||||
a_output.append (" connector=%"")
|
||||
a_output.append (req.wgi_connector.name)
|
||||
a_output.append (" connector-version=")
|
||||
a_output.append (req.wgi_connector.version)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_cgi_variables_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
a_output.append ("CGI variables:")
|
||||
a_output.append (eol)
|
||||
a_output.append (req.cgi_variables.debug_output)
|
||||
a_output.append (eol)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_meta_variables_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
append_iterable_to ("Meta variables", req.meta_variables, a_output)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_path_parameters_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
append_iterable_to ("Path parameters", req.path_parameters, a_output)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_query_parameters_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
append_iterable_to ("Query parameters", req.query_parameters, a_output)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_form_parameters_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
req.set_raw_input_data_recorded (True)
|
||||
append_iterable_to ("Form parameters", req.form_parameters, a_output)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_execution_variables_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
append_iterable_any_to ("Execution variables", req.execution_variables, a_output)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_environment_variables_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
a_output.append ("Environment vars:")
|
||||
a_output.append (eol)
|
||||
across
|
||||
(create {EXECUTION_ENVIRONMENT}).starting_environment_variables as ic
|
||||
loop
|
||||
a_output.append_character (' ')
|
||||
a_output.append_character ('-')
|
||||
a_output.append_string (ic.key)
|
||||
a_output.append_character ('=')
|
||||
a_output.append_string (ic.item)
|
||||
a_output.append (eol)
|
||||
end
|
||||
a_output.append (eol)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
append_all_variables_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
req.set_raw_input_data_recorded (True)
|
||||
|
||||
append_path_parameters_to (req, res, a_output)
|
||||
append_query_parameters_to (req, res, a_output)
|
||||
append_form_parameters_to (req, res, a_output)
|
||||
append_meta_variables_to (req, res, a_output)
|
||||
if is_verbose then
|
||||
append_execution_variables_to (req, res, a_output)
|
||||
-- append_environment_variables_to (req, res, a_output)
|
||||
end
|
||||
end
|
||||
|
||||
append_content_information_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
local
|
||||
v: STRING_8
|
||||
do
|
||||
if attached req.content_type as l_type then
|
||||
a_output.append ("Content: type=" + l_type.debug_output)
|
||||
a_output.append (" length=")
|
||||
a_output.append_natural_64 (req.content_length_value)
|
||||
a_output.append (eol)
|
||||
if is_verbose then
|
||||
create v.make (req.content_length_value.to_integer_32)
|
||||
req.set_raw_input_data_recorded (True)
|
||||
req.read_input_data_into (v)
|
||||
across
|
||||
v.split ('%N') as v_cursor
|
||||
loop
|
||||
a_output.append (" |")
|
||||
a_output.append (v_cursor.item)
|
||||
a_output.append (eol)
|
||||
end
|
||||
a_output.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
append_information_to (req: WSF_REQUEST; res: WSF_RESPONSE; a_output: STRING)
|
||||
do
|
||||
append_connector_informations_to (req, res, a_output)
|
||||
a_output.append (eol)
|
||||
|
||||
append_all_variables_to (req, res, a_output)
|
||||
a_output.append (eol)
|
||||
|
||||
append_content_information_to (req, res, a_output)
|
||||
a_output.append (eol)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
iterable_count (a_iterable: ITERABLE [detachable ANY]): INTEGER
|
||||
do
|
||||
if attached {FINITE [detachable ANY]} a_iterable as a_finite then
|
||||
Result := a_finite.count
|
||||
else
|
||||
across a_iterable as ic loop
|
||||
Result := Result + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
append_iterable_any_to (a_title: READABLE_STRING_8; it: detachable TABLE_ITERABLE [detachable ANY, READABLE_STRING_GENERAL]; s: STRING_8)
|
||||
local
|
||||
n: INTEGER
|
||||
v: READABLE_STRING_8
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
if is_verbose then
|
||||
s.append (a_title)
|
||||
s.append_character (':')
|
||||
end
|
||||
if it /= Void then
|
||||
n := iterable_count (it)
|
||||
if n = 0 then
|
||||
if is_verbose then
|
||||
s.append (" empty")
|
||||
s.append (eol)
|
||||
end
|
||||
else
|
||||
s.append (eol)
|
||||
across
|
||||
it as c
|
||||
loop
|
||||
s.append (" - ")
|
||||
s.append (utf.escaped_utf_32_string_to_utf_8_string_8 (c.key))
|
||||
s.append_character (' ')
|
||||
if attached c.item as l_item then
|
||||
s.append_character ('{')
|
||||
s.append (l_item.generating_type)
|
||||
s.append_character ('}')
|
||||
|
||||
s.append_character (' ')
|
||||
s.append_character ('=')
|
||||
s.append_character (' ')
|
||||
if attached {READABLE_STRING_GENERAL} c.item as l_string then
|
||||
v := "%"" + utf.escaped_utf_32_string_to_utf_8_string_8 (l_string) + "%""
|
||||
elseif attached {DEBUG_OUTPUT} c.item as l_dbg_output then
|
||||
v := utf.escaped_utf_32_string_to_utf_8_string_8 (l_dbg_output.debug_output)
|
||||
else
|
||||
v := "..."
|
||||
end
|
||||
if v.has ('%N') then
|
||||
s.append (eol)
|
||||
across
|
||||
v.split ('%N') as v_cursor
|
||||
loop
|
||||
s.append (" |")
|
||||
s.append (v_cursor.item)
|
||||
s.append (eol)
|
||||
end
|
||||
else
|
||||
s.append (v)
|
||||
s.append (eol)
|
||||
end
|
||||
else
|
||||
s.append_character ('=')
|
||||
s.append ("Void")
|
||||
s.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if is_verbose then
|
||||
s.append (" none")
|
||||
s.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
append_iterable_to (a_title: READABLE_STRING_8; it: detachable ITERABLE [WSF_VALUE]; a_output: STRING_8)
|
||||
local
|
||||
n: INTEGER
|
||||
t: READABLE_STRING_8
|
||||
v: READABLE_STRING_8
|
||||
s: READABLE_STRING_GENERAL
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
if is_verbose then
|
||||
a_output.append (a_title)
|
||||
a_output.append_character (':')
|
||||
end
|
||||
if it /= Void then
|
||||
n := iterable_count (it)
|
||||
if n = 0 then
|
||||
if is_verbose then
|
||||
a_output.append (" empty")
|
||||
a_output.append (eol)
|
||||
end
|
||||
else
|
||||
a_output.append (eol)
|
||||
across
|
||||
it as c
|
||||
loop
|
||||
a_output.append (" - ")
|
||||
a_output.append (c.item.url_encoded_name)
|
||||
t := c.item.generating_type
|
||||
if t.same_string ("WSF_STRING") then
|
||||
else
|
||||
a_output.append_character (' ')
|
||||
a_output.append_character ('{')
|
||||
a_output.append (t)
|
||||
a_output.append_character ('}')
|
||||
end
|
||||
a_output.append_character ('=')
|
||||
if attached {WSF_STRING} c.item as l_str then
|
||||
s := l_str.url_encoded_value
|
||||
else
|
||||
s := c.item.string_representation
|
||||
end
|
||||
if s.is_valid_as_string_8 then
|
||||
v := s.as_string_8
|
||||
else
|
||||
v := utf.escaped_utf_32_string_to_utf_8_string_8 (s)
|
||||
end
|
||||
if v.has ('%N') then
|
||||
a_output.append (eol)
|
||||
across
|
||||
v.split ('%N') as v_cursor
|
||||
loop
|
||||
a_output.append (" |")
|
||||
a_output.append (v_cursor.item)
|
||||
a_output.append (eol)
|
||||
end
|
||||
else
|
||||
a_output.append (v)
|
||||
a_output.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if is_verbose then
|
||||
a_output.append (" none")
|
||||
a_output.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
append_iterable_string_to (a_title: READABLE_STRING_8; it: detachable TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_GENERAL]; a_output: STRING_8)
|
||||
local
|
||||
n: INTEGER
|
||||
v: READABLE_STRING_8
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
if is_verbose then
|
||||
a_output.append (a_title)
|
||||
a_output.append_character (':')
|
||||
end
|
||||
if it /= Void then
|
||||
n := iterable_count (it)
|
||||
if n = 0 then
|
||||
if is_verbose then
|
||||
a_output.append (" empty")
|
||||
a_output.append (eol)
|
||||
end
|
||||
else
|
||||
a_output.append (eol)
|
||||
across
|
||||
it as c
|
||||
loop
|
||||
a_output.append (" - ")
|
||||
if c.key.is_valid_as_string_8 then
|
||||
a_output.append (c.key.as_string_8)
|
||||
else
|
||||
a_output.append (utf.utf_32_string_to_utf_8_string_8 (c.key))
|
||||
end
|
||||
a_output.append_character ('=')
|
||||
v := c.item
|
||||
if v.has ('%N') then
|
||||
a_output.append (eol)
|
||||
across
|
||||
v.split ('%N') as v_cursor
|
||||
loop
|
||||
a_output.append (" |")
|
||||
a_output.append (v_cursor.item)
|
||||
a_output.append (eol)
|
||||
end
|
||||
else
|
||||
a_output.append (v)
|
||||
a_output.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if is_verbose then
|
||||
a_output.append (" none")
|
||||
a_output.append (eol)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Constants
|
||||
|
||||
eol: STRING = "%N"
|
||||
|
||||
invariant
|
||||
|
||||
note
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, 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
|
||||
@@ -25,11 +25,8 @@ feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: READABLE_STRING_8; a_string: READABLE_STRING_8)
|
||||
do
|
||||
name := url_decoded_string (a_name)
|
||||
value := url_decoded_string (a_string)
|
||||
|
||||
url_encoded_name := a_name
|
||||
url_encoded_value := a_string
|
||||
url_encoded_name := utf_8_percent_encoded_string (a_name)
|
||||
url_encoded_value := utf_8_percent_encoded_string (a_string)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -38,11 +35,31 @@ feature -- Access
|
||||
-- <Precursor>
|
||||
--| Note that the value might be html encoded as well
|
||||
--| this is the application responsibility to html decode it
|
||||
local
|
||||
v: like internal_name
|
||||
do
|
||||
v := internal_name
|
||||
if v = Void then
|
||||
v := url_decoded_string (url_encoded_name)
|
||||
internal_name := v
|
||||
end
|
||||
Result := v
|
||||
end
|
||||
|
||||
value: READABLE_STRING_32
|
||||
-- <Precursor>
|
||||
--| Note that the value might be html encoded as well
|
||||
--| this is the application responsibility to html decode it
|
||||
local
|
||||
v: like internal_value
|
||||
do
|
||||
v := internal_value
|
||||
if v = Void then
|
||||
v := url_decoded_string (url_encoded_value)
|
||||
internal_value := v
|
||||
end
|
||||
Result := v
|
||||
end
|
||||
|
||||
url_encoded_name: READABLE_STRING_8
|
||||
-- URL encoded string of `name'.
|
||||
@@ -50,6 +67,14 @@ feature -- Access
|
||||
url_encoded_value: READABLE_STRING_8
|
||||
-- URL encoded string of `value'.
|
||||
|
||||
feature {NONE} -- Access: internals
|
||||
|
||||
internal_name: detachable like name
|
||||
-- Cached value of `name'.
|
||||
|
||||
internal_value: detachable like value
|
||||
-- Cached value of `value'.
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
integer_value: INTEGER
|
||||
@@ -81,7 +106,7 @@ feature -- Element change
|
||||
|
||||
change_name (a_name: like name)
|
||||
do
|
||||
name := url_decoded_string (a_name)
|
||||
internal_name := Void
|
||||
url_encoded_name := a_name
|
||||
ensure then
|
||||
a_name.same_string (url_encoded_name)
|
||||
@@ -122,8 +147,89 @@ feature -- Visitor
|
||||
vis.process_string (Current)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
utf_8_percent_encoded_string (s: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Percent-encode the UTF-8 sequence characters from UTF-8 encoded `s' and
|
||||
-- return the Result.
|
||||
local
|
||||
s8: STRING_8
|
||||
i, n, nb: INTEGER
|
||||
do
|
||||
-- First check if there are such UTF-8 character
|
||||
-- If it has, convert them and return a new object as Result
|
||||
-- otherwise return `s' directly to avoid creating a new object
|
||||
from
|
||||
i := 1
|
||||
n := s.count
|
||||
nb := 0
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
if s.code (i) > 0x7F then -- >= 128
|
||||
nb := nb + 1
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
if nb > 0 then
|
||||
create s8.make (s.count + nb * 3)
|
||||
utf_8_string_8_into_percent_encoded_string_8 (s, s8)
|
||||
Result := s8
|
||||
else
|
||||
Result := s
|
||||
end
|
||||
end
|
||||
|
||||
utf_8_string_8_into_percent_encoded_string_8 (s: READABLE_STRING_8; a_result: STRING_8)
|
||||
-- Copy STRING_32 corresponding to UTF-8 sequence `s' appended into `a_result'.
|
||||
local
|
||||
i: INTEGER
|
||||
n: INTEGER
|
||||
c: NATURAL_32
|
||||
do
|
||||
from
|
||||
n := s.count
|
||||
a_result.grow (a_result.count + n)
|
||||
until
|
||||
i >= n
|
||||
loop
|
||||
i := i + 1
|
||||
c := s.code (i)
|
||||
if c <= 0x7F then
|
||||
-- 0xxxxxxx
|
||||
a_result.append_code (c)
|
||||
elseif c <= 0xDF then
|
||||
-- 110xxxxx 10xxxxxx
|
||||
url_encoder.append_percent_encoded_character_code_to (c, a_result)
|
||||
i := i + 1
|
||||
if i <= n then
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
end
|
||||
elseif c <= 0xEF then
|
||||
-- 1110xxxx 10xxxxxx 10xxxxxx
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
i := i + 2
|
||||
if i <= n then
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i - 1), a_result)
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
end
|
||||
elseif c <= 0xF7 then
|
||||
-- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
i := i + 3
|
||||
if i <= n then
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i - 2), a_result)
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i - 1), a_result)
|
||||
url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
|
||||
end
|
||||
else
|
||||
a_result.append_code (c)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -71,6 +71,7 @@ feature -- Query
|
||||
string_representation: STRING_32
|
||||
-- String representation of Current
|
||||
-- if possible
|
||||
-- note: unicode value.
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -127,7 +128,7 @@ feature -- Visitor
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -20,8 +20,8 @@ note
|
||||
About https support: `is_https' indicates if the request is made through an https connection or not.
|
||||
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
date: "$Date: 2014-05-14 16:52:42 +0200 (mer., 14 mai 2014) $"
|
||||
revision: "$Revision: 95057 $"
|
||||
|
||||
class
|
||||
WSF_REQUEST
|
||||
@@ -87,18 +87,19 @@ feature {NONE} -- Initialization
|
||||
local
|
||||
s8: detachable READABLE_STRING_8
|
||||
req: WGI_REQUEST
|
||||
utf: UTF_CONVERTER
|
||||
do
|
||||
init_mime_handlers
|
||||
req := wgi_request
|
||||
|
||||
--| Content-Length
|
||||
--| Content-Length
|
||||
if attached content_length as s and then s.is_natural_64 then
|
||||
content_length_value := s.to_natural_64
|
||||
else
|
||||
content_length_value := 0
|
||||
end
|
||||
|
||||
-- Content-Type
|
||||
--| Content-Type
|
||||
s8 := req.content_type
|
||||
if s8 /= Void then
|
||||
create content_type.make_from_string (s8)
|
||||
@@ -106,18 +107,11 @@ feature {NONE} -- Initialization
|
||||
content_type := Void
|
||||
end
|
||||
|
||||
--| Request Methods
|
||||
--| Request Methods
|
||||
request_method := req.request_method
|
||||
|
||||
--| PATH_INFO
|
||||
percent_encoded_path_info := req.path_info
|
||||
path_info := url_decoded_string (req.path_info)
|
||||
|
||||
--| PATH_TRANSLATED
|
||||
s8 := req.path_translated
|
||||
if s8 /= Void then
|
||||
path_translated := url_decoded_string (s8)
|
||||
end
|
||||
--| PATH_INFO
|
||||
path_info := utf.utf_8_string_8_to_string_32 (req.path_info)
|
||||
|
||||
--| Here one can set its own environment entries if needed
|
||||
if meta_variable ({WSF_META_NAMES}.request_time) = Void then
|
||||
@@ -139,9 +133,19 @@ feature {NONE} -- Initialization
|
||||
end
|
||||
end
|
||||
|
||||
feature {WSF_REQUEST_EXPORTER} -- Restricted Access
|
||||
|
||||
wgi_request: WGI_REQUEST
|
||||
-- Associated WGI request
|
||||
|
||||
cgi_variables: WGI_REQUEST_CGI_VARIABLES
|
||||
-- Object containing the CGI variables
|
||||
--| mainly for debugging purpose.
|
||||
--| note: a new instance is created on each call!
|
||||
do
|
||||
Result := wgi_request.cgi_variables
|
||||
end
|
||||
|
||||
feature -- Destroy
|
||||
|
||||
destroy
|
||||
@@ -166,9 +170,9 @@ feature -- Destroy
|
||||
form_parameters_table.wipe_out
|
||||
mime_handlers := Void
|
||||
path_info := empty_string_32
|
||||
internal_percent_encoded_path_info := Void
|
||||
path_parameters_source := Void
|
||||
path_parameters_table := Void
|
||||
path_translated := Void
|
||||
raw_input_data := Void
|
||||
raw_input_data_recorded := False
|
||||
request_method := empty_string_8
|
||||
@@ -612,6 +616,12 @@ feature -- Helpers: global variables
|
||||
|
||||
feature -- Execution variables
|
||||
|
||||
execution_variables: TABLE_ITERABLE [detachable ANY, READABLE_STRING_GENERAL]
|
||||
-- Execution variables values.
|
||||
do
|
||||
Result := execution_variables_table
|
||||
end
|
||||
|
||||
has_execution_variable (a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Has execution variable related to `a_name'?
|
||||
require
|
||||
@@ -829,19 +839,52 @@ feature -- Access: CGI meta parameters - 1.1
|
||||
end
|
||||
|
||||
percent_encoded_path_info: READABLE_STRING_8
|
||||
-- Non decoded PATH_INFO value from CGI.
|
||||
-- Percent encoded PATH_INFO value from CGI.
|
||||
-- See `path_info' for the related percent decoded value.
|
||||
--| This value should be used by component dealing only with ASCII path
|
||||
--| this value is not always available, so it requires to be computed.
|
||||
local
|
||||
l_result: like internal_percent_encoded_path_info
|
||||
r: READABLE_STRING_8
|
||||
i: INTEGER
|
||||
do
|
||||
l_result := internal_percent_encoded_path_info
|
||||
if l_result = Void then
|
||||
r := request_uri
|
||||
i := r.index_of ('?', 1)
|
||||
if i > 0 then
|
||||
l_result := r.substring (1, i - 1)
|
||||
else
|
||||
l_result := r.string
|
||||
end
|
||||
if attached script_name as s then
|
||||
if l_result.starts_with (s) then
|
||||
l_result := l_result.substring (s.count + 1, l_result.count)
|
||||
end
|
||||
end
|
||||
internal_percent_encoded_path_info := l_result
|
||||
end
|
||||
Result := l_result
|
||||
end
|
||||
|
||||
utf_8_path_info: READABLE_STRING_8
|
||||
-- UTF-8 encoded value for PATH_INFO.
|
||||
-- See `path_info' for extended description.
|
||||
do
|
||||
Result := wgi_request.path_info
|
||||
end
|
||||
|
||||
path_info: READABLE_STRING_32
|
||||
-- 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.
|
||||
-- preceding any query data.
|
||||
-- Unlike a URI path, the PATH_INFO is not URL-encoded, and cannot
|
||||
-- contain path-segment parameters.
|
||||
-- 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 )
|
||||
@@ -862,9 +905,10 @@ feature -- Access: CGI meta parameters - 1.1
|
||||
-- preserve the case of the PATH_INFO element of the URI when
|
||||
-- making it available to scripts.
|
||||
--
|
||||
-- See `percent_encoded_path_info' to get the original non decoded path info.
|
||||
-- Note: this is the unicode version of PATH_INFO, for utf-8 version
|
||||
-- please use `utf_8_path_info', which is the real CGI value of PATH_INFO.
|
||||
|
||||
path_translated: detachable READABLE_STRING_32
|
||||
path_translated: detachable READABLE_STRING_8
|
||||
-- PATH_TRANSLATED is derived by taking any path-info component
|
||||
-- of the wgi_request URI (see section 6.1.6), decoding it (see
|
||||
-- section 3.1), parsing it as a URI in its own right, and
|
||||
@@ -907,6 +951,11 @@ feature -- Access: CGI meta parameters - 1.1
|
||||
--
|
||||
-- Servers SHOULD provide this metavariable to scripts if and
|
||||
-- only if the wgi_request URI includes a path-info component.
|
||||
--
|
||||
-- note: it is UTF_8 encoded.
|
||||
do
|
||||
Result := wgi_request.path_translated
|
||||
end
|
||||
|
||||
query_string: READABLE_STRING_8
|
||||
-- A URL-encoded string; the <query> part of the Script-URI. (See
|
||||
@@ -1853,7 +1902,7 @@ feature -- URL Utility
|
||||
elseif spos > 0 then
|
||||
i := spos
|
||||
end
|
||||
spos := l_rq_uri.substring_index (percent_encoded_path_info, i)
|
||||
spos := l_rq_uri.substring_index (path_info, i)
|
||||
if spos > 0 then
|
||||
l_base_url := l_rq_uri.substring (1, spos - 1)
|
||||
else
|
||||
@@ -1879,6 +1928,9 @@ feature {NONE} -- Implementation: URL Utility
|
||||
internal_url_base: detachable STRING
|
||||
-- URL base of potential script
|
||||
|
||||
internal_percent_encoded_path_info: detachable like percent_encoded_path_info
|
||||
-- Cache value of `percent_encoded_path_info'
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_raw_input_data_recorded (b: BOOLEAN)
|
||||
|
||||
Reference in New Issue
Block a user