removed implementation from APPLICATION , RESPONSE and REQUEST classes
This commit is contained in:
@@ -20,7 +20,7 @@ feature -- Process request
|
|||||||
if not rescued then
|
if not rescued then
|
||||||
pre_execute (env)
|
pre_execute (env)
|
||||||
req := new_request (env, a_input)
|
req := new_request (env, a_input)
|
||||||
res := new_response (a_output)
|
res := new_response (req, a_output)
|
||||||
execute (req, res)
|
execute (req, res)
|
||||||
post_execute (req, res)
|
post_execute (req, res)
|
||||||
else
|
else
|
||||||
@@ -56,13 +56,6 @@ feature {NONE} -- Execution
|
|||||||
rescue_execute (req: detachable GW_REQUEST; res: detachable GW_RESPONSE; a_exception: detachable EXCEPTION)
|
rescue_execute (req: detachable GW_REQUEST; res: detachable GW_RESPONSE; a_exception: detachable EXCEPTION)
|
||||||
-- Operation processed on rescue of `execute'
|
-- Operation processed on rescue of `execute'
|
||||||
do
|
do
|
||||||
if
|
|
||||||
req /= Void and res /= Void
|
|
||||||
and a_exception /= Void and then attached a_exception.exception_trace as l_trace
|
|
||||||
then
|
|
||||||
res.write_header ({HTTP_STATUS_CODE}.internal_server_error, Void)
|
|
||||||
res.write_string ("<pre>" + l_trace + "</pre>")
|
|
||||||
end
|
|
||||||
post_execute (req, res)
|
post_execute (req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -76,8 +69,8 @@ feature -- Factory
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
new_response (a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
||||||
-- New Response based on `a_output'
|
-- New Response based on `req' and `a_output'
|
||||||
--| note: you can redefine this function to create your own
|
--| note: you can redefine this function to create your own
|
||||||
--| descendant of GW_RESPONSE , or even to reuse/recycle existing
|
--| descendant of GW_RESPONSE , or even to reuse/recycle existing
|
||||||
--| instance of GW_RESPONSE
|
--| instance of GW_RESPONSE
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ deferred class
|
|||||||
inherit
|
inherit
|
||||||
GW_APPLICATION
|
GW_APPLICATION
|
||||||
redefine
|
redefine
|
||||||
process
|
process,
|
||||||
|
rescue_execute
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -28,6 +29,19 @@ feature -- Execution
|
|||||||
Precursor (env, a_input, a_output)
|
Precursor (env, a_input, a_output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue_execute (req: detachable GW_REQUEST; res: detachable GW_RESPONSE; a_exception: detachable EXCEPTION)
|
||||||
|
-- Operation processed on rescue of `execute'
|
||||||
|
do
|
||||||
|
if
|
||||||
|
req /= Void and res /= Void
|
||||||
|
and a_exception /= Void and then attached a_exception.exception_trace as l_trace
|
||||||
|
then
|
||||||
|
res.write_header ({HTTP_STATUS_CODE}.internal_server_error, Void)
|
||||||
|
res.write_string ("<pre>" + l_trace + "</pre>")
|
||||||
|
end
|
||||||
|
Precursor (req, res, a_exception)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Factory
|
feature -- Factory
|
||||||
|
|
||||||
new_request (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST
|
new_request (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST
|
||||||
@@ -36,7 +50,7 @@ feature -- Factory
|
|||||||
Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT")
|
Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT")
|
||||||
end
|
end
|
||||||
|
|
||||||
new_response (a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
||||||
do
|
do
|
||||||
create {GW_RESPONSE_IMP} Result.make (a_output)
|
create {GW_RESPONSE_IMP} Result.make (a_output)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,15 +28,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
body: STRING_8
|
body: STRING_8
|
||||||
|
|
||||||
feature -- Status setting
|
feature {NONE} -- Status output
|
||||||
|
|
||||||
set_status_code (c: INTEGER)
|
|
||||||
-- Set the status code of the response
|
|
||||||
do
|
|
||||||
header.put_status (c)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Output operation
|
|
||||||
|
|
||||||
write (s: STRING)
|
write (s: STRING)
|
||||||
-- Send the content of `s'
|
-- Send the content of `s'
|
||||||
@@ -44,6 +36,8 @@ feature -- Output operation
|
|||||||
body.append (s)
|
body.append (s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Output operation
|
||||||
|
|
||||||
write_file_content (fn: STRING)
|
write_file_content (fn: STRING)
|
||||||
-- Send the content of file `fn'
|
-- Send the content of file `fn'
|
||||||
local
|
local
|
||||||
@@ -73,6 +67,7 @@ feature {GW_APPLICATION} -- Commit
|
|||||||
|
|
||||||
commit (a_output: GW_OUTPUT_STREAM)
|
commit (a_output: GW_OUTPUT_STREAM)
|
||||||
do
|
do
|
||||||
|
a_output.put_status (status_code)
|
||||||
header.send_to (a_output)
|
header.send_to (a_output)
|
||||||
write (body)
|
write (body)
|
||||||
Precursor (a_output)
|
Precursor (a_output)
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ feature {GW_APPLICATION} -- Commit
|
|||||||
|
|
||||||
commit (a_output_stream: GW_OUTPUT_STREAM)
|
commit (a_output_stream: GW_OUTPUT_STREAM)
|
||||||
-- Commit the current response
|
-- Commit the current response
|
||||||
do
|
deferred
|
||||||
--| To be redefined as needed, to flush, or what you need...
|
ensure
|
||||||
a_output_stream.flush
|
status_set: is_status_set
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Core output operation
|
feature {NONE} -- Core output operation
|
||||||
@@ -27,8 +27,8 @@ feature {NONE} -- Core output operation
|
|||||||
feature -- Status setting
|
feature -- Status setting
|
||||||
|
|
||||||
is_status_set: BOOLEAN
|
is_status_set: BOOLEAN
|
||||||
do
|
-- Is status set?
|
||||||
Result := status_code /= 0
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
set_status_code (a_code: INTEGER)
|
set_status_code (a_code: INTEGER)
|
||||||
@@ -36,23 +36,15 @@ feature -- Status setting
|
|||||||
-- Should be done before sending any data back to the client
|
-- Should be done before sending any data back to the client
|
||||||
require
|
require
|
||||||
status_not_set: not is_status_set
|
status_not_set: not is_status_set
|
||||||
do
|
deferred
|
||||||
status_code := a_code
|
|
||||||
write_status (a_code)
|
|
||||||
ensure
|
ensure
|
||||||
|
status_code_set: status_code = a_code
|
||||||
status_set: is_status_set
|
status_set: is_status_set
|
||||||
end
|
end
|
||||||
|
|
||||||
status_code: INTEGER
|
status_code: INTEGER
|
||||||
-- Response status
|
-- Response status
|
||||||
|
|
||||||
feature {NONE} -- Status output
|
|
||||||
|
|
||||||
write_status (a_code: INTEGER)
|
|
||||||
-- Send status line for `a_code'
|
|
||||||
deferred
|
deferred
|
||||||
ensure
|
|
||||||
status_set: is_status_set
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Output operation
|
feature -- Output operation
|
||||||
@@ -61,8 +53,7 @@ feature -- Output operation
|
|||||||
-- Send the string `s'
|
-- Send the string `s'
|
||||||
require
|
require
|
||||||
status_set: is_status_set
|
status_set: is_status_set
|
||||||
do
|
deferred
|
||||||
write (s)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
write_file_content (fn: STRING)
|
write_file_content (fn: STRING)
|
||||||
@@ -74,35 +65,11 @@ feature -- Output operation
|
|||||||
|
|
||||||
feature -- Header output operation
|
feature -- Header output operation
|
||||||
|
|
||||||
write_header_object (h: GW_HEADER)
|
|
||||||
-- Send `header' to `output'.
|
|
||||||
require
|
|
||||||
status_set: is_status_set
|
|
||||||
deferred
|
|
||||||
end
|
|
||||||
|
|
||||||
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
|
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
|
||||||
-- Send headers with status `a_status', and headers from `a_headers'
|
-- Send headers with status `a_status', and headers from `a_headers'
|
||||||
require
|
require
|
||||||
status_not_set: not is_status_set
|
status_not_set: not is_status_set
|
||||||
local
|
deferred
|
||||||
h: GW_HEADER
|
|
||||||
i,n: INTEGER
|
|
||||||
do
|
|
||||||
set_status_code (a_status_code)
|
|
||||||
create h.make
|
|
||||||
if a_headers /= Void then
|
|
||||||
from
|
|
||||||
i := a_headers.lower
|
|
||||||
n := a_headers.upper
|
|
||||||
until
|
|
||||||
i > n
|
|
||||||
loop
|
|
||||||
h.put_header_key_value (a_headers[i].key, a_headers[i].value)
|
|
||||||
i := i + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
write_header_object (h)
|
|
||||||
ensure
|
ensure
|
||||||
status_set: is_status_set
|
status_set: is_status_set
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ feature {NONE} -- Initialization
|
|||||||
output := a_output
|
output := a_output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {GW_APPLICATION} -- Commit
|
||||||
|
|
||||||
|
commit (a_output_stream: GW_OUTPUT_STREAM)
|
||||||
|
-- Commit the current response
|
||||||
|
do
|
||||||
|
a_output_stream.flush
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Core output operation
|
feature {NONE} -- Core output operation
|
||||||
|
|
||||||
write (s: STRING)
|
write (s: STRING)
|
||||||
@@ -28,28 +36,70 @@ feature {NONE} -- Core output operation
|
|||||||
output.put_string (s)
|
output.put_string (s)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Status output
|
feature -- Status setting
|
||||||
|
|
||||||
write_status (a_code: INTEGER)
|
is_status_set: BOOLEAN
|
||||||
-- Send status line for `a_code'
|
|
||||||
do
|
do
|
||||||
|
Result := status_code /= 0
|
||||||
|
end
|
||||||
|
|
||||||
|
set_status_code (a_code: INTEGER)
|
||||||
|
-- Set response status code
|
||||||
|
-- Should be done before sending any data back to the client
|
||||||
|
do
|
||||||
|
status_code := a_code
|
||||||
output.put_status_line (a_code)
|
output.put_status_line (a_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
status_code: INTEGER
|
||||||
|
-- Response status
|
||||||
|
|
||||||
feature -- Output operation
|
feature -- Output operation
|
||||||
|
|
||||||
|
write_string (s: STRING)
|
||||||
|
-- Send the string `s'
|
||||||
|
do
|
||||||
|
write (s)
|
||||||
|
end
|
||||||
|
|
||||||
write_file_content (fn: STRING)
|
write_file_content (fn: STRING)
|
||||||
-- Send the content of file `fn'
|
-- Send the content of file `fn'
|
||||||
do
|
do
|
||||||
output.put_file_content (fn)
|
output.put_file_content (fn)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Header output operation
|
||||||
|
|
||||||
write_header_object (h: GW_HEADER)
|
write_header_object (h: GW_HEADER)
|
||||||
-- Send `header' to `output'.
|
-- Send `header' to `output'.
|
||||||
|
require
|
||||||
|
status_set: is_status_set
|
||||||
do
|
do
|
||||||
h.send_to (Current)
|
h.send_to (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]])
|
||||||
|
-- Send headers with status `a_status', and headers from `a_headers'
|
||||||
|
local
|
||||||
|
h: GW_HEADER
|
||||||
|
i,n: INTEGER
|
||||||
|
do
|
||||||
|
set_status_code (a_status_code)
|
||||||
|
create h.make
|
||||||
|
if a_headers /= Void then
|
||||||
|
from
|
||||||
|
i := a_headers.lower
|
||||||
|
n := a_headers.upper
|
||||||
|
until
|
||||||
|
i > n
|
||||||
|
loop
|
||||||
|
h.put_header_key_value (a_headers[i].key, a_headers[i].value)
|
||||||
|
i := i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
write_header_object (h)
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation: Access
|
feature {NONE} -- Implementation: Access
|
||||||
|
|
||||||
output: GW_OUTPUT_STREAM
|
output: GW_OUTPUT_STREAM
|
||||||
|
|||||||
Reference in New Issue
Block a user