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,54 +88,54 @@ 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
|
||||
analyze_request_line (line)
|
||||
txt.append (line)
|
||||
txt.append_character ('%N')
|
||||
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
|
||||
until
|
||||
end_of_stream
|
||||
loop
|
||||
line := a_input.last_string
|
||||
n := line.count
|
||||
debug ("nino")
|
||||
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
|
||||
request_header := txt
|
||||
from
|
||||
line := next_line (a_socket)
|
||||
until
|
||||
line = Void or end_of_stream
|
||||
loop
|
||||
n := line.count
|
||||
debug ("nino")
|
||||
print ("%N" + line)
|
||||
end
|
||||
if line [n] = '%R' then
|
||||
n := n - 1
|
||||
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
|
||||
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
|
||||
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
|
||||
a_input.read_line
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
analyze_request_line (line: STRING)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user