Tried to reduce gap between both EWSGI proposals
Re-adapt the Spec-compliant solution (instead of Lib-compliant solution). Thus no more 100% deferred interface. Rename EWSGI_RESPONSE into EWSGI_RESPONSE_BUFFER Added in extra/response-as-result/ an copy/paste from the implementation of Paul's proposal (not up to date with Paul's spec). But this is mainly for information and tests. Removed part of the ewsgi/specification interfaces ... to be able to test EWSGI compliant library against the pure specification (experimental). Renamed most of the GW_... into EWSGI_...
This commit is contained in:
109
library/server/ewsgi/src/extra/in_memory/gw_in_memory_response.e
Normal file
109
library/server/ewsgi/src/extra/in_memory/gw_in_memory_response.e
Normal file
@@ -0,0 +1,109 @@
|
||||
note
|
||||
description: "Summary description for {GW_IN_MEMORY_RESPONSE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_IN_MEMORY_RESPONSE
|
||||
|
||||
inherit
|
||||
EWSGI_RESPONSE_BUFFER
|
||||
redefine
|
||||
make,
|
||||
commit,
|
||||
write,
|
||||
set_status_code,
|
||||
write_header,
|
||||
flush
|
||||
end
|
||||
|
||||
create {EWSGI_APPLICATION}
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_output: EWSGI_OUTPUT_STREAM)
|
||||
do
|
||||
Precursor (a_output)
|
||||
create header.make
|
||||
create body.make (100)
|
||||
end
|
||||
|
||||
header: GW_HEADER
|
||||
|
||||
body: STRING_8
|
||||
|
||||
feature {NONE} -- Status output
|
||||
|
||||
write (s: STRING)
|
||||
-- Send the content of `s'
|
||||
do
|
||||
body.append (s)
|
||||
end
|
||||
|
||||
feature -- Status setting
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
feature -- Output operation
|
||||
|
||||
flush
|
||||
do
|
||||
--| Do nothing ... this is in_memory response
|
||||
end
|
||||
|
||||
feature -- Header output operation
|
||||
|
||||
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
|
||||
header := h
|
||||
end
|
||||
|
||||
feature {EWSGI_APPLICATION} -- Commit
|
||||
|
||||
commit
|
||||
local
|
||||
o: like output
|
||||
do
|
||||
o := output
|
||||
o.put_status_line (status_code)
|
||||
o.put_string (header.string)
|
||||
header_committed := True
|
||||
o.put_string (body)
|
||||
o.flush
|
||||
Precursor
|
||||
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
|
||||
@@ -0,0 +1,33 @@
|
||||
note
|
||||
description: "Summary description for {GW_IN_MEMORY_RESPONSE_APPLICATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
GW_IN_MEMORY_RESPONSE_APPLICATION
|
||||
|
||||
inherit
|
||||
EWSGI_APPLICATION
|
||||
redefine
|
||||
new_response
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_response (req: EWSGI_REQUEST; a_output: EWSGI_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE
|
||||
do
|
||||
create {GW_IN_MEMORY_RESPONSE} 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)"
|
||||
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