Removed HTTP_(INPUT,OUTPUT)_STREAM, since it is unlikely that we use something else than TCP_STREAM_SOCKET
This way, we remove one indirection for users, and get smaller code.
This commit is contained in:
@@ -37,14 +37,8 @@ feature -- Execution
|
||||
|
||||
receive_message_and_send_reply (client_socket: TCP_STREAM_SOCKET)
|
||||
local
|
||||
l_input: HTTP_INPUT_STREAM
|
||||
l_output: HTTP_OUTPUT_STREAM
|
||||
l_remote_info: detachable like remote_info
|
||||
do
|
||||
create l_input.make (client_socket)
|
||||
create l_output.make (client_socket)
|
||||
|
||||
|
||||
create l_remote_info
|
||||
if attached client_socket.peer_address as l_addr then
|
||||
l_remote_info.addr := l_addr.host_address.host_address
|
||||
@@ -53,14 +47,14 @@ feature -- Execution
|
||||
remote_info := l_remote_info
|
||||
end
|
||||
|
||||
analyze_request_message (l_input)
|
||||
process_request (Current, l_input, l_output)
|
||||
analyze_request_message (client_socket)
|
||||
process_request (Current, client_socket)
|
||||
reset
|
||||
end
|
||||
|
||||
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 ...
|
||||
require
|
||||
a_handler_attached: a_handler /= Void
|
||||
@@ -68,8 +62,7 @@ feature -- Request processing
|
||||
a_method_attached: a_handler.method /= Void
|
||||
a_header_map_attached: a_handler.request_header_map /= Void
|
||||
a_header_text_attached: a_handler.request_header /= Void
|
||||
a_input_attached: a_input /= Void
|
||||
a_output_attached: a_output /= Void
|
||||
a_socket_attached: a_socket /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -95,30 +88,29 @@ feature -- Access
|
||||
|
||||
feature -- Parsing
|
||||
|
||||
analyze_request_message (a_input: HTTP_INPUT_STREAM)
|
||||
analyze_request_message (a_socket: TCP_STREAM_SOCKET)
|
||||
require
|
||||
input_readable: a_input /= Void and then a_input.is_readable
|
||||
input_readable: a_socket /= Void and then a_socket.is_open_read
|
||||
local
|
||||
end_of_stream : BOOLEAN
|
||||
pos,n : INTEGER
|
||||
line : STRING
|
||||
line : detachable STRING
|
||||
k, val: STRING
|
||||
txt: STRING
|
||||
do
|
||||
create txt.make (64)
|
||||
a_input.read_line
|
||||
line := a_input.last_string
|
||||
line := next_line (a_socket)
|
||||
if line /= Void then
|
||||
analyze_request_line (line)
|
||||
txt.append (line)
|
||||
txt.append_character ('%N')
|
||||
|
||||
request_header := txt
|
||||
from
|
||||
a_input.read_line
|
||||
line := next_line (a_socket)
|
||||
until
|
||||
end_of_stream
|
||||
line = Void or end_of_stream
|
||||
loop
|
||||
line := a_input.last_string
|
||||
n := line.count
|
||||
debug ("nino")
|
||||
print ("%N" + line)
|
||||
@@ -140,7 +132,8 @@ feature -- Parsing
|
||||
if line.is_empty or else line [1] = '%R' then
|
||||
end_of_stream := True
|
||||
else
|
||||
a_input.read_line
|
||||
line := next_line (a_socket)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -165,6 +158,15 @@ feature -- Parsing
|
||||
not_void_method: method /= Void
|
||||
end
|
||||
|
||||
next_line (a_socket: TCP_STREAM_SOCKET): detachable STRING
|
||||
require
|
||||
is_readable: a_socket.is_open_read
|
||||
do
|
||||
if a_socket.socket_ok then
|
||||
a_socket.read_line_thread_aware
|
||||
Result := a_socket.last_string
|
||||
end
|
||||
end
|
||||
|
||||
invariant
|
||||
request_header_attached: request_header /= Void
|
||||
|
||||
@@ -25,8 +25,10 @@ feature -- Initialization
|
||||
require
|
||||
a_http_handler_valid: a_http_handler /= Void
|
||||
do
|
||||
if configuration.is_verbose then
|
||||
print("%N%N%N")
|
||||
print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
|
||||
end
|
||||
stop_requested := False
|
||||
if configuration.force_single_threaded then
|
||||
a_http_handler.execute
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_INPUT_STREAM}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_INPUT_STREAM
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_socket: like source)
|
||||
do
|
||||
source := a_socket
|
||||
create last_string.make_empty
|
||||
end
|
||||
|
||||
source: TCP_STREAM_SOCKET
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
is_readable: BOOLEAN
|
||||
-- Is readable?
|
||||
do
|
||||
Result := source.is_open_read
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
read_line
|
||||
require
|
||||
is_readable: is_readable
|
||||
do
|
||||
last_string.wipe_out
|
||||
if source.socket_ok then
|
||||
source.read_line_thread_aware
|
||||
last_string.append_string (source.last_string)
|
||||
end
|
||||
end
|
||||
|
||||
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'.
|
||||
require
|
||||
nb_char_positive: nb_char > 0
|
||||
is_readable: is_readable
|
||||
do
|
||||
last_string.wipe_out
|
||||
if source.socket_ok then
|
||||
source.read_stream_thread_aware (nb_char)
|
||||
last_string.append_string (source.last_string)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
last_string: STRING
|
||||
-- Last string read
|
||||
|
||||
;note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
@@ -1,33 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_OUTPUT_STREAM}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_OUTPUT_STREAM
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_socket: like target)
|
||||
do
|
||||
target := a_socket
|
||||
end
|
||||
|
||||
target: TCP_STREAM_SOCKET
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
put_string (s: STRING)
|
||||
-- Write string `s' to `target'
|
||||
do
|
||||
target.put_string (s)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
Reference in New Issue
Block a user