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:
Jocelyn Fiat
2011-11-10 22:05:34 +01:00
parent abd67c8caa
commit a46c08de11
4 changed files with 53 additions and 149 deletions

View File

@@ -37,14 +37,8 @@ feature -- Execution
receive_message_and_send_reply (client_socket: TCP_STREAM_SOCKET) receive_message_and_send_reply (client_socket: TCP_STREAM_SOCKET)
local local
l_input: HTTP_INPUT_STREAM
l_output: HTTP_OUTPUT_STREAM
l_remote_info: detachable like remote_info l_remote_info: detachable like remote_info
do do
create l_input.make (client_socket)
create l_output.make (client_socket)
create l_remote_info create l_remote_info
if attached client_socket.peer_address as l_addr then if attached client_socket.peer_address as l_addr then
l_remote_info.addr := l_addr.host_address.host_address l_remote_info.addr := l_addr.host_address.host_address
@@ -53,14 +47,14 @@ feature -- Execution
remote_info := l_remote_info remote_info := l_remote_info
end end
analyze_request_message (l_input) analyze_request_message (client_socket)
process_request (Current, l_input, l_output) process_request (Current, client_socket)
reset reset
end end
feature -- Request processing 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 ... -- Process request ...
require require
a_handler_attached: a_handler /= Void a_handler_attached: a_handler /= Void
@@ -68,8 +62,7 @@ feature -- Request processing
a_method_attached: a_handler.method /= Void a_method_attached: a_handler.method /= Void
a_header_map_attached: a_handler.request_header_map /= Void a_header_map_attached: a_handler.request_header_map /= Void
a_header_text_attached: a_handler.request_header /= Void a_header_text_attached: a_handler.request_header /= Void
a_input_attached: a_input /= Void a_socket_attached: a_socket /= Void
a_output_attached: a_output /= Void
deferred deferred
end end
@@ -95,54 +88,54 @@ feature -- Access
feature -- Parsing feature -- Parsing
analyze_request_message (a_input: HTTP_INPUT_STREAM) analyze_request_message (a_socket: TCP_STREAM_SOCKET)
require 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 local
end_of_stream : BOOLEAN end_of_stream : BOOLEAN
pos,n : INTEGER pos,n : INTEGER
line : STRING line : detachable STRING
k, val: STRING k, val: STRING
txt: STRING txt: STRING
do do
create txt.make (64) create txt.make (64)
a_input.read_line line := next_line (a_socket)
line := a_input.last_string if line /= Void then
analyze_request_line (line) analyze_request_line (line)
txt.append (line) txt.append (line)
txt.append_character ('%N') txt.append_character ('%N')
request_header := txt request_header := txt
from from
a_input.read_line line := next_line (a_socket)
until until
end_of_stream line = Void or end_of_stream
loop loop
line := a_input.last_string n := line.count
n := line.count debug ("nino")
debug ("nino") print ("%N" + line)
print ("%N" + line)
end
pos := line.index_of (':',1)
if pos > 0 then
k := line.substring (1, pos-1)
if line [pos+1].is_space then
pos := pos + 1
end end
if line [n] = '%R' then pos := line.index_of (':',1)
n := n - 1 if pos > 0 then
k := line.substring (1, pos-1)
if line [pos+1].is_space then
pos := pos + 1
end
if line [n] = '%R' then
n := n - 1
end
val := line.substring (pos + 1, n)
request_header_map.put (val, k)
end
txt.append (line)
txt.append_character ('%N')
if line.is_empty or else line [1] = '%R' then
end_of_stream := True
else
line := next_line (a_socket)
end end
val := line.substring (pos + 1, n)
request_header_map.put (val, k)
end end
txt.append (line) end
txt.append_character ('%N')
if line.is_empty or else line [1] = '%R' then
end_of_stream := True
else
a_input.read_line
end
end
end end
analyze_request_line (line: STRING) analyze_request_line (line: STRING)
@@ -165,6 +158,15 @@ feature -- Parsing
not_void_method: method /= Void not_void_method: method /= Void
end 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 invariant
request_header_attached: request_header /= Void request_header_attached: request_header /= Void

View File

@@ -25,8 +25,10 @@ feature -- Initialization
require require
a_http_handler_valid: a_http_handler /= Void a_http_handler_valid: a_http_handler /= Void
do do
print("%N%N%N") if configuration.is_verbose then
print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N") print("%N%N%N")
print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
end
stop_requested := False stop_requested := False
if configuration.force_single_threaded then if configuration.force_single_threaded then
a_http_handler.execute a_http_handler.execute

View File

@@ -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

View File

@@ -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