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
|
||||
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")
|
||||
(create {GW_NINO_APPLICATION}.make (agent (ctx: GW_REQUEST_CONTEXT)
|
||||
(create {GW_NINO_APPLICATION}.make (agent (req: GW_REQUEST_CONTEXT; res: GW_RESPONSE)
|
||||
do
|
||||
ctx.output.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
ctx.output.put_string ("Hello World!%N")
|
||||
res.output.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
res.output.put_string ("Hello World!%N")
|
||||
end
|
||||
)).listen (port_number)
|
||||
end
|
||||
|
||||
@@ -22,11 +22,6 @@ feature -- Access: Input/Output
|
||||
deferred
|
||||
end
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
-- Server output channel
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access: global variable
|
||||
|
||||
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'
|
||||
local
|
||||
rescued: BOOLEAN
|
||||
ctx: detachable GW_REQUEST_CONTEXT
|
||||
req: detachable like new_request_context
|
||||
res: detachable like new_response
|
||||
do
|
||||
if not rescued then
|
||||
pre_execute (env)
|
||||
ctx := new_request_context (env, a_input, a_output)
|
||||
execute (ctx)
|
||||
post_execute (ctx)
|
||||
req := new_request_context (env, a_input)
|
||||
res := new_response (a_output)
|
||||
execute (req, res)
|
||||
post_execute (req, res)
|
||||
else
|
||||
rescue_execute (ctx, (create {EXCEPTION_MANAGER}).last_exception)
|
||||
rescue_execute (req, res, (create {EXCEPTION_MANAGER}).last_exception)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Execution
|
||||
|
||||
execute (ctx: GW_REQUEST_CONTEXT)
|
||||
execute (req: GW_REQUEST_CONTEXT; res: GW_RESPONSE)
|
||||
-- Execute the request
|
||||
-- See `ctx.input' and `ctx.output' for i/o streams
|
||||
-- `ctx.environment' for the Gateway environment
|
||||
-- See `req.input' and `res.output' for i/o streams
|
||||
-- `req.environment' for the Gateway environment
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -42,27 +44,35 @@ feature {NONE} -- Execution
|
||||
do
|
||||
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'
|
||||
do
|
||||
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'
|
||||
do
|
||||
post_execute (ctx)
|
||||
post_execute (req, res)
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM; a_output: GW_OUTPUT_STREAM): GW_REQUEST_CONTEXT
|
||||
-- New Gateway Context based on `env' `a_input' and `a_output'
|
||||
new_request_context (env: GW_ENVIRONMENT; a_input: GW_INPUT_STREAM): GW_REQUEST_CONTEXT
|
||||
-- New Request context based on `env' and `a_input'
|
||||
--| note: you can redefine this function to create your own
|
||||
--| descendant of GW_REQUEST_CONTEXT , or even to reuse/recycle existing
|
||||
--| instance of GW_REQUEST_CONTEXT
|
||||
deferred
|
||||
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
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -23,13 +23,13 @@ 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'
|
||||
|
||||
execute (ctx: like new_request_context)
|
||||
execute (req: like new_request_context; res: like new_response)
|
||||
-- Execute the request
|
||||
do
|
||||
callback.call ([ctx])
|
||||
callback.call ([req, res])
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
@@ -30,12 +30,17 @@ feature -- Execution
|
||||
|
||||
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
|
||||
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")
|
||||
end
|
||||
|
||||
new_response (a_output: GW_OUTPUT_STREAM): GW_RESPONSE
|
||||
do
|
||||
create {GW_RESPONSE_IMP} Result.make (a_output)
|
||||
end
|
||||
|
||||
;note
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -23,13 +23,12 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (env: GW_ENVIRONMENT; a_input: like input; a_output: like output)
|
||||
make (env: GW_ENVIRONMENT; a_input: like input)
|
||||
require
|
||||
env_attached: env /= Void
|
||||
do
|
||||
create error_handler.make
|
||||
input := a_input
|
||||
output := a_output
|
||||
environment := env
|
||||
content_length := env.content_length_value
|
||||
create execution_variables.make (10)
|
||||
@@ -70,10 +69,7 @@ feature {NONE} -- Initialization
|
||||
extract_variables
|
||||
end
|
||||
|
||||
feature -- Access: Input/Output
|
||||
|
||||
output: GW_OUTPUT_STREAM
|
||||
-- Server output channel
|
||||
feature -- Access: Input
|
||||
|
||||
input: GW_INPUT_STREAM
|
||||
-- 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