From 394ca46f032cb3f834bdf8ac223a180ebac06b17 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 12 Jun 2014 19:52:41 +0200 Subject: [PATCH 01/11] Added example to help debugging EWF This is mainly a kind of echo server .. that return the request information. --- examples/debug/debug.ecf | 45 ++++++++ .../debug/launcher/any/application_launcher.e | 19 ++++ .../launcher/any/application_launcher_i.e | 102 ++++++++++++++++++ .../launcher/default/application_launcher.e | 19 ++++ .../launcher/default/application_launcher_i.e | 26 +++++ examples/debug/src/ewf_debug_server.e | 45 ++++++++ 6 files changed, 256 insertions(+) create mode 100644 examples/debug/debug.ecf create mode 100644 examples/debug/launcher/any/application_launcher.e create mode 100644 examples/debug/launcher/any/application_launcher_i.e create mode 100644 examples/debug/launcher/default/application_launcher.e create mode 100644 examples/debug/launcher/default/application_launcher_i.e create mode 100644 examples/debug/src/ewf_debug_server.e diff --git a/examples/debug/debug.ecf b/examples/debug/debug.ecf new file mode 100644 index 00000000..d4ed430b --- /dev/null +++ b/examples/debug/debug.ecf @@ -0,0 +1,45 @@ + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/debug/launcher/any/application_launcher.e b/examples/debug/launcher/any/application_launcher.e new file mode 100644 index 00000000..0ef505c3 --- /dev/null +++ b/examples/debug/launcher/any/application_launcher.e @@ -0,0 +1,19 @@ +note + description: "[ + Effective class for APPLICATION_LAUNCHER_I + + You can put modification in this class + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +class + APPLICATION_LAUNCHER + +inherit + APPLICATION_LAUNCHER_I + +feature -- Custom + +end + diff --git a/examples/debug/launcher/any/application_launcher_i.e b/examples/debug/launcher/any/application_launcher_i.e new file mode 100644 index 00000000..0744c801 --- /dev/null +++ b/examples/debug/launcher/any/application_launcher_i.e @@ -0,0 +1,102 @@ +note + description: "[ + Specific application launcher + + DO NOT EDIT THIS CLASS + + you can customize APPLICATION_LAUNCHER + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +deferred class + APPLICATION_LAUNCHER_I + +inherit + SHARED_EXECUTION_ENVIRONMENT + +feature -- Execution + + launch (a_service: WSF_SERVICE; opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + nature: like launcher_nature + do + nature := launcher_nature + if nature = Void or else nature = nature_nino then + launch_nino (a_service, opts) + elseif nature = nature_cgi then + launch_cgi (a_service, opts) + elseif nature = nature_libfcgi then + launch_libfcgi (a_service, opts) + else + -- bye bye + (create {EXCEPTIONS}).die (-1) + end + end + +feature {NONE} -- Access + + launcher_nature: detachable READABLE_STRING_8 + -- Initialize the launcher nature + -- either cgi, libfcgi, or nino. + --| We could extend with more connector if needed. + --| and we could use WSF_DEFAULT_SERVICE_LAUNCHER to configure this at compilation time. + local + p: PATH + l_entry_name: READABLE_STRING_32 + ext: detachable READABLE_STRING_32 + do + create p.make_from_string (execution_environment.arguments.command_name) + if attached p.entry as l_entry then + ext := l_entry.extension + end + if ext /= Void then + if ext.same_string (nature_nino) then + Result := nature_nino + end + if ext.same_string (nature_cgi) then + Result := nature_cgi + end + if ext.same_string (nature_libfcgi) or else ext.same_string ("fcgi") then + Result := nature_libfcgi + end + end + end + +feature {NONE} -- nino + + nature_nino: STRING = "nino" + + launch_nino (a_service: WSF_SERVICE; opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_NINO_SERVICE_LAUNCHER + do + create launcher.make_and_launch (a_service, opts) + end + +feature {NONE} -- cgi + + nature_cgi: STRING = "cgi" + + launch_cgi (a_service: WSF_SERVICE; opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_CGI_SERVICE_LAUNCHER + do + create launcher.make_and_launch (a_service, opts) + end + +feature {NONE} -- libfcgi + + nature_libfcgi: STRING = "libfcgi" + + launch_libfcgi (a_service: WSF_SERVICE; opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_LIBFCGI_SERVICE_LAUNCHER + do + create launcher.make_and_launch (a_service, opts) + end + + +end + + diff --git a/examples/debug/launcher/default/application_launcher.e b/examples/debug/launcher/default/application_launcher.e new file mode 100644 index 00000000..0ef505c3 --- /dev/null +++ b/examples/debug/launcher/default/application_launcher.e @@ -0,0 +1,19 @@ +note + description: "[ + Effective class for APPLICATION_LAUNCHER_I + + You can put modification in this class + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +class + APPLICATION_LAUNCHER + +inherit + APPLICATION_LAUNCHER_I + +feature -- Custom + +end + diff --git a/examples/debug/launcher/default/application_launcher_i.e b/examples/debug/launcher/default/application_launcher_i.e new file mode 100644 index 00000000..2cd4a73d --- /dev/null +++ b/examples/debug/launcher/default/application_launcher_i.e @@ -0,0 +1,26 @@ +note + description: "[ + Specific application launcher + + DO NOT EDIT THIS CLASS + + you can customize APPLICATION_LAUNCHER + ]" + date: "$Date: 2013-06-12 13:55:42 +0200 (mer., 12 juin 2013) $" + revision: "$Revision: 36 $" + +deferred class + APPLICATION_LAUNCHER_I + +feature -- Execution + + launch (a_service: WSF_SERVICE; opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) + local + launcher: WSF_SERVICE_LAUNCHER + do + create {WSF_DEFAULT_SERVICE_LAUNCHER} launcher.make_and_launch (a_service, opts) + end + +end + + diff --git a/examples/debug/src/ewf_debug_server.e b/examples/debug/src/ewf_debug_server.e new file mode 100644 index 00000000..218b346d --- /dev/null +++ b/examples/debug/src/ewf_debug_server.e @@ -0,0 +1,45 @@ +note + description: "[ + application service + ]" + date: "$Date$" + revision: "$Revision$" + +class + EWF_DEBUG_SERVER + +inherit + WSF_LAUNCHABLE_SERVICE + redefine + initialize + end + + APPLICATION_LAUNCHER + +create + make_and_launch + +feature {NONE} -- Initialization + + initialize + -- Initialize current service. + do + Precursor + set_service_option ("verbose", True) + set_service_option ("port", 9090) + set_service_option ("base", "/www-debug/debug_service.fcgi") + end + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + local + dbg: WSF_DEBUG_HANDLER + m: WSF_PAGE_RESPONSE + do + create dbg.make + dbg.execute_starts_with ("", req, res) + --create m.make_with_body ("This is ewf debug") + --res.send (m) + end + +end + From 93c92c0e38e2f8760025d70f4cabffb312087563 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 12 Jun 2014 19:54:30 +0200 Subject: [PATCH 02/11] Avoid decoding PATH_INFO and PATH_TRANSLATED to follow CGI spec. --- library/server/wsf/src/wsf_request.e | 60 +++++++++++++++++----------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index 6e4469b9..e4a26bfe 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -18,10 +18,10 @@ note --| to keep value attached to the request 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 @@ -91,14 +91,14 @@ feature {NONE} -- Initialization 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 +106,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 + unicode_path_info := url_decoded_string (req.path_info) --| Here one can set its own environment entries if needed if meta_variable ({WSF_META_NAMES}.request_time) = Void then @@ -136,7 +129,7 @@ feature {NONE} -- Initialization --| so, let's be flexible, and accepts other variants of "on" else check is_not_https: is_https = False end - end + end end wgi_request: WGI_REQUEST @@ -165,10 +158,9 @@ feature -- Destroy internal_url_base := Void form_parameters_table.wipe_out mime_handlers := Void - path_info := empty_string_32 + unicode_path_info := empty_string_32 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 @@ -832,8 +824,13 @@ feature -- Access: CGI meta parameters - 1.1 -- Non decoded 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]" + do + Result := path_info + end - path_info: READABLE_STRING_32 + path_info: READABLE_STRING_8 -- 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 @@ -861,10 +858,15 @@ 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. - -- - -- See `percent_encoded_path_info' to get the original non decoded path info. + do + Result := wgi_request.path_info + end - path_translated: detachable READABLE_STRING_32 + unicode_path_info: READABLE_STRING_32 + -- Percent decoded version of `path_info' + -- See `path_info' to get the original non decoded path info. + + 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 +909,18 @@ 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. + 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 part of the Script-URI. (See @@ -1823,7 +1837,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 From 942896aa0c9fecf753c407c3460d0c6c288c6794 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 12 Jun 2014 20:02:57 +0200 Subject: [PATCH 03/11] Fixed library location for http --- examples/debug/debug.ecf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/debug/debug.ecf b/examples/debug/debug.ecf index d4ed430b..9aecc058 100644 --- a/examples/debug/debug.ecf +++ b/examples/debug/debug.ecf @@ -10,7 +10,7 @@ - + From 425c9760327daa60fe3fa134ded34e90f8847e32 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 30 Jun 2014 15:13:47 +0200 Subject: [PATCH 04/11] 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. --- .../connectors/nino/src/wgi_nino_handler.e | 18 +- .../ewsgi/specification/request/wgi_request.e | 10 + .../request/wgi_request_cgi_variables.e | 366 ++++++++++++++++++ .../implementation/wgi_request_from_table.e | 1 + .../wsf/extension/filter/wsf_debug_filter.e | 24 +- .../wsf/extension/handler/wsf_debug_handler.e | 130 ++----- .../wsf/extension/wsf_debug_information.e | 340 ++++++++++++++++ library/server/wsf/src/request/wsf_value.e | 3 +- library/server/wsf/src/wsf_request.e | 92 +++-- library/text/encoder/src/percent_encoder.e | 11 +- library/text/encoder/src/url_encoder.e | 9 +- 11 files changed, 860 insertions(+), 144 deletions(-) create mode 100644 library/server/ewsgi/specification/request/wgi_request_cgi_variables.e create mode 100644 library/server/wsf/extension/wsf_debug_information.e diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e index 314c4c57..e28c1151 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e @@ -74,8 +74,8 @@ feature -- Request processing l_request_uri := a_handler.uri l_headers_map := a_handler.request_header_map create e + create enc if attached e.starting_environment as vars then - create enc create env.make_equal (vars.count) across vars as c @@ -168,8 +168,22 @@ feature -- Request processing if p > 0 then l_path_info.keep_head (p - 1) end - env.force (l_path_info, "PATH_INFO") + env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") env.force (l_base, "SCRIPT_NAME") + else + -- This should not happen, this means the `base' is not correctly set. + -- It is better to consider base as empty, rather than having empty PATH_INFO + check valid_base_value: False end + + l_path_info := l_request_uri + p := l_request_uri.index_of ('?', 1) + if p > 0 then + l_path_info := l_request_uri.substring (1, p - 1) + else + l_path_info := l_request_uri.string + end + env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") + env.force ("", "SCRIPT_NAME") end end diff --git a/library/server/ewsgi/specification/request/wgi_request.e b/library/server/ewsgi/specification/request/wgi_request.e index 697e0ba2..f6a10e35 100644 --- a/library/server/ewsgi/specification/request/wgi_request.e +++ b/library/server/ewsgi/specification/request/wgi_request.e @@ -88,6 +88,14 @@ feature -- Access: Input feature -- Access: CGI meta variables + cgi_variables: WGI_REQUEST_CGI_VARIABLES + -- Object containing the CGI variables + --| note: a new instance is created on each call! + --| this is mainly for debugging purpose. + do + create Result.make (Current) + end + meta_variable (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_8 -- Environment variable related to `a_name' require @@ -297,6 +305,8 @@ feature -- Common Gateway Interface - 1.1 8 January 1996 -- 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. + -- + -- Note: it is UTF-8 encoded, and percent decoded. deferred end diff --git a/library/server/ewsgi/specification/request/wgi_request_cgi_variables.e b/library/server/ewsgi/specification/request/wgi_request_cgi_variables.e new file mode 100644 index 00000000..a969dfad --- /dev/null +++ b/library/server/ewsgi/specification/request/wgi_request_cgi_variables.e @@ -0,0 +1,366 @@ +note + description: "[ + Object containing the CGI variable for a specific WGI request. + This is mainly used for debugging purpose. + ]" + date: "$Date$" + revision: "$Revision$" + +class + WGI_REQUEST_CGI_VARIABLES + +inherit + DEBUG_OUTPUT + +create + make + +feature {NONE} -- Initialization + + make (req: WGI_REQUEST) + -- Initialize Current from `req'. + local + utf: UTF_CONVERTER + do + auth_type := req.auth_type + content_length := req.content_length + if attached req.content_type as ct then + content_type := ct.string + else + content_type := Void + end + gateway_interface := req.gateway_interface + path_info := req.path_info + path_translated := req.path_translated + query_string := req.query_string + remote_addr := req.remote_addr + remote_host := req.remote_host + remote_ident := req.remote_ident + remote_user := req.remote_user + request_method := req.request_method + script_name := req.script_name + server_name := req.server_name + server_port := req.server_port + server_protocol := req.server_protocol + server_software := req.server_software + + create http_meta_variables.make (0) + across + req.meta_variables as ic + loop + if ic.key.starts_with ("HTTP_") then + if ic.key.is_valid_as_string_8 then + http_meta_variables.force (ic.item, ic.key.as_string_8) + else + http_meta_variables.force (ic.item, utf.escaped_utf_32_string_to_utf_8_string_8 (ic.key)) + end + end + end + end + +feature -- Status report + + debug_output: STRING_32 + -- + do + create Result.make (1_024) + append_variable_to_debug_output ("AUTH_TYPE", auth_type, Result) + append_variable_to_debug_output ("CONTENT_LENGTH", content_length, Result) + append_variable_to_debug_output ("CONTENT_TYPE", content_type, Result) + append_required_variable_to_debug_output ("GATEWAY_INTERFACE", gateway_interface, Result) + across + http_meta_variables as ic + loop + append_variable_to_debug_output (ic.key, ic.item, Result) + end + append_required_variable_to_debug_output ("PATH_INFO", path_info, Result) + append_variable_to_debug_output ("PATH_TRANSLATED", path_translated, Result) + append_required_variable_to_debug_output ("QUERY_STRING", query_string, Result) + append_required_variable_to_debug_output ("REMOTE_ADDR", remote_addr, Result) + append_variable_to_debug_output ("REMOTE_HOST", remote_host, Result) + append_variable_to_debug_output ("REMOTE_IDENT", remote_ident, Result) + append_variable_to_debug_output ("REMOTE_USER", remote_user, Result) + append_required_variable_to_debug_output ("REQUEST_METHOD", request_method, Result) + append_variable_to_debug_output ("SCRIPT_NAME", script_name, Result) + append_required_variable_to_debug_output ("SERVER_NAME", server_name, Result) + append_variable_to_debug_output ("SERVER_PORT", server_port.out, Result) + append_variable_to_debug_output ("SERVER_PROTOCOL", request_method, Result) + append_variable_to_debug_output ("SERVER_SOFTWARE", server_software, Result) + end + +feature {NONE} -- Implementation + + append_required_variable_to_debug_output (a_name: READABLE_STRING_8; a_value: READABLE_STRING_GENERAL; a_output: STRING_32) + require + a_value_not_is_empty: a_value /= Void + do + a_output.append (a_name) + a_output.append_character ('=') + a_output.append_string_general (a_value) + a_output.append_character ('%N') + end + + append_variable_to_debug_output (a_name: READABLE_STRING_8; a_value: detachable READABLE_STRING_GENERAL; a_output: STRING_32) + do + if a_value /= Void then + a_output.append (a_name) + a_output.append_character ('=') + a_output.append_string_general (a_value) + a_output.append_character ('%N') + end + end + +feature -- Access: meta variable + + auth_type: detachable READABLE_STRING_8 + -- The variable is specific to requests made with HTTP. + -- + -- If the script URI would require access authentication for external + -- access, then this variable is found from the `auth-scheme' token + -- in the request, otherwise NULL. + -- + -- auth-scheme = "Basic" | token + -- + -- HTTP access authentication schemes are described in section 11 of + -- the HTTP/1.0 specification [3]. The auth-scheme is not + -- case-sensitive. + + content_length: detachable READABLE_STRING_8 + -- The size of the entity attached to the request, if any, in decimal + -- number of octets. If no data is attached, then NULL. The syntax is + -- the same as the HTTP Content-Length header (section 10, HTTP/1.0 + -- specification [3]). + -- + -- CONTENT_LENGTH = "" | [ 1*digit ] + + content_type: detachable READABLE_STRING_8 + -- The Internet Media Type [9] of the attached entity. The syntax is + -- the same as the HTTP Content-Type header. + -- + -- CONTENT_TYPE = "" | media-type + -- media-type = type "/" subtype *( ";" parameter) + -- type = token + -- subtype = token + -- parameter = attribute "=" value + -- attribute = token + -- value = token | quoted-string + -- + -- The type, subtype and parameter attribute names are not + -- case-sensitive. Parameter values may be case sensitive. Media + -- types and their use in HTTP are described section 3.6 of the + -- HTTP/1.0 specification [3]. Example: + -- + -- application/x-www-form-urlencoded + -- + -- There is no default value for this variable. If and only if it is + -- unset, then the script may attempt to determine the media type + -- from the data received. If the type remains unknown, then + -- application/octet-stream should be assumed. + + gateway_interface: READABLE_STRING_8 + -- The version of the CGI specification to which this server + -- complies. Syntax: + -- + -- GATEWAY_INTERFACE = "CGI" "/" 1*digit "." 1*digit + -- + -- Note that the major and minor numbers are treated as separate + -- integers and that each may be incremented higher than a single + -- digit. Thus CGI/2.4 is a lower version than CGI/2.13 which in + -- turn is lower than CGI/12.3. Leading zeros must be ignored by + -- scripts and should never be generated by servers. + + http_meta_variables: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8] + -- These variables are specific to requests made with HTTP. + -- Interpretation of these variables may depend on the value of + -- SERVER_PROTOCOL. + -- + -- Environment variables with names beginning with "HTTP_" contain + -- header data read from the client, if the protocol used was HTTP. + -- The HTTP header name is converted to upper case, has all + -- occurrences of "-" replaced with "_" and has "HTTP_" prepended to + -- give the environment variable name. The header data may be + -- presented as sent by the client, or may be rewritten in ways which + -- do not change its semantics. If multiple headers with the same + -- field-name are received then they must be rewritten as a single + -- header having the same semantics. Similarly, a header that is + -- received on more than one line must be merged onto a single line. + -- The server must, if necessary, change the representation of the + -- data (for example, the character set) to be appropriate for a CGI + -- environment variable. + -- + -- The server is not required to create environment variables for all + -- the headers that it receives. In particular, it may remove any + -- headers carrying authentication information, such as + -- "Authorization"; it may remove headers whose value is available to + -- the script via other variables, such as "Content-Length" and + -- "Content-Type". + + path_info: READABLE_STRING_GENERAL + -- A path to be interpreted by the CGI script. It identifies the + -- resource or sub-resource to be returned by the CGI script. The + -- syntax and semantics are similar to a decoded HTTP URL `hpath' + -- token (defined in RFC 1738 [4]), with the exception that a + -- PATH_INFO of "/" represents a single void path segment. Otherwise, + -- the leading "/" character is not part of the path. + -- + -- PATH_INFO = "" | "/" path + -- path = segment *( "/" segment ) + -- segment = *pchar + -- pchar = + -- + -- The PATH_INFO string is the trailing part of the component + -- of the script URI that follows the SCRIPT_NAME part of the path. + + path_translated: detachable READABLE_STRING_GENERAL + -- The OS path to the file that the server would attempt to access + -- were the client to request the absolute URL containing the path + -- PATH_INFO. i.e for a request of + -- + -- protocol "://" SERVER_NAME ":" SERVER_PORT enc-path-info + -- + -- where `enc-path-info' is a URL-encoded version of PATH_INFO. If + -- PATH_INFO is NULL then PATH_TRANSLATED is set to NULL. + -- + -- PATH_TRANSLATED = *CHAR + -- + -- PATH_TRANSLATED need not be supported by the server. The server + -- may choose to set PATH_TRANSLATED to NULL for reasons of security, + -- or because the path would not be interpretable by a CGI script; + -- such as the object it represented was internal to the server and + -- not visible in the file-system; or for any other reason. + -- + -- The algorithm the server uses to derive PATH_TRANSLATED is + -- obviously implementation defined; CGI scripts which use this + -- variable may suffer limited portability. + + query_string: READABLE_STRING_GENERAL + -- A URL-encoded search string; the part of the script URI. + -- + -- QUERY_STRING = query-string + -- query-string = *qchar + -- qchar = unreserved | escape | reserved + -- unreserved = alpha | digit | safe | extra + -- reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" + -- safe = "$" | "-" | "_" | "." | "+" + -- extra = "!" | "*" | "'" | "(" | ")" | "," + -- escape = "%" hex hex + -- hex = digit | "A" | "B" | "C" | "D" | "E" | "F" | "a" + -- | "b" | "c" | "d" | "e" | "f" + -- + -- The URL syntax for a search string is described in RFC 1738 [4]. + + remote_addr: READABLE_STRING_GENERAL + -- The IP address of the agent sending the request to the server. Not + -- necessarily that of the client. + -- + -- REMOTE_ADDR = hostnumber + -- hostnumber = digits "." digits "." digits "." digits + -- digits = 1*digit + + remote_host: detachable READABLE_STRING_GENERAL + -- The fully qualified domain name of the agent sending the request + -- to the server, if available, otherwise NULL. Not necessarily that + -- of the client. Fully qualified domain names take the form as + -- described in section 3.5 of RFC 1034 [8] and section 2.1 of RFC + -- 1123 [5]; a sequence of domain labels separated by ".", each + -- domain label starting and ending with an alphanumerical character + -- and possibly also containing "-" characters. The rightmost domain + -- label will never start with a digit. Domain names are not case + -- sensitive. + -- + -- REMOTE_HOST = "" | hostname + -- hostname = *( domainlabel ".") toplabel + -- domainlabel = alphadigit [ *alphahypdigit alphadigit ] + -- toplabel = alpha [ *alphahypdigit alphadigit ] + -- alphahypdigit = alphadigit | "-" + -- alphadigit = alpha | digit + + remote_ident: detachable READABLE_STRING_GENERAL + -- The identity information reported about the connection by a RFC + -- 931 [10] request to the remote agent, if available. The server may + -- choose not to support this feature, or not to request the data for + -- efficiency reasons. + -- + -- REMOTE_IDENT = *CHAR + -- + -- The data returned is not appropriate for use as authentication + -- information. + + remote_user: detachable READABLE_STRING_GENERAL + -- This variable is specific to requests made with HTTP. + -- + -- If AUTH_TYPE is "Basic", then the user-ID sent by the client. If + -- AUTH_TYPE is NULL, then NULL, otherwise undefined. + -- + -- userid = token + + request_method: READABLE_STRING_GENERAL + -- This variable is specific to requests made with HTTP. + -- + -- The method with which the request was made, as described in + -- section 5.1.1 of the HTTP/1.0 specification [3]. + -- + -- http-method = "GET" | "HEAD" | "POST" | extension-method + -- extension-method = token + -- + -- The method is case sensitive. + + script_name: READABLE_STRING_GENERAL + -- A URL path that could identify the CGI script (rather then the + -- particular CGI output). The syntax and semantics are identical to + -- a decoded HTTP URL `hpath' token [4]. + -- + -- SCRIPT_NAME = "" | "/" [ path ] + -- + -- The leading "/" is not part of the path. It is optional if the + -- path is NULL. + -- + -- The SCRIPT_NAME string is some leading part of the + -- component of the script URI derived in some implementation defined + -- manner. + + server_name: READABLE_STRING_GENERAL + -- The name for this server, as used in the part of the script + -- URI. Thus either a fully qualified domain name, or an IP address. + -- + -- SERVER_NAME = hostname | hostnumber + + server_port: INTEGER + -- The port on which this request was received, as used in the + -- part of the script URI. + -- + -- SERVER_PORT = 1*digit + + server_protocol: READABLE_STRING_GENERAL + -- The name and revision of the information protocol this request + -- came in with. + -- + -- SERVER_PROTOCOL = HTTP-Version | extension-version + -- HTTP-Version = "HTTP" "/" 1*digit "." 1*digit + -- extension-version = protocol "/" 1*digit "." 1*digit + -- protocol = 1*( alpha | digit | "+" | "-" | "." ) + -- + -- `protocol' is a version of the part of the script URI, + -- and is not case sensitive. By convention, `protocol' is in upper + -- case. + + server_software: READABLE_STRING_GENERAL + -- The name and version of the information server software answering + -- the request (and running the gateway). + -- + -- SERVER_SOFTWARE = *CHAR + +invariant + request_method_set: not request_method.is_empty + +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 diff --git a/library/server/ewsgi/src/implementation/wgi_request_from_table.e b/library/server/ewsgi/src/implementation/wgi_request_from_table.e index 4368bb33..69d20e1a 100644 --- a/library/server/ewsgi/src/implementation/wgi_request_from_table.e +++ b/library/server/ewsgi/src/implementation/wgi_request_from_table.e @@ -319,6 +319,7 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO until a_vars.after loop + -- Warning: truncated value to ascii !!! table.force (a_vars.item_for_iteration.to_string_8, a_vars.key_for_iteration) a_vars.forth end diff --git a/library/server/wsf/extension/filter/wsf_debug_filter.e b/library/server/wsf/extension/filter/wsf_debug_filter.e index 6563f425..11eaf8fc 100644 --- a/library/server/wsf/extension/filter/wsf_debug_filter.e +++ b/library/server/wsf/extension/filter/wsf_debug_filter.e @@ -28,23 +28,19 @@ 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_path_parameters_to (req, res, s) if not s.is_empty then - s.prepend ("**DEBUG**%N") + s.append ("**DEBUG**%N") if attached output as o then o.put_string (s) else @@ -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. diff --git a/library/server/wsf/extension/handler/wsf_debug_handler.e b/library/server/wsf/extension/handler/wsf_debug_handler.e index 7acce7c1..e64cb34c 100644 --- a/library/server/wsf/extension/handler/wsf_debug_handler.e +++ b/library/server/wsf/extension/handler/wsf_debug_handler.e @@ -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,59 @@ 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 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.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 diff --git a/library/server/wsf/extension/wsf_debug_information.e b/library/server/wsf/extension/wsf_debug_information.e new file mode 100644 index 00000000..6869443d --- /dev/null +++ b/library/server/wsf/extension/wsf_debug_information.e @@ -0,0 +1,340 @@ +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 ('=') + s := c.item.string_representation + 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 + +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 diff --git a/library/server/wsf/src/request/wsf_value.e b/library/server/wsf/src/request/wsf_value.e index 6a1577e9..ce57dd63 100644 --- a/library/server/wsf/src/request/wsf_value.e +++ b/library/server/wsf/src/request/wsf_value.e @@ -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 diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index e4a26bfe..95e7bfa8 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -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 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) diff --git a/library/text/encoder/src/percent_encoder.e b/library/text/encoder/src/percent_encoder.e index 75b9961e..8a0d90b2 100644 --- a/library/text/encoder/src/percent_encoder.e +++ b/library/text/encoder/src/percent_encoder.e @@ -208,8 +208,15 @@ feature {NONE} -- Implementation: character encoding feature -- Percent decoding percent_decoded_string (v: READABLE_STRING_GENERAL): STRING_32 - -- Return the percent decoded string equivalent to the percent-encoded string `v' - --| Note that is `a_result' is a STRING_8, any Unicode character will be kept as UTF-8 + -- Return the percent decoded unicode string equivalent to the percent-encoded string `v' + do + create Result.make (v.count) + append_percent_decoded_string_to (v, Result) + end + + percent_decoded_utf_8_string (v: READABLE_STRING_GENERAL): STRING_8 + -- Return the percent decoded UTF-8 string equivalent to the percent-encoded string `v' + --| Note that any Unicode character will be kept as UTF-8 do create Result.make (v.count) append_percent_decoded_string_to (v, Result) diff --git a/library/text/encoder/src/url_encoder.e b/library/text/encoder/src/url_encoder.e index 8975e8cb..d327f0e9 100644 --- a/library/text/encoder/src/url_encoder.e +++ b/library/text/encoder/src/url_encoder.e @@ -23,7 +23,8 @@ inherit PERCENT_ENCODER rename percent_encoded_string as general_encoded_string, - percent_decoded_string as general_decoded_string + percent_decoded_string as general_decoded_string, + percent_decoded_utf_8_string as general_decoded_utf_8_string end feature -- Access @@ -49,6 +50,12 @@ feature -- Decoder Result := general_decoded_string (v) end + decoded_utf_8_string (v: READABLE_STRING_8): STRING_8 + -- The URL-encoded equivalent of the given string + do + Result := general_decoded_utf_8_string (v) + end + note copyright: "Copyright (c) 2011-2014, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" From 66a1e0629cb13bc2af2d5203a4a5ed4e91864130 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 30 Jun 2014 15:16:31 +0200 Subject: [PATCH 05/11] Improved the debug example, so that it outputs more information. --- examples/debug/debug.ecf | 6 ++++-- examples/debug/src/ewf_debug_server.e | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/debug/debug.ecf b/examples/debug/debug.ecf index 9aecc058..7b1f2b7b 100644 --- a/examples/debug/debug.ecf +++ b/examples/debug/debug.ecf @@ -9,14 +9,16 @@ + + - + - + diff --git a/examples/debug/src/ewf_debug_server.e b/examples/debug/src/ewf_debug_server.e index 218b346d..8900d2a7 100644 --- a/examples/debug/src/ewf_debug_server.e +++ b/examples/debug/src/ewf_debug_server.e @@ -27,18 +27,15 @@ feature {NONE} -- Initialization Precursor set_service_option ("verbose", True) set_service_option ("port", 9090) - set_service_option ("base", "/www-debug/debug_service.fcgi") +-- set_service_option ("base", "/www-debug/debug_service.fcgi/") end execute (req: WSF_REQUEST; res: WSF_RESPONSE) local dbg: WSF_DEBUG_HANDLER - m: WSF_PAGE_RESPONSE do create dbg.make dbg.execute_starts_with ("", req, res) - --create m.make_with_body ("This is ewf debug") - --res.send (m) end end From add71543a4602f8ad9cbfba3d428212b627c5d87 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 30 Jun 2014 15:21:03 +0200 Subject: [PATCH 06/11] Fixed error introduced during refactorying on WSF_DEBUG_FILTER --- library/server/wsf/extension/filter/wsf_debug_filter.e | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/server/wsf/extension/filter/wsf_debug_filter.e b/library/server/wsf/extension/filter/wsf_debug_filter.e index 11eaf8fc..4a715457 100644 --- a/library/server/wsf/extension/filter/wsf_debug_filter.e +++ b/library/server/wsf/extension/filter/wsf_debug_filter.e @@ -37,10 +37,10 @@ feature -- Basic operations 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_path_parameters_to (req, res, s) + dbg.append_form_parameters_to (req, res, s) if not s.is_empty then - s.append ("**DEBUG**%N") + s.prepend ("**DEBUG**%N") if attached output as o then o.put_string (s) else From 0b1697f20d2f7c05b0ae8e9199bb0ae831b8a5d0 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 30 Jun 2014 15:45:54 +0200 Subject: [PATCH 07/11] Verbose mode for the WSF_DEBUG_HANDLER. --- library/server/wsf/extension/handler/wsf_debug_handler.e | 1 + 1 file changed, 1 insertion(+) diff --git a/library/server/wsf/extension/handler/wsf_debug_handler.e b/library/server/wsf/extension/handler/wsf_debug_handler.e index e64cb34c..3bc35bf5 100644 --- a/library/server/wsf/extension/handler/wsf_debug_handler.e +++ b/library/server/wsf/extension/handler/wsf_debug_handler.e @@ -58,6 +58,7 @@ feature -- Access s.append ("%N") create dbg.make + dbg.set_is_verbose (True) dbg.append_information_to (req, res, s) s.append ("= END =") From 7dfc6ea67aafbef0c7971da9efc7df74827ab64e Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 1 Jul 2014 19:57:14 +0200 Subject: [PATCH 08/11] Fixed various issues related to unicode and CGI variables (assuming that CGI variables are utf-8 encoded, and sometime percent encoded). Delayed computation of `value' and `name' from WSF_STRING. Fixed computation of REQUEST_URI when the server does not provide it (this is rare, but possible). compute it as SERVER_NAME + encoded-PATH_INFO + {? + QUERY_STRING} --- .../connectors/nino/src/wgi_nino_handler.e | 5 +- .../implementation/wgi_request_from_table.e | 34 +++-- .../server/wsf/src/request/value/wsf_string.e | 120 +++++++++++++++++- 3 files changed, 140 insertions(+), 19 deletions(-) diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e index e28c1151..8bbf1b25 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e @@ -70,6 +70,7 @@ feature -- Request processing e: EXECUTION_ENVIRONMENT enc: URL_ENCODER + utf: UTF_CONVERTER do l_request_uri := a_handler.uri l_headers_map := a_handler.request_header_map @@ -80,13 +81,13 @@ feature -- Request processing across vars as c loop - env.force (enc.encoded_string (c.item), enc.encoded_string (c.key)) + env.force (utf.utf_32_string_to_utf_8_string_8 (c.item), utf.utf_32_string_to_utf_8_string_8 (c.key)) end else create env.make (0) end - --| 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 l_headers_map.start until diff --git a/library/server/ewsgi/src/implementation/wgi_request_from_table.e b/library/server/ewsgi/src/implementation/wgi_request_from_table.e index 69d20e1a..5274075a 100644 --- a/library/server/ewsgi/src/implementation/wgi_request_from_table.e +++ b/library/server/ewsgi/src/implementation/wgi_request_from_table.e @@ -253,7 +253,7 @@ feature -- Access: HTTP_* CGI meta parameters - 1.1 do Result := meta_string_variable ({WGI_META_NAMES}.http_if_match) end - + http_if_modified_since: detachable READABLE_STRING_8 -- Modification check on resource do @@ -306,8 +306,11 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO s: like meta_string_variable table: STRING_TABLE [READABLE_STRING_8] l_query_string: like query_string - l_request_uri: detachable STRING_32 + l_request_uri: detachable READABLE_STRING_8 + s8: STRING_8 l_empty_string: like empty_string + enc: PERCENT_ENCODER + utf: UTF_CONVERTER do create {STRING_8} l_empty_string.make_empty empty_string := l_empty_string @@ -319,8 +322,11 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO until a_vars.after loop - -- Warning: truncated value to ascii !!! - table.force (a_vars.item_for_iteration.to_string_8, a_vars.key_for_iteration) + if attached {READABLE_STRING_32} a_vars.item_for_iteration as s32 then + table.force (utf.utf_32_string_to_utf_8_string_8 (s32), a_vars.key_for_iteration) + else + table.force (a_vars.item_for_iteration.to_string_8, a_vars.key_for_iteration) + end a_vars.forth end @@ -370,14 +376,22 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO if s /= Void then l_request_uri := s else - --| It might occur that REQUEST_URI is not available, so let's compute it from SCRIPT_NAME - create l_request_uri.make_from_string (script_name) + --| REQUEST_URI is not always available, in this case, + --| compute it from SCRIPT_NAME, PATH_INFO and QUERY_STRING which are required by CGI. + create s8.make_from_string (script_name) + create enc + enc.append_partial_percent_encoded_string_to (utf.utf_8_string_8_to_string_32 (path_info), s8, <<'/', '!', '$', '&', '%'', '(', ')', '*', '+', ',', ';', '='>>) if not l_query_string.is_empty then - l_request_uri.append_character ('?') - l_request_uri.append (l_query_string) + s8.append_character ('?') + s8.append (l_query_string) end + l_request_uri := s8 end - request_uri := single_slash_starting_string (l_request_uri) + --| FIXME: should it strip "////abc/def" to "/abc/def" ? + --| Not sure why this was done before. +-- l_request_uri := single_slash_starting_string (l_request_uri) + request_uri := l_request_uri + set_meta_string_variable ({WGI_META_NAMES}.request_uri, l_request_uri) end set_orig_path_info (s: READABLE_STRING_8) @@ -482,7 +496,7 @@ invariant empty_string_unchanged: empty_string.is_empty note - copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software diff --git a/library/server/wsf/src/request/value/wsf_string.e b/library/server/wsf/src/request/value/wsf_string.e index 0da28891..a969072e 100644 --- a/library/server/wsf/src/request/value/wsf_string.e +++ b/library/server/wsf/src/request/value/wsf_string.e @@ -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 -- --| 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 -- --| 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 From 446c692f97b251fd9837cf2c8800ddf5196a32d1 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 1 Jul 2014 19:59:08 +0200 Subject: [PATCH 09/11] Various changes related to new WSF_DEBUG_INFORMATION and WSF_DEBUG_HANDLER. --- examples/debug/src/ewf_debug_server.e | 3 +- .../wsf/extension/handler/wsf_debug_handler.e | 2 + .../wsf/extension/wsf_debug_information.e | 61 ++++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/examples/debug/src/ewf_debug_server.e b/examples/debug/src/ewf_debug_server.e index 8900d2a7..3725bfc9 100644 --- a/examples/debug/src/ewf_debug_server.e +++ b/examples/debug/src/ewf_debug_server.e @@ -25,7 +25,7 @@ feature {NONE} -- Initialization -- Initialize current service. do Precursor - set_service_option ("verbose", True) +-- set_service_option ("verbose", True) set_service_option ("port", 9090) -- set_service_option ("base", "/www-debug/debug_service.fcgi/") end @@ -34,6 +34,7 @@ feature {NONE} -- Initialization local dbg: WSF_DEBUG_HANDLER do + res.put_error ("DEBUG" + req.request_uri + "%N") create dbg.make dbg.execute_starts_with ("", req, res) end diff --git a/library/server/wsf/extension/handler/wsf_debug_handler.e b/library/server/wsf/extension/handler/wsf_debug_handler.e index 3bc35bf5..00a6437a 100644 --- a/library/server/wsf/extension/handler/wsf_debug_handler.e +++ b/library/server/wsf/extension/handler/wsf_debug_handler.e @@ -52,6 +52,7 @@ feature -- Access p: WSF_PAGE_RESPONSE l_len: INTEGER dbg: WSF_DEBUG_INFORMATION + utf: UTF_CONVERTER do create s.make (2048) s.append ("= EWF DEBUG =") @@ -59,6 +60,7 @@ feature -- Access create dbg.make dbg.set_is_verbose (True) + dbg.append_cgi_variables_to (req, res, s) dbg.append_information_to (req, res, s) s.append ("= END =") diff --git a/library/server/wsf/extension/wsf_debug_information.e b/library/server/wsf/extension/wsf_debug_information.e index 6869443d..1b9b2180 100644 --- a/library/server/wsf/extension/wsf_debug_information.e +++ b/library/server/wsf/extension/wsf_debug_information.e @@ -135,7 +135,7 @@ feature -- Execution 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) +-- append_environment_variables_to (req, res, a_output) end end @@ -292,7 +292,11 @@ feature {NONE} -- Implementation a_output.append_character ('}') end a_output.append_character ('=') - s := c.item.string_representation + 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 @@ -321,6 +325,59 @@ feature {NONE} -- Implementation 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" From 1b4b50ee8047afb379860f729292eaf5b1584e12 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Wed, 2 Jul 2014 11:36:43 +0200 Subject: [PATCH 10/11] Replace any multiple slash sequence by a single slash character for PATH_INFO. --- .../connectors/nino/src/wgi_nino_handler.e | 34 +++++++++++++++++-- .../implementation/wgi_request_from_table.e | 6 ++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e index 8bbf1b25..86eb66b0 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e @@ -169,7 +169,6 @@ feature -- Request processing if p > 0 then l_path_info.keep_head (p - 1) end - env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") env.force (l_base, "SCRIPT_NAME") else -- This should not happen, this means the `base' is not correctly set. @@ -183,9 +182,11 @@ feature -- Request processing else l_path_info := l_request_uri.string end - env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") env.force ("", "SCRIPT_NAME") end + --| Strip multiple slashes "////abc/def///end////" to "/abc/def/end/" ? + convert_multiple_slashes_to_single (l_path_info) + env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") end callback.process_request (env, a_handler.request_header, a_socket) @@ -213,6 +214,35 @@ feature -- Request processing end end +feature {NONE} -- Implementation + + convert_multiple_slashes_to_single (s: STRING_8) + -- Replace multiple slashes sequence by a single slash character. + local + i,n: INTEGER + do + from + i := 1 + n := s.count + until + i > n + loop + if s[i] = '/' then + -- Remove following slashes '/'. + from + i := i + 1 + until + i > n or s[i] /= '/' + loop + s.remove (i) + n := n - 1 + end + else + i := i + 1 + end + end + end + note copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/server/ewsgi/src/implementation/wgi_request_from_table.e b/library/server/ewsgi/src/implementation/wgi_request_from_table.e index 5274075a..a58eadcb 100644 --- a/library/server/ewsgi/src/implementation/wgi_request_from_table.e +++ b/library/server/ewsgi/src/implementation/wgi_request_from_table.e @@ -387,11 +387,8 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO end l_request_uri := s8 end - --| FIXME: should it strip "////abc/def" to "/abc/def" ? - --| Not sure why this was done before. --- l_request_uri := single_slash_starting_string (l_request_uri) - request_uri := l_request_uri set_meta_string_variable ({WGI_META_NAMES}.request_uri, l_request_uri) + request_uri := l_request_uri end set_orig_path_info (s: READABLE_STRING_8) @@ -418,6 +415,7 @@ feature {NONE} -- Element change: CGI meta parameter related to PATH_INFO l_path_info: STRING do l_path_info := path_info + --| Warning --| on IIS: we might have PATH_INFO = /sample.exe/foo/bar --| on apache: PATH_INFO = /foo/bar From ff19adc6c8124172072f5f10678280687c0c8832 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 7 Jul 2014 11:27:31 +0200 Subject: [PATCH 11/11] Improved comment related to PATH_INFO and stripping multiple slashes sequence to single slash. --- library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e index 86eb66b0..528a48c1 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e @@ -184,7 +184,11 @@ feature -- Request processing end env.force ("", "SCRIPT_NAME") end - --| Strip multiple slashes "////abc/def///end////" to "/abc/def/end/" ? + --| In order to have same path value for PATH_INFO on various connectors and servers + --| the multiple slashes must be stripped to single slash. + --| tested with: CGI+apache, libfcgi+apache on Windows and Linux + --| + --| For example: "////abc/def///end////" to "/abc/def/end/" ? convert_multiple_slashes_to_single (l_path_info) env.force (enc.decoded_utf_8_string (l_path_info), "PATH_INFO") end