added use of URL-encoder to unencode the URL values (to fill the parameters)

review design of GW_RESPONSE to hide the output, and remove the header attribute
added script_url in REQUEST to help the user build url relative to script_name

+ cosmetic
This commit is contained in:
Jocelyn Fiat
2011-07-20 18:27:02 +02:00
parent 51b70a2490
commit 0d363f065b
9 changed files with 203 additions and 204 deletions

View File

@@ -12,6 +12,7 @@
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/> <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="error" location="..\..\error\error.ecf"/> <library name="error" location="..\..\error\error.ecf"/>
<library name="http" location="..\..\protocol\http\http.ecf"/> <library name="http" location="..\..\protocol\http\http.ecf"/>
<library name="encoder" location="..\..\text\encoder\encoder-safe.ecf" readonly="false"/>
<library name="libfcgi" location="..\libfcgi\libfcgi.ecf"/> <library name="libfcgi" location="..\libfcgi\libfcgi.ecf"/>
<library name="nino" location="..\..\..\ext\server\nino\nino.ecf" readonly="false"> <library name="nino" location="..\..\..\ext\server\nino\nino.ecf" readonly="false">
<renaming old_name="HTTP_CONSTANTS" new_name="NINO_HTTP_CONSTANTS"/> <renaming old_name="HTTP_CONSTANTS" new_name="NINO_HTTP_CONSTANTS"/>

View File

@@ -13,6 +13,7 @@
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/> <library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="error" location="..\..\error\error-safe.ecf"/> <library name="error" location="..\..\error\error-safe.ecf"/>
<library name="http" location="..\..\protocol\http\http-safe.ecf"/> <library name="http" location="..\..\protocol\http\http-safe.ecf"/>
<library name="encoder" location="..\..\text\encoder\encoder-safe.ecf" readonly="false"/>
<cluster name="interface" location="src\" recursive="true"/> <cluster name="interface" location="src\" recursive="true"/>
</target> </target>
</system> </system>

View File

@@ -13,6 +13,7 @@
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/> <library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="error" location="..\..\error\error-safe.ecf"/> <library name="error" location="..\..\error\error-safe.ecf"/>
<library name="http" location="..\..\protocol\http\http.ecf"/> <library name="http" location="..\..\protocol\http\http.ecf"/>
<library name="encoder" location="..\..\text\encoder\encoder-safe.ecf" readonly="false"/>
<cluster name="interface" location="src\" recursive="true" /> <cluster name="interface" location="src\" recursive="true" />
</target> </target>
</system> </system>

View File

@@ -20,8 +20,8 @@ feature {NONE} -- Initialization
execute (req: GW_REQUEST; res: GW_RESPONSE) execute (req: GW_REQUEST; res: GW_RESPONSE)
do do
res.output.put_header (200, <<["Content-Type", "text/plain"]>>) res.write_header (200, <<["Content-Type", "text/plain"]>>)
res.output.put_string ("Hello World!%N") res.write_string ("Hello World!%N")
end end
port_number: INTEGER = 8123 port_number: INTEGER = 8123

View File

@@ -15,101 +15,14 @@ note
deferred class deferred class
GW_REQUEST GW_REQUEST
feature -- Access: Input/Output feature -- Access: Input
input: GW_INPUT_STREAM input: GW_INPUT_STREAM
-- Server input channel -- Server input channel
deferred deferred
end end
feature -- Access: global variable feature -- Access: extra values
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
request_time: detachable DATE_TIME request_time: detachable DATE_TIME
-- Request time (UTC) -- Request time (UTC)
@@ -201,6 +114,93 @@ feature -- Cookies
deferred deferred
end 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 feature -- Uploaded File Handling
move_uploaded_file (a_filename: STRING; a_destination: STRING): BOOLEAN move_uploaded_file (a_filename: STRING; a_destination: STRING): BOOLEAN
@@ -226,6 +226,70 @@ feature {NONE} -- Temporary File handling
deferred deferred
end 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 note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -68,40 +68,39 @@ feature -- Import urlencoded
import_urlencoded (a_content: STRING; decoding: BOOLEAN) import_urlencoded (a_content: STRING; decoding: BOOLEAN)
-- Import `a_content' -- Import `a_content'
local local
-- n, p, i, j: INTEGER n, p, i, j: INTEGER
-- s: STRING s: STRING
-- l_name,l_value: STRING_32 l_name,l_value: STRING_32
do do
-- FIXME n := a_content.count
-- n := a_content.count if n > 0 then
-- if n > 0 then from
-- from p := 1
-- p := 1 until
-- until p = 0
-- p = 0 loop
-- loop i := a_content.index_of ('&', p)
-- i := a_content.index_of ('&', p) if i = 0 then
-- if i = 0 then s := a_content.substring (p, n)
-- s := a_content.substring (p, n) p := 0
-- p := 0 else
-- else s := a_content.substring (p, i - 1)
-- s := a_content.substring (p, i - 1) p := i + 1
-- p := i + 1 end
-- end if not s.is_empty then
-- if not s.is_empty then j := s.index_of ('=', 1)
-- j := s.index_of ('=', 1) if j > 0 then
-- if j > 0 then l_name := s.substring (1, j - 1)
-- l_name := s.substring (1, j - 1) l_value := s.substring (j + 1, s.count)
-- l_value := s.substring (j + 1, s.count) if decoding then
-- if decoding then l_name := url_encoder.decoded_string (l_name)
-- l_name := url_encoder.decoded_string (l_name) l_value := url_encoder.decoded_string (l_value)
-- l_value := url_encoder.decoded_string (l_value) end
-- end add_variable (l_value, l_name)
-- add_variable (l_value, l_name) end
-- end end
-- end end
-- end end
-- end
end end
feature -- Access: table feature -- Access: table
@@ -132,10 +131,10 @@ feature {GW_REQUEST} -- Element change
feature {NONE} -- Implementation feature {NONE} -- Implementation
-- url_encoder: URL_ENCODER url_encoder: URL_ENCODER
-- once once
-- create Result create Result
-- end end
note note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"

View File

@@ -261,65 +261,7 @@ feature -- Cookies
Result := l_cookies Result := l_cookies
end end
feature -- Query feature -- Access extra information
-- 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
request_time: detachable DATE_TIME request_time: detachable DATE_TIME
-- Request time (UTC) -- Request time (UTC)

View File

@@ -7,17 +7,19 @@ note
deferred class deferred class
GW_RESPONSE GW_RESPONSE
feature -- Access: Output feature {NONE} -- Implementation: Output
output: GW_OUTPUT_STREAM output: GW_OUTPUT_STREAM
-- Server output channel -- Server output channel
deferred deferred
end end
send_header feature -- Output header
write_header_object (h: GW_HEADER)
-- Send `header' to `output'. -- Send `header' to `output'.
do do
header.send_to (output) h.send_to (output)
end end
feature -- Output operation feature -- Output operation
@@ -39,7 +41,7 @@ feature -- Output operation
h: GW_HEADER h: GW_HEADER
i,n: INTEGER i,n: INTEGER
do do
h := header create h.make
h.put_status (a_status) h.put_status (a_status)
if a_headers /= Void then if a_headers /= Void then
from from
@@ -52,7 +54,7 @@ feature -- Output operation
i := i + 1 i := i + 1
end end
end end
send_header write_header_object (h)
end end
write_header_line (s: STRING) write_header_line (s: STRING)
@@ -62,13 +64,6 @@ feature -- Output operation
write_string ("%R%N") write_string ("%R%N")
end end
feature -- Header
header: GW_HEADER
-- Header for the response
deferred
end
note note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -18,17 +18,13 @@ feature {NONE} -- Initialization
make (a_output: like output) make (a_output: like output)
do do
output := a_output output := a_output
create header.make
end end
feature -- Access: Input/Output feature {NONE} -- Implementation: Access
output: GW_OUTPUT_STREAM output: GW_OUTPUT_STREAM
-- Server output channel -- Server output channel
header: GW_HEADER
-- Header for the response
;note ;note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"