Ensure that PATH_INFO and REQUEST_URI are following the CGI specifications:

- PATH_INFO is percent decoded but still utf-8 encoded,
  this is available via WGI.path_info and WSF_REQUEST.utf_8_path_info.
- Added WSF_REQUEST.percent_encoded_path_info
- and WSF_REQUEST.path_info remains the unicode value for PATH_INFO

Added cgi_variables: WGI_REQUEST_CGI_VARIABLES to have a simple and quick view on CGI variables
Added execution_variables to be able to iterate on execution variables.
Added PERCENT_ENCODER.percent_decoded_utf_8_string
Improved the WSF_DEBUG_HANDLER to provide more information thanks to WSF_DEBUG_INFORMATION object.
This commit is contained in:
2014-06-30 15:13:47 +02:00
parent 942896aa0c
commit 425c976032
11 changed files with 860 additions and 144 deletions

View File

@@ -87,6 +87,7 @@ feature {NONE} -- Initialization
local
s8: detachable READABLE_STRING_8
req: WGI_REQUEST
utf: UTF_CONVERTER
do
init_mime_handlers
req := wgi_request
@@ -110,7 +111,7 @@ feature {NONE} -- Initialization
request_method := req.request_method
--| PATH_INFO
unicode_path_info := url_decoded_string (req.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
@@ -132,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
@@ -158,7 +169,8 @@ feature -- Destroy
internal_url_base := Void
form_parameters_table.wipe_out
mime_handlers := Void
unicode_path_info := empty_string_32
path_info := empty_string_32
internal_percent_encoded_path_info := Void
path_parameters_source := Void
path_parameters_table := Void
raw_input_data := Void
@@ -604,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
@@ -821,24 +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
obsolete
"Use directly `path_info' which is not decoded [June/2014]"
--| 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
Result := path_info
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
path_info: READABLE_STRING_8
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 )
@@ -858,13 +904,9 @@ feature -- Access: CGI meta parameters - 1.1
-- 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.
do
Result := wgi_request.path_info
end
unicode_path_info: READABLE_STRING_32
-- Percent decoded version of `path_info'
-- See `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_8
-- PATH_TRANSLATED is derived by taking any path-info component
@@ -909,19 +951,12 @@ 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
unicode_path_translated: detachable READABLE_STRING_32
-- Percent decoded version of `path_translated'
-- See `path_translated' to get the original non decoded path info.
do
if attached path_translated as s then
Result := url_decoded_string (s)
end
end
query_string: READABLE_STRING_8
-- A URL-encoded string; the <query> part of the Script-URI. (See
-- section 3.2.)
@@ -1863,6 +1898,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)