Changed the WGI_INPUT_STREAM and WGI_OUTPUT_STREAM interfaces
main changes for existing code `read_stream' is renamed `read_string'
This commit is contained in:
@@ -10,10 +10,15 @@ class
|
||||
|
||||
inherit
|
||||
WGI_INPUT_STREAM
|
||||
undefine
|
||||
read_to_string
|
||||
end
|
||||
|
||||
CONSOLE
|
||||
rename
|
||||
make as console_make
|
||||
make as console_make,
|
||||
read_stream as read_string,
|
||||
end_of_file as end_of_input
|
||||
end
|
||||
|
||||
create
|
||||
|
||||
@@ -10,9 +10,6 @@ class
|
||||
|
||||
inherit
|
||||
WGI_OUTPUT_STREAM
|
||||
undefine
|
||||
flush
|
||||
end
|
||||
|
||||
CONSOLE
|
||||
rename
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="connector" location="..\connector-safe.ecf" readonly="false"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
|
||||
<library name="libfcgi" location="..\..\..\libfcgi\libfcgi-safe.ecf" />
|
||||
<library name="connector" location="..\connector-safe.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi-safe.ecf"/>
|
||||
<library name="libfcgi" location="..\..\..\libfcgi\libfcgi-safe.ecf"/>
|
||||
<library name="http" location="..\..\..\..\protocol\http\http-safe.ecf"/>
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
|
||||
@@ -32,9 +32,38 @@ feature {NONE} -- Initialization
|
||||
create last_string.make_empty
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
feature -- Status report
|
||||
|
||||
read_stream (nb_char: INTEGER)
|
||||
is_open_read: BOOLEAN
|
||||
-- Can items be read from input stream?
|
||||
do
|
||||
Result := True
|
||||
end
|
||||
|
||||
end_of_input: BOOLEAN
|
||||
-- Has the end of input stream been reached?
|
||||
do
|
||||
Result := fcgi.fcgi_end_of_input
|
||||
end
|
||||
|
||||
feature -- Input
|
||||
|
||||
read_character
|
||||
-- Read the next character in input stream.
|
||||
-- Make the result available in `last_character'.
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
create s.make (1)
|
||||
fcgi.fill_string_from_stdin (s, 1)
|
||||
if s.count >= 1 then
|
||||
last_character := s.item (1)
|
||||
else
|
||||
last_character := '%U'
|
||||
end
|
||||
end
|
||||
|
||||
read_string (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' bound characters
|
||||
-- or until end of file.
|
||||
-- Make result available in `last_string'.
|
||||
@@ -47,6 +76,9 @@ feature -- Access
|
||||
last_string: STRING
|
||||
-- Last string read
|
||||
|
||||
last_character: CHARACTER_8
|
||||
-- Last item read
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
fcgi: FCGI;
|
||||
|
||||
@@ -28,6 +28,14 @@ feature {NONE} -- Initialization
|
||||
fcgi := a_fcgi
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_open_write: BOOLEAN
|
||||
-- Can items be written to output stream?
|
||||
do
|
||||
Result := True
|
||||
end
|
||||
|
||||
feature -- Status writing
|
||||
|
||||
put_status_line (a_code: INTEGER)
|
||||
@@ -56,6 +64,13 @@ feature -- Basic operation
|
||||
fcgi.put_string (s)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
flush
|
||||
-- Flush buffered data to disk.
|
||||
do
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
fcgi: FCGI
|
||||
|
||||
@@ -104,15 +104,15 @@ feature -- Server
|
||||
server.setup (l_http_handler)
|
||||
end
|
||||
|
||||
process_request (env: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM)
|
||||
process_request (env: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_socket: TCP_STREAM_SOCKET)
|
||||
local
|
||||
req: WGI_REQUEST_FROM_TABLE
|
||||
res: detachable WGI_RESPONSE_STREAM_BUFFER
|
||||
rescued: BOOLEAN
|
||||
do
|
||||
if not rescued then
|
||||
create req.make (env, create {WGI_NINO_INPUT_STREAM}.make (a_input))
|
||||
create res.make (create {WGI_NINO_OUTPUT_STREAM}.make (a_output))
|
||||
create req.make (env, create {WGI_NINO_INPUT_STREAM}.make (a_socket))
|
||||
create res.make (create {WGI_NINO_OUTPUT_STREAM}.make (a_socket))
|
||||
req.set_meta_string_variable ("RAW_HEADER_DATA", a_headers_text)
|
||||
application.execute (req, res)
|
||||
else
|
||||
|
||||
@@ -58,7 +58,7 @@ feature -- Element change
|
||||
|
||||
feature -- Request processing
|
||||
|
||||
process_request (a_handler: HTTP_CONNECTION_HANDLER; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM)
|
||||
process_request (a_handler: HTTP_CONNECTION_HANDLER; a_socket: TCP_STREAM_SOCKET)
|
||||
-- Process request ...
|
||||
local
|
||||
env, vars: HASH_TABLE [STRING, STRING]
|
||||
@@ -161,14 +161,20 @@ feature -- Request processing
|
||||
end
|
||||
end
|
||||
|
||||
callback.process_request (env, a_handler.request_header, a_input, a_output)
|
||||
callback.process_request (env, a_handler.request_header, a_socket)
|
||||
end
|
||||
|
||||
add_environment_variable (a_value: detachable STRING; a_var_name: STRING; env: HASH_TABLE [STRING, STRING])
|
||||
-- Add variable `a_var_name => a_value' to `env'
|
||||
do
|
||||
if a_value /= Void then
|
||||
env.force (a_value, a_var_name)
|
||||
if env.has_key (a_var_name) and then attached env.found_item as l_existing_value then
|
||||
--| Check http://www.ietf.org/rfc/rfc3875 4.1.18
|
||||
check find_proper_rewrite_for_same_header: False end
|
||||
env.force (l_existing_value + " " + a_value, a_var_name)
|
||||
else
|
||||
env.force (a_value, a_var_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,36 +16,71 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_nino_input: like nino_input)
|
||||
make (a_source: like source)
|
||||
do
|
||||
create last_string.make_empty
|
||||
set_nino_input (a_nino_input)
|
||||
set_source (a_source)
|
||||
end
|
||||
|
||||
feature {WGI_NINO_CONNECTOR, WGI_APPLICATION} -- Nino
|
||||
|
||||
set_nino_input (i: like nino_input)
|
||||
set_source (i: like source)
|
||||
do
|
||||
nino_input := i
|
||||
source := i
|
||||
end
|
||||
|
||||
nino_input: HTTP_INPUT_STREAM
|
||||
source: TCP_STREAM_SOCKET
|
||||
|
||||
feature -- Basic operation
|
||||
feature -- Input
|
||||
|
||||
read_stream (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' bound characters
|
||||
-- or until end of file.
|
||||
-- Make result available in `last_string'.
|
||||
read_character
|
||||
-- Read the next character in input stream.
|
||||
-- Make the result available in `last_character'.
|
||||
local
|
||||
s: detachable STRING
|
||||
do
|
||||
nino_input.read_stream (nb_char)
|
||||
last_string := nino_input.last_string
|
||||
if source.socket_ok then
|
||||
source.read_character
|
||||
last_character := source.last_character
|
||||
else
|
||||
last_character := '%U'
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
read_string (nb: INTEGER)
|
||||
do
|
||||
last_string.wipe_out
|
||||
if source.socket_ok then
|
||||
source.read_stream_thread_aware (nb)
|
||||
last_string.append_string (source.last_string)
|
||||
end
|
||||
end
|
||||
|
||||
last_string: STRING
|
||||
-- Last string read
|
||||
feature -- Access
|
||||
|
||||
last_string: STRING_8
|
||||
-- Last string read
|
||||
-- (Note: this query always return the same object.
|
||||
-- Therefore a clone should be used if the result
|
||||
-- is to be kept beyond the next call to this feature.
|
||||
-- However `last_string' is not shared between input objects.)
|
||||
|
||||
last_character: CHARACTER_8
|
||||
-- Last item read
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_open_read: BOOLEAN
|
||||
-- Can items be read from input stream?
|
||||
do
|
||||
Result := source.is_open_read
|
||||
end
|
||||
|
||||
end_of_input: BOOLEAN
|
||||
-- Has the end of input stream been reached?
|
||||
do
|
||||
Result := source.ready_for_reading
|
||||
end
|
||||
|
||||
;note
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
|
||||
@@ -10,6 +10,9 @@ class
|
||||
|
||||
inherit
|
||||
WGI_OUTPUT_STREAM
|
||||
redefine
|
||||
put_character_8
|
||||
end
|
||||
|
||||
HTTP_STATUS_CODE_MESSAGES
|
||||
export
|
||||
@@ -21,19 +24,19 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_nino_output: like nino_output)
|
||||
make (a_target: like target)
|
||||
do
|
||||
set_nino_output (a_nino_output)
|
||||
set_target (a_target)
|
||||
end
|
||||
|
||||
feature {WGI_NINO_CONNECTOR, WGI_APPLICATION} -- Nino
|
||||
|
||||
set_nino_output (o: like nino_output)
|
||||
set_target (o: like target)
|
||||
do
|
||||
nino_output := o
|
||||
target := o
|
||||
end
|
||||
|
||||
nino_output: HTTP_OUTPUT_STREAM
|
||||
target: TCP_STREAM_SOCKET
|
||||
|
||||
feature -- Status writing
|
||||
|
||||
@@ -55,15 +58,31 @@ feature -- Status writing
|
||||
put_header_line (s)
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
feature -- Output
|
||||
|
||||
put_string (s: STRING_8)
|
||||
-- Send `s' to http client
|
||||
do
|
||||
debug ("nino")
|
||||
print (s)
|
||||
end
|
||||
nino_output.put_string (s)
|
||||
target.put_string (s)
|
||||
end
|
||||
|
||||
put_character_8 (c: CHARACTER_8)
|
||||
do
|
||||
target.put_character (c)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_open_write: BOOLEAN
|
||||
-- Can items be written to output stream?
|
||||
do
|
||||
Result := target.is_open_write
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
flush
|
||||
do
|
||||
end
|
||||
|
||||
note
|
||||
|
||||
Reference in New Issue
Block a user