Design change, now we have req' REQUEST and res' RESPONSE instead of just `ctx'
This commit is contained in:
@@ -15,10 +15,10 @@ feature {NONE} -- Initialization
|
|||||||
make
|
make
|
||||||
do
|
do
|
||||||
print ("Example: start a Nino web server on port " + port_number.out + ", %Nand reply Hello World for any request such as http://localhost:8123/%N")
|
print ("Example: start a Nino web server on port " + port_number.out + ", %Nand reply Hello World for any request such as http://localhost:8123/%N")
|
||||||
(create {GW_NINO_APPLICATION}.make (agent (ctx: GW_REQUEST_CONTEXT)
|
(create {GW_NINO_APPLICATION}.make (agent (req: GW_REQUEST_CONTEXT; res: GW_RESPONSE)
|
||||||
do
|
do
|
||||||
ctx.output.put_header (200, <<["Content-Type", "text/plain"]>>)
|
res.output.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||||
ctx.output.put_string ("Hello World!%N")
|
res.output.put_string ("Hello World!%N")
|
||||||
end
|
end
|
||||||
)).listen (port_number)
|
)).listen (port_number)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,11 +22,6 @@ feature -- Access: Input/Output
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
output: GW_OUTPUT_STREAM
|
|
||||||
-- Server output channel
|
|
||||||
deferred
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access: global variable
|
feature -- Access: global variable
|
||||||
|
|
||||||
variables: HASH_TABLE [STRING_32, STRING_32]
|
variables: HASH_TABLE [STRING_32, STRING_32]
|
||||||
|
|||||||
@@ -14,24 +14,26 @@ feature -- Process request
|
|||||||
-- Process request with environment `env', and i/o streams `a_input' and `a_output'
|
-- Process request with environment `env', and i/o streams `a_input' and `a_output'
|
||||||
local
|
local
|
||||||
rescued: BOOLEAN
|
rescued: BOOLEAN
|
||||||
ctx: detachable GW_REQUEST_CONTEXT
|
req: detachable like new_request_context
|
||||||
|
res: detachable like new_response
|
||||||
do
|
do
|
||||||
if not rescued then
|
if not rescued then
|
||||||
pre_execute (env)
|
pre_execute (env)
|
||||||
ctx := new_request_context (env, a_input, a_output)
|
req := new_request_context (env, a_input)
|
||||||
execute (ctx)
|
res := new_response (a_output)
|
||||||
post_execute (ctx)
|
execute (req, res)
|
||||||
|
post_execute (req, res)
|
||||||
else
|
else
|
||||||
rescue_execute (ctx, (create {EXCEPTION_MANAGER}).last_exception)
|
rescue_execute (req, res, (create {EXCEPTION_MANAGER}).last_exception)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Execution
|
feature {NONE} -- Execution
|
||||||
|
|
||||||
execute (ctx: GW_REQUEST_CONTEXT)
|
execute (req: GW_REQUEST_CONTEXT; res: GW_RESPONSE)
|
||||||
-- Execute the request
|
-- Execute the request
|
||||||
-- See `ctx.input' and `ctx.output' for i/o streams
|
-- See `req.input' and `res.output' for i/o streams
|
||||||
-- `ctx.environment' for the Gateway environment
|
-- `req.environment' for the Gateway environment
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,27 +44,35 @@ feature {NONE} -- Execution
|
|||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
post_execute (ctx: detachable GW_REQUEST_CONTEXT)
|
post_execute (req: detachable GW_REQUEST_CONTEXT; res: detachable GW_RESPONSE)
|
||||||
-- Operation processed after `execute', or after `rescue_execute'
|
-- Operation processed after `execute', or after `rescue_execute'
|
||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_execute (ctx: detachable GW_REQUEST_CONTEXT; a_exception: detachable EXCEPTION)
|
rescue_execute (req: detachable GW_REQUEST_CONTEXT; res: detachable GW_RESPONSE; a_exception: detachable EXCEPTION)
|
||||||
-- Operation processed on rescue of `execute'
|
-- Operation processed on rescue of `execute'
|
||||||
do
|
do
|
||||||
post_execute (ctx)
|
post_execute (req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Factory
|
feature -- Factory
|
||||||
|
|
||||||
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM): GW_REQUEST_CONTEXT
|
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST_CONTEXT
|
||||||
-- New Gateway Context based on `env' `a_input' and `a_output'
|
-- New Request context based on `env' and `a_input'
|
||||||
--| note: you can redefine this function to create your own
|
--| note: you can redefine this function to create your own
|
||||||
--| descendant of GW_REQUEST_CONTEXT , or even to reuse/recycle existing
|
--| descendant of GW_REQUEST_CONTEXT , or even to reuse/recycle existing
|
||||||
--| instance of GW_REQUEST_CONTEXT
|
--| instance of GW_REQUEST_CONTEXT
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
new_response (a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
||||||
|
-- New Response based on `a_output'
|
||||||
|
--| note: you can redefine this function to create your own
|
||||||
|
--| descendant of GW_RESPONSE , or even to reuse/recycle existing
|
||||||
|
--| instance of GW_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)"
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ feature {NONE} -- Implementation
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
callback: PROCEDURE [ANY, TUPLE [like new_request_context]]
|
callback: PROCEDURE [ANY, TUPLE [req: like new_request_context; res: like new_response]]
|
||||||
-- Procedure called on `execute'
|
-- Procedure called on `execute'
|
||||||
|
|
||||||
execute (ctx: like new_request_context)
|
execute (req: like new_request_context; res: like new_response)
|
||||||
-- Execute the request
|
-- Execute the request
|
||||||
do
|
do
|
||||||
callback.call ([ctx])
|
callback.call ([req, res])
|
||||||
end
|
end
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
|
|||||||
@@ -30,12 +30,17 @@ feature -- Execution
|
|||||||
|
|
||||||
feature -- Factory
|
feature -- Factory
|
||||||
|
|
||||||
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM): GW_REQUEST_CONTEXT
|
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST_CONTEXT
|
||||||
do
|
do
|
||||||
create {GW_REQUEST_CONTEXT_IMP} Result.make (env, a_input, a_output)
|
create {GW_REQUEST_CONTEXT_IMP} Result.make (env, a_input)
|
||||||
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
|
||||||
|
do
|
||||||
|
create {GW_RESPONSE_IMP} Result.make (a_output)
|
||||||
|
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)"
|
||||||
|
|||||||
@@ -23,13 +23,12 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (env: GW_ENVIRONMENT; a_input: like input; a_output: like output)
|
make (env: GW_ENVIRONMENT; a_input: like input)
|
||||||
require
|
require
|
||||||
env_attached: env /= Void
|
env_attached: env /= Void
|
||||||
do
|
do
|
||||||
create error_handler.make
|
create error_handler.make
|
||||||
input := a_input
|
input := a_input
|
||||||
output := a_output
|
|
||||||
environment := env
|
environment := env
|
||||||
content_length := env.content_length_value
|
content_length := env.content_length_value
|
||||||
create execution_variables.make (10)
|
create execution_variables.make (10)
|
||||||
@@ -70,10 +69,7 @@ feature {NONE} -- Initialization
|
|||||||
extract_variables
|
extract_variables
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access: Input/Output
|
feature -- Access: Input
|
||||||
|
|
||||||
output: GW_OUTPUT_STREAM
|
|
||||||
-- Server output channel
|
|
||||||
|
|
||||||
input: GW_INPUT_STREAM
|
input: GW_INPUT_STREAM
|
||||||
-- Server input channel
|
-- Server input channel
|
||||||
|
|||||||
32
library/server/ewsgi/src/response/gw_response.e
Normal file
32
library/server/ewsgi/src/response/gw_response.e
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {GW_RESPONSE}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
GW_RESPONSE
|
||||||
|
|
||||||
|
feature -- Access: Input/Output
|
||||||
|
|
||||||
|
output: GW_OUTPUT_STREAM
|
||||||
|
-- Server output channel
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
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)"
|
||||||
|
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
|
||||||
42
library/server/ewsgi/src/response/gw_response_imp.e
Normal file
42
library/server/ewsgi/src/response/gw_response_imp.e
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {GW_RESPONSE_IMP}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
GW_RESPONSE_IMP
|
||||||
|
|
||||||
|
inherit
|
||||||
|
GW_RESPONSE
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (a_output: like output)
|
||||||
|
do
|
||||||
|
output := a_output
|
||||||
|
create header.make
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access: Input/Output
|
||||||
|
|
||||||
|
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)"
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user