From a46c08de11ebe132de2c32d970fd192d9675b3d3 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 10 Nov 2011 22:05:34 +0100 Subject: [PATCH] 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. --- library/http_connection_handler.e | 96 ++++++++++++++++--------------- library/http_server.e | 6 +- library/io/http_input_stream.e | 67 --------------------- library/io/http_output_stream.e | 33 ----------- 4 files changed, 53 insertions(+), 149 deletions(-) delete mode 100644 library/io/http_input_stream.e delete mode 100644 library/io/http_output_stream.e diff --git a/library/http_connection_handler.e b/library/http_connection_handler.e index ff3757a3..a8e29895 100644 --- a/library/http_connection_handler.e +++ b/library/http_connection_handler.e @@ -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 diff --git a/library/http_server.e b/library/http_server.e index a21e048c..862eac4c 100644 --- a/library/http_server.e +++ b/library/http_server.e @@ -25,8 +25,10 @@ feature -- Initialization require a_http_handler_valid: a_http_handler /= Void do - print("%N%N%N") - print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N") + 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 diff --git a/library/io/http_input_stream.e b/library/io/http_input_stream.e deleted file mode 100644 index 23cce238..00000000 --- a/library/io/http_input_stream.e +++ /dev/null @@ -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 diff --git a/library/io/http_output_stream.e b/library/io/http_output_stream.e deleted file mode 100644 index c6c84582..00000000 --- a/library/io/http_output_stream.e +++ /dev/null @@ -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