diff --git a/library/server/ewsgi/ewsgi-full.ecf b/library/server/ewsgi/ewsgi-full.ecf index e27b6aaa..72ab05f3 100644 --- a/library/server/ewsgi/ewsgi-full.ecf +++ b/library/server/ewsgi/ewsgi-full.ecf @@ -12,6 +12,7 @@ + diff --git a/library/server/ewsgi/ewsgi-safe.ecf b/library/server/ewsgi/ewsgi-safe.ecf index 578a1c68..c8014c95 100644 --- a/library/server/ewsgi/ewsgi-safe.ecf +++ b/library/server/ewsgi/ewsgi-safe.ecf @@ -13,6 +13,7 @@ + diff --git a/library/server/ewsgi/ewsgi.ecf b/library/server/ewsgi/ewsgi.ecf index ca19856a..e918096a 100644 --- a/library/server/ewsgi/ewsgi.ecf +++ b/library/server/ewsgi/ewsgi.ecf @@ -13,6 +13,7 @@ + diff --git a/library/server/ewsgi/examples/hello_world/src/hello_world.e b/library/server/ewsgi/examples/hello_world/src/hello_world.e index c8840b15..591a1075 100644 --- a/library/server/ewsgi/examples/hello_world/src/hello_world.e +++ b/library/server/ewsgi/examples/hello_world/src/hello_world.e @@ -20,8 +20,8 @@ feature {NONE} -- Initialization execute (req: GW_REQUEST; res: GW_RESPONSE) do - res.output.put_header (200, <<["Content-Type", "text/plain"]>>) - res.output.put_string ("Hello World!%N") + res.write_header (200, <<["Content-Type", "text/plain"]>>) + res.write_string ("Hello World!%N") end port_number: INTEGER = 8123 diff --git a/library/server/ewsgi/src/context/gw_request.e b/library/server/ewsgi/src/context/gw_request.e index 28d4ffdc..f230da42 100644 --- a/library/server/ewsgi/src/context/gw_request.e +++ b/library/server/ewsgi/src/context/gw_request.e @@ -15,101 +15,14 @@ note deferred class GW_REQUEST -feature -- Access: Input/Output +feature -- Access: Input input: GW_INPUT_STREAM -- Server input channel deferred end -feature -- Access: global variable - - variables: HASH_TABLE [STRING_32, STRING_32] - -- Table containing all the various variables - -- Warning: this is computed each time, if you change the content of other containers - -- this won't update this Result's content, unless you query it again - local - vars: HASH_TABLE [STRING_GENERAL, STRING_GENERAL] - do - create Result.make (100) - - vars := execution_variables - from - vars.start - until - vars.after - loop - Result.put (vars.item_for_iteration, vars.key_for_iteration) - vars.forth - end - - vars := environment.table - from - vars.start - until - vars.after - loop - Result.put (vars.item_for_iteration, vars.key_for_iteration) - vars.forth - end - - vars := parameters.table - from - vars.start - until - vars.after - loop - Result.put (vars.item_for_iteration, vars.key_for_iteration) - vars.forth - end - - vars := form_fields.table - from - vars.start - until - vars.after - loop - Result.put (vars.item_for_iteration, vars.key_for_iteration) - vars.forth - end - - vars := cookies_variables - from - vars.start - until - vars.after - loop - Result.put (vars.item_for_iteration, vars.key_for_iteration) - vars.forth - end - end - - variable (n8: STRING_8): detachable STRING_32 - -- Variable named `n' from any of the variables container - -- and following a specific order - -- execution, environment, get, post, cookies - local - s: detachable STRING_GENERAL - do - s := execution_variable (n8) - if s = Void then - s := environment_variable (n8) - if s = Void then - s := parameter (n8) - if s = Void then - s := form_field (n8) - if s = Void then - s := cookies_variable (n8) - end - end - end - end - if s /= Void then - Result := s.as_string_32 - end - end - -feature -- Access: environment extra values +feature -- Access: extra values request_time: detachable DATE_TIME -- Request time (UTC) @@ -201,6 +114,93 @@ feature -- Cookies deferred end +feature -- Access: global variable + + variables: HASH_TABLE [STRING_32, STRING_32] + -- Table containing all the various variables + -- Warning: this is computed each time, if you change the content of other containers + -- this won't update this Result's content, unless you query it again + local + vars: HASH_TABLE [STRING_GENERAL, STRING_GENERAL] + do + create Result.make (100) + + vars := execution_variables + from + vars.start + until + vars.after + loop + Result.put (vars.item_for_iteration, vars.key_for_iteration) + vars.forth + end + + vars := environment.table + from + vars.start + until + vars.after + loop + Result.put (vars.item_for_iteration, vars.key_for_iteration) + vars.forth + end + + vars := parameters.table + from + vars.start + until + vars.after + loop + Result.put (vars.item_for_iteration, vars.key_for_iteration) + vars.forth + end + + vars := form_fields.table + from + vars.start + until + vars.after + loop + Result.put (vars.item_for_iteration, vars.key_for_iteration) + vars.forth + end + + vars := cookies_variables + from + vars.start + until + vars.after + loop + Result.put (vars.item_for_iteration, vars.key_for_iteration) + vars.forth + end + end + + variable (n8: STRING_8): detachable STRING_32 + -- Variable named `n' from any of the variables container + -- and following a specific order + -- execution, environment, get, post, cookies + local + s: detachable STRING_GENERAL + do + s := execution_variable (n8) + if s = Void then + s := environment_variable (n8) + if s = Void then + s := parameter (n8) + if s = Void then + s := form_field (n8) + if s = Void then + s := cookies_variable (n8) + end + end + end + end + if s /= Void then + Result := s.as_string_32 + end + end + feature -- Uploaded File Handling move_uploaded_file (a_filename: STRING; a_destination: STRING): BOOLEAN @@ -226,6 +226,70 @@ feature {NONE} -- Temporary File handling deferred end +feature -- URL Utility + + absolute_script_url (a_path: STRING): STRING + -- Absolute Url for the script if any, extended by `a_path' + do + Result := script_url (a_path) + if attached environment.http_host as h then + Result.prepend (h) + else + --| Issue ?? + end + 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 + local + l_base_url: like internal_url_base + i,m,n: INTEGER + l_rq_uri: like environment.request_uri + env: like environment + do + l_base_url := internal_url_base + if l_base_url = Void then + env := environment + if attached env.script_name as l_script_name then + l_rq_uri := env.request_uri + if l_rq_uri.starts_with (l_script_name) then + l_base_url := l_script_name + else + --| Handle Rewrite url engine, to have clean path + from + i := 1 + m := l_rq_uri.count + n := l_script_name.count + until + i > m or i > n or l_rq_uri[i] /= l_script_name[i] + loop + i := i + 1 + end + if i > 1 then + if l_rq_uri[i-1] = '/' then + i := i -1 + end + l_base_url := l_rq_uri.substring (1, i - 1) + end + end + end + if l_base_url = Void then + create l_base_url.make_empty + end + internal_url_base := l_base_url + end + Result := l_base_url + a_path + end + +feature {NONE} -- Implementation: URL Utility + + internal_url_base: detachable STRING + -- URL base of potential script + +invariant + note copyright: "2011-2011, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/server/ewsgi/src/context/gw_request_variables.e b/library/server/ewsgi/src/context/gw_request_variables.e index f820de3b..b050af81 100644 --- a/library/server/ewsgi/src/context/gw_request_variables.e +++ b/library/server/ewsgi/src/context/gw_request_variables.e @@ -68,40 +68,39 @@ feature -- Import urlencoded import_urlencoded (a_content: STRING; decoding: BOOLEAN) -- Import `a_content' local --- n, p, i, j: INTEGER --- s: STRING --- l_name,l_value: STRING_32 + n, p, i, j: INTEGER + s: STRING + l_name,l_value: STRING_32 do --- FIXME --- n := a_content.count --- if n > 0 then --- from --- p := 1 --- until --- p = 0 --- loop --- i := a_content.index_of ('&', p) --- if i = 0 then --- s := a_content.substring (p, n) --- p := 0 --- else --- s := a_content.substring (p, i - 1) --- p := i + 1 --- end --- if not s.is_empty then --- j := s.index_of ('=', 1) --- if j > 0 then --- l_name := s.substring (1, j - 1) --- l_value := s.substring (j + 1, s.count) --- if decoding then --- l_name := url_encoder.decoded_string (l_name) --- l_value := url_encoder.decoded_string (l_value) --- end --- add_variable (l_value, l_name) --- end --- end --- end --- end + n := a_content.count + if n > 0 then + from + p := 1 + until + p = 0 + loop + i := a_content.index_of ('&', p) + if i = 0 then + s := a_content.substring (p, n) + p := 0 + else + s := a_content.substring (p, i - 1) + p := i + 1 + end + if not s.is_empty then + j := s.index_of ('=', 1) + if j > 0 then + l_name := s.substring (1, j - 1) + l_value := s.substring (j + 1, s.count) + if decoding then + l_name := url_encoder.decoded_string (l_name) + l_value := url_encoder.decoded_string (l_value) + end + add_variable (l_value, l_name) + end + end + end + end end feature -- Access: table @@ -132,10 +131,10 @@ feature {GW_REQUEST} -- Element change feature {NONE} -- Implementation --- url_encoder: URL_ENCODER --- once --- create Result --- end + url_encoder: URL_ENCODER + once + create Result + end note copyright: "2011-2011, Eiffel Software and others" diff --git a/library/server/ewsgi/src/implementation/gw_request_imp.e b/library/server/ewsgi/src/implementation/gw_request_imp.e index 90116110..ba136f44 100644 --- a/library/server/ewsgi/src/implementation/gw_request_imp.e +++ b/library/server/ewsgi/src/implementation/gw_request_imp.e @@ -261,65 +261,7 @@ feature -- Cookies Result := l_cookies end -feature -- Query - --- script_absolute_url (a_path: STRING): STRING --- -- Absolute Url for the script if any, extended by `a_path' --- do --- Result := script_url (a_path) --- if attached http_host as h then --- Result.prepend (h) --- else --- --| Issue ?? --- end --- 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 --- local --- l_base_url: like script_url_base --- i,m,n: INTEGER --- l_rq_uri: like request_uri --- do --- l_base_url := script_url_base --- if l_base_url = Void then --- if attached environment.script_name as l_script_name then --- l_rq_uri := request_uri --- if l_rq_uri.starts_with (l_script_name) then --- l_base_url := l_script_name --- else --- --| Handle Rewrite url engine, to have clean path --- from --- i := 1 --- m := l_rq_uri.count --- n := l_script_name.count --- until --- i > m or i > n or l_rq_uri[i] /= l_script_name[i] --- loop --- i := i + 1 --- end --- if i > 1 then --- if l_rq_uri[i-1] = '/' then --- i := i -1 --- end --- l_base_url := l_rq_uri.substring (1, i - 1) --- end --- end --- end --- if l_base_url = Void then --- create l_base_url.make_empty --- end --- script_url_base := l_base_url --- end --- Result := l_base_url + a_path --- end - --- script_url_base: detachable STRING --- -- URL base of potential script - -feature -- Access environment information +feature -- Access extra information request_time: detachable DATE_TIME -- Request time (UTC) diff --git a/library/server/ewsgi/src/response/gw_response.e b/library/server/ewsgi/src/response/gw_response.e index a14ab246..5cdec3f0 100644 --- a/library/server/ewsgi/src/response/gw_response.e +++ b/library/server/ewsgi/src/response/gw_response.e @@ -7,17 +7,19 @@ note deferred class GW_RESPONSE -feature -- Access: Output +feature {NONE} -- Implementation: Output output: GW_OUTPUT_STREAM -- Server output channel deferred end - send_header +feature -- Output header + + write_header_object (h: GW_HEADER) -- Send `header' to `output'. do - header.send_to (output) + h.send_to (output) end feature -- Output operation @@ -39,7 +41,7 @@ feature -- Output operation h: GW_HEADER i,n: INTEGER do - h := header + create h.make h.put_status (a_status) if a_headers /= Void then from @@ -52,7 +54,7 @@ feature -- Output operation i := i + 1 end end - send_header + write_header_object (h) end write_header_line (s: STRING) @@ -62,13 +64,6 @@ feature -- Output operation write_string ("%R%N") end -feature -- Header - - header: GW_HEADER - -- Header for the response - deferred - end - note copyright: "2011-2011, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/server/ewsgi/src/response/gw_response_imp.e b/library/server/ewsgi/src/response/gw_response_imp.e index 0dcebf84..d91c12b7 100644 --- a/library/server/ewsgi/src/response/gw_response_imp.e +++ b/library/server/ewsgi/src/response/gw_response_imp.e @@ -18,17 +18,13 @@ feature {NONE} -- Initialization make (a_output: like output) do output := a_output - create header.make end -feature -- Access: Input/Output +feature {NONE} -- Implementation: Access output: GW_OUTPUT_STREAM -- Server output channel - header: GW_HEADER - -- Header for the response - ;note copyright: "2011-2011, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"