From 20281bc9220879d3b549f50bcac20c20a07c7d28 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 6 Jan 2012 18:27:52 +0100 Subject: [PATCH] HTTP_HEADER: - added put_last_modified - added RFC1123 http date format helper - added put_cookie_with_expiration_date as DATE_TIME REQUEST: added `execution_variable' to provide a way to keep object attached to the request and indexed by a string. A typical usage is a SESSION object --- .../request/rest/src/rest_request_handler.e | 5 +- .../rest/src/rest_request_handler_context.e | 46 +------------------ library/protocol/http/src/http_header.e | 25 +++++++++- .../wsf/router/request_handler_context.e | 44 ++++++++++++++++++ library/server/wsf/src/wsf_request.e | 41 ++++++----------- 5 files changed, 84 insertions(+), 77 deletions(-) diff --git a/draft/library/server/request/rest/src/rest_request_handler.e b/draft/library/server/request/rest/src/rest_request_handler.e index 0f8795e5..df202468 100644 --- a/draft/library/server/request/rest/src/rest_request_handler.e +++ b/draft/library/server/request/rest/src/rest_request_handler.e @@ -9,9 +9,6 @@ deferred class inherit REQUEST_HANDLER [C] - redefine - execute - end feature -- Access @@ -327,7 +324,7 @@ feature -- Element change: request methods note - copyright: "Copyright (c) 1984-2011, Eiffel Software and others" + copyright: "Copyright (c) 1984-2012, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software diff --git a/draft/library/server/request/rest/src/rest_request_handler_context.e b/draft/library/server/request/rest/src/rest_request_handler_context.e index 8563fee5..395872e3 100644 --- a/draft/library/server/request/rest/src/rest_request_handler_context.e +++ b/draft/library/server/request/rest/src/rest_request_handler_context.e @@ -10,52 +10,8 @@ deferred class inherit REQUEST_HANDLER_CONTEXT -feature -- Status report - - script_absolute_url (a_path: STRING): STRING - -- Absolute Url for the script if any, extended by `a_path' - do - Result := request.absolute_script_url (a_path) - end - - script_url (a_path: STRING): STRING - -- Url relative to script name if any, extended by `a_path' - require - a_path_attached: a_path /= Void - do - Result := request.script_url (a_path) - end - - url (args: detachable STRING; abs: BOOLEAN): STRING - -- Associated url based on `path' and `args' - -- if `abs' then return absolute url - local - s,t: detachable STRING - do - s := args - if s /= Void and then s.count > 0 then - create t.make_from_string (path) - if s[1] /= '/' and t[t.count] /= '/' then - t.append_character ('/') - t.append (s) - else - t.append (s) - end - s := t - else - s := path - end - if abs then - Result := script_absolute_url (s) - else - Result := script_url (s) - end - ensure - result_attached: Result /= Void - end - note - copyright: "Copyright (c) 1984-2011, Eiffel Software and others" + copyright: "Copyright (c) 1984-2012, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software diff --git a/library/protocol/http/src/http_header.e b/library/protocol/http/src/http_header.e index 441eeb5a..871a74c2 100644 --- a/library/protocol/http/src/http_header.e +++ b/library/protocol/http/src/http_header.e @@ -282,7 +282,13 @@ feature -- Date put_utc_date (dt: DATE_TIME) -- Put UTC date time `dt' with "Date" header do - put_date (dt.formatted_out ("ddd,[0]dd mmm yyyy [0]hh:[0]mi:[0]ss.ff2") + " GMT") + put_date (date_to_rfc1123_http_date_format (dt)) + end + + put_last_modified (dt: DATE_TIME) + -- Put UTC date time `dt' with "Date" header + do + put_header_key_value ({HTTP_HEADER_NAMES}.header_last_modified, date_to_rfc1123_http_date_format (dt)) end feature -- Others @@ -352,6 +358,15 @@ feature -- Cookie add_header (s) end + put_cookie_with_expiration_date (key, value: READABLE_STRING_8; expiration: DATE_TIME; path, domain, secure: detachable READABLE_STRING_8) + -- Set a cookie on the client's machine + -- with key 'key' and value 'value'. + require + make_sense: (key /= Void and value /= Void) and then (not key.is_empty and not value.is_empty) + do + put_cookie (key, value, date_to_rfc1123_http_date_format (expiration), path, domain, secure) + end + feature -- Status report header_named_value (a_name: READABLE_STRING_8): detachable STRING_8 @@ -498,6 +513,12 @@ feature {NONE} -- Implementation h.append_character ('%N') end + date_to_rfc1123_http_date_format (dt: DATE_TIME): READABLE_STRING_8 + -- String representation of `dt' using the RFC 1123 + do + Result := dt.formatted_out ("ddd,[0]dd mmm yyyy [0]hh:[0]mi:[0]ss.ff2") + " GMT" + end + feature {NONE} -- Constants str_binary: STRING = "binary" @@ -507,7 +528,7 @@ feature {NONE} -- Constants semi_colon_space: STRING = "; " note - copyright: "2011-2011, Eiffel Software and others" + copyright: "2011-2012, 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/router/request_handler_context.e b/library/server/wsf/router/request_handler_context.e index 8c6fbbef..cf5f0b82 100644 --- a/library/server/wsf/router/request_handler_context.e +++ b/library/server/wsf/router/request_handler_context.e @@ -22,6 +22,50 @@ feature -- Access path: READABLE_STRING_8 -- Associated path +feature -- Url Query + + script_absolute_url (a_path: STRING): STRING + -- Absolute Url for the script if any, extended by `a_path' + do + Result := request.absolute_script_url (a_path) + end + + script_url (a_path: STRING): STRING + -- Url relative to script name if any, extended by `a_path' + require + a_path_attached: a_path /= Void + do + Result := request.script_url (a_path) + end + + url (args: detachable STRING; abs: BOOLEAN): STRING + -- Associated url based on `path' and `args' + -- if `abs' then return absolute url + local + s,t: detachable STRING + do + s := args + if s /= Void and then s.count > 0 then + create t.make_from_string (path) + if s[1] /= '/' and t[t.count] /= '/' then + t.append_character ('/') + t.append (s) + else + t.append (s) + end + s := t + else + s := path + end + if abs then + Result := script_absolute_url (s) + else + Result := script_url (s) + end + ensure + result_attached: Result /= Void + end + feature {NONE} -- Constants Format_constants: HTTP_FORMAT_CONSTANTS diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index b6063dc3..52cd4a75 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -3,10 +3,19 @@ note Server request context of the httpd request It includes CGI interface and a few extra values that are usually valuable + meta_variable (a_name: READABLE_STRING_8): detachable WSF_STRING + meta_string_variable (a_name: READABLE_STRING_8): detachable READABLE_STRING_32 + In addition it provides - query_parameter(s) - form_parameter(s) + + query_parameter (a_name: READABLE_STRING_32): detachable WSF_VALUE + form_parameter (a_name: READABLE_STRING_32): detachable WSF_VALUE + cookie (a_name: READABLE_STRING_8): detachable WSF_VALUE ... + + And also has + execution_variable (a_name: READABLE_STRING_32): detachable ANY + --| to keep value attached to the request ]" date: "$Date$" revision: "$Revision$" @@ -49,7 +58,6 @@ feature {NONE} -- Initialization create execution_variables_table.make (0) execution_variables_table.compare_objects - execution_variables := execution_variables_table initialize analyze @@ -226,19 +234,14 @@ feature -- Execution variables require a_name_valid: a_name /= Void and then not a_name.is_empty do - if attached execution_variables_table.item (a_name) as v then - Result := v.item - end + Result := execution_variables_table.item (a_name) end - execution_variables: ITERABLE [WSF_ANY] - -- Execution variables values - set_execution_variable (a_name: READABLE_STRING_32; a_value: detachable ANY) do - execution_variables_table.force (create {WSF_ANY}.make (a_name, a_value), a_name) + execution_variables_table.force (a_value, a_name) ensure - param_set: attached {WSF_ANY} execution_variable (a_name) as val and then val ~ a_value + param_set: execution_variable (a_name) = a_value end unset_execution_variable (a_name: READABLE_STRING_32) @@ -250,7 +253,7 @@ feature -- Execution variables feature {NONE} -- Execution variables: implementation - execution_variables_table: HASH_TABLE [WSF_ANY, READABLE_STRING_32] + execution_variables_table: HASH_TABLE [detachable ANY, READABLE_STRING_32] feature -- Access: CGI Meta variables @@ -1153,20 +1156,6 @@ feature {NONE} -- Form fields and related if l_raw_data_cell /= Void and then attached l_raw_data_cell.item as l_raw_data then set_meta_string_variable ("RAW_POST_DATA", l_raw_data) end - --- if --- l_type /= Void and then --- l_type.starts_with ({HTTP_MIME_TYPES}.multipart_form_data) --- then --- create vars.make (5) --- vars.compare_objects --- --| FIXME: optimization ... fetch the input data progressively, otherwise we might run out of memory ... --- s := form_input_data (n) --- analyze_multipart_form (l_type, s, vars) --- else --- s := form_input_data (n) --- vars := urlencoded_parameters (s) --- end end internal_form_data_parameters_table := vars end