From b78c44f4a1eacbe48c2fa39f127ff861c3486892 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 14 Nov 2011 16:32:09 +0100 Subject: [PATCH] Applied the removal of HTTP_INPUT_STREAM and HTTP_OUTPUT_STREAM to the example. --- example/SimpleWebServer/application.e | 3 +++ .../application_connection_handler.e | 16 +++++++------- .../request/get_request_handler.e | 11 ++++------ .../request/post_request_handler.e | 21 ++++++++++++++----- example/SimpleWebServer/web_server-safe.ecf | 9 ++++---- nino-safe.ecf | 3 +-- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/example/SimpleWebServer/application.e b/example/SimpleWebServer/application.e index 4b9bb023..96e80318 100644 --- a/example/SimpleWebServer/application.e +++ b/example/SimpleWebServer/application.e @@ -24,6 +24,9 @@ feature {NONE} -- Initialization create l_cfg.make l_cfg.http_server_port := 9_000 l_cfg.document_root := default_document_root + debug ("nino") + l_cfg.set_is_verbose (True) + end create l_server.make (l_cfg) create {APPLICATION_CONNECTION_HANDLER} l_http_handler.make (l_server) diff --git a/example/SimpleWebServer/application_connection_handler.e b/example/SimpleWebServer/application_connection_handler.e index 78277160..87833f7d 100644 --- a/example/SimpleWebServer/application_connection_handler.e +++ b/example/SimpleWebServer/application_connection_handler.e @@ -15,17 +15,17 @@ create 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 a_method: STRING do a_method := a_handler.method - + if a_method.is_equal (Get) then - execute_get_request (a_handler.uri, a_handler.request_header_map, a_handler.request_header, a_input, a_output) + execute_get_request (a_handler.uri, a_handler.request_header_map, a_handler.request_header, a_socket) elseif a_method.is_equal (Post) then - execute_post_request (a_handler.uri, a_handler.request_header_map, a_handler.request_header, a_input, a_output) + execute_post_request (a_handler.uri, a_handler.request_header_map, a_handler.request_header, a_socket) elseif a_method.is_equal (Put) then elseif a_method.is_equal (Options) then elseif a_method.is_equal (Head) then @@ -39,21 +39,21 @@ feature -- Request processing end end - execute_get_request (a_uri: STRING; a_headers_map: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM) + execute_get_request (a_uri: STRING; a_headers_map: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_socket: TCP_STREAM_SOCKET) local l_http_request : HTTP_REQUEST_HANDLER do - create {GET_REQUEST_HANDLER} l_http_request.make (a_input, a_output) + create {GET_REQUEST_HANDLER} l_http_request.make (a_socket) l_http_request.set_uri (a_uri) l_http_request.process end - execute_post_request (a_uri: STRING; a_headers_map: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM) + execute_post_request (a_uri: STRING; a_headers_map: HASH_TABLE [STRING, STRING]; a_headers_text: STRING; a_socket: TCP_STREAM_SOCKET) local l_http_request : HTTP_REQUEST_HANDLER do check not_yet_implemented: False end - create {POST_REQUEST_HANDLER} l_http_request.make (a_input, a_output) + create {POST_REQUEST_HANDLER} l_http_request.make (a_socket) l_http_request.set_uri (a_uri) l_http_request.process end diff --git a/example/SimpleWebServer/request/get_request_handler.e b/example/SimpleWebServer/request/get_request_handler.e index e37d77b2..eb7f8543 100644 --- a/example/SimpleWebServer/request/get_request_handler.e +++ b/example/SimpleWebServer/request/get_request_handler.e @@ -24,18 +24,15 @@ create feature {NONE} -- Initialization - make (a_input: like input; a_output: like output) + make (a_socket: TCP_STREAM_SOCKET) do default_create - input := a_input - output := a_output + socket := a_socket end feature -- Access - input: HTTP_INPUT_STREAM - - output: HTTP_OUTPUT_STREAM + socket: TCP_STREAM_SOCKET feature -- Execution @@ -88,7 +85,7 @@ feature -- Execution end --| Output the result - output.put_string (answer.reply_header + answer.reply_text) + socket.put_string (answer.reply_header + answer.reply_text) end process_default diff --git a/example/SimpleWebServer/request/post_request_handler.e b/example/SimpleWebServer/request/post_request_handler.e index 0dadf245..478660eb 100644 --- a/example/SimpleWebServer/request/post_request_handler.e +++ b/example/SimpleWebServer/request/post_request_handler.e @@ -22,19 +22,30 @@ feature -- Execution -- process the request and create an answer local l_data: STRING - s: STRING + s: detachable STRING n: INTEGER + sock: like socket do from n := 1_024 - input.read_stream (n) - s := input.last_string + sock := socket + if sock.socket_ok then + sock.read_stream_thread_aware (n) + s := sock.last_string + else + s := Void + end create l_data.make_empty until - s.count < n + s = Void or else s.count < n loop l_data.append_string (s) - input.read_stream (n) + if sock.socket_ok then + sock.read_stream_thread_aware (n) + s := sock.last_string + else + s := Void + end end Precursor end diff --git a/example/SimpleWebServer/web_server-safe.ecf b/example/SimpleWebServer/web_server-safe.ecf index 299fd578..7b14b1cd 100644 --- a/example/SimpleWebServer/web_server-safe.ecf +++ b/example/SimpleWebServer/web_server-safe.ecf @@ -1,21 +1,22 @@ - + + /.git$ /EIFGENs$ /CVS$ /.svn$ - /.git$ - + - diff --git a/nino-safe.ecf b/nino-safe.ecf index 95fbf5ae..b76c24df 100644 --- a/nino-safe.ecf +++ b/nino-safe.ecf @@ -15,7 +15,6 @@ - - +