Merged REQUEST and ENVIRONMENT into REQUEST

renamed ENVIRONMENT_NAMES into META_NAMES
better usage of READABLE_STRING_GENERAL, and other strings
abstract RESPONSE_BUFFER in implementation of EWSGI
for the implementation, inheriting from deferred specification (more to come later)
This commit is contained in:
Jocelyn Fiat
2011-08-25 14:41:35 +02:00
parent 4d0148d562
commit f6b362217c
34 changed files with 1275 additions and 2366 deletions

View File

@@ -9,26 +9,21 @@ class
inherit
EWSGI_RESPONSE_BUFFER
rename
make as buffer_make
redefine
write,
flush,
commit
end
create {EWSGI_APPLICATION}
make
feature {NONE} -- Initialization
make (a_output: like output; a_buffer_size: INTEGER)
make (a_res: like response_buffer; a_buffer_size: INTEGER)
do
buffer_make (a_output)
response_buffer := a_res
buffer_capacity := a_buffer_size
create buffer.make (a_buffer_size)
end
response_buffer: EWSGI_RESPONSE_BUFFER
buffer: STRING_8
buffer_capacity: INTEGER
@@ -78,7 +73,7 @@ feature {NONE} -- Implementation
require
buffer_count_match_buffer: buffer_count = buffer.count
do
output.put_string (buffer)
response_buffer.write (buffer)
buffer_count := 0
ensure
buffer_flushed: buffer_count = 0 and buffer.count = 0
@@ -89,7 +84,93 @@ feature {EWSGI_APPLICATION} -- Commit
commit
do
flush_buffer
Precursor
end
feature -- Status report
header_committed: BOOLEAN
-- Header committed?
message_committed: BOOLEAN
-- Message committed?
message_writable: BOOLEAN
-- Can message be written?
do
Result := status_is_set and header_committed
end
feature -- Status setting
status_is_set: BOOLEAN
-- Is status set?
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
response_buffer.set_status_code (a_code)
end
status_code: INTEGER
-- Response status
feature -- Header output operation
write_headers_string (a_headers: STRING)
do
write (a_headers)
header_committed := True
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
h.put_status (a_status_code)
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_headers_string (h.string)
end
feature -- Output operation
write_string (s: STRING)
-- Send the string `s'
do
write (s)
end
write_substring (s: STRING; start_index, end_index: INTEGER)
-- Send the substring `start_index:end_index]'
--| Could be optimized according to the target output
do
flush_buffer
response_buffer.write_substring (s, start_index, end_index)
end
write_file_content (fn: STRING)
-- Send the content of file `fn'
do
flush_buffer
response_buffer.write_file_content (fn)
end
;note

View File

@@ -8,31 +8,72 @@ class
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)
make (res: EWSGI_RESPONSE_BUFFER)
do
Precursor (a_output)
response_buffer := res
create header.make
create body.make (100)
end
response_buffer: EWSGI_RESPONSE_BUFFER
header: GW_HEADER
body: STRING_8
feature {EWSGI_APPLICATION} -- Commit
commit
local
r: like response_buffer
do
r := response_buffer
r.set_status_code (status_code)
r.write_headers_string (header.string)
header_committed := True
r.write_string (body)
r.flush
end
feature -- Status report
header_committed: BOOLEAN
-- Header committed?
message_committed: BOOLEAN
-- Message committed?
message_writable: BOOLEAN
-- Can message be written?
do
Result := status_is_set and header_committed
end
feature -- Status setting
status_is_set: BOOLEAN
-- Is status set?
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
end
status_code: INTEGER
-- Response status
feature {NONE} -- Status output
write (s: STRING)
@@ -41,24 +82,14 @@ feature {NONE} -- Status output
body.append (s)
end
feature -- Status setting
feature -- Header output operation
set_status_code (a_code: INTEGER)
-- Set response status code
-- Should be done before sending any data back to the client
write_headers_string (a_headers: STRING)
do
status_code := a_code
write (a_headers)
header_committed := True
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
@@ -81,19 +112,30 @@ feature -- Header output operation
header := h
end
feature {EWSGI_APPLICATION} -- Commit
feature -- Output operation
commit
local
o: like output
write_string (s: STRING)
-- Send the string `s'
do
o := output
o.put_status_line (status_code)
o.put_string (header.string)
header_committed := True
o.put_string (body)
o.flush
Precursor
write (s)
end
write_substring (s: STRING; start_index, end_index: INTEGER)
-- Send the substring `start_index:end_index]'
--| Could be optimized according to the target output
do
write_string (s.substring (start_index, end_index))
end
write_file_content (fn: STRING)
-- Send the content of file `fn'
do
response_buffer.write_file_content (fn)
end
flush
do
--| Do nothing ... this is in_memory response
end
;note

View File

@@ -9,15 +9,41 @@ deferred class
inherit
EWSGI_APPLICATION
redefine
new_response
rename
execute as app_execute
end
feature -- Factory
new_response (req: EWSGI_REQUEST; a_output: EWSGI_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE
feature -- Execution
app_execute (req: EWSGI_REQUEST; res: EWSGI_RESPONSE_BUFFER)
-- Execute the request
-- See `req.input' for input stream
-- `req.environment' for the Gateway environment
-- and `res' for output buffer
do
create {GW_IN_MEMORY_RESPONSE} Result.make (a_output)
execute (req, new_response (req, res))
end
feature -- Execute
execute (req: EWSGI_REQUEST; res: EWSGI_RESPONSE_BUFFER)
-- Execute the request
-- See `req.input' for input stream
-- `req.environment' for the Gateway environment
-- and `res' for output buffer
require
res_status_unset: not res.status_is_set
deferred
ensure
res_status_set: res.status_is_set
end
feature {NONE} -- Implementation
new_response (req: EWSGI_REQUEST; a_res: EWSGI_RESPONSE_BUFFER): GW_IN_MEMORY_RESPONSE
do
create {GW_IN_MEMORY_RESPONSE} Result.make (a_res)
end
note