From 186e5514eb15bbf785378bd9f5f58276dcee99ee Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 1 Dec 2016 21:20:14 +0100 Subject: [PATCH] If the count for put_file_content is not positive (i.e <= 0), do not send anything. Output/log more information for request handling when standalone httpd server has verbose enabled. --- .../alternatives/launcher/hello_application.e | 7 ++---- .../src/implementation/wgi_response_stream.e | 4 ++- .../server/httpd/httpd_request_handler_i.e | 25 ++++++++++++++++++- library/server/wsf/src/wsf_response.e | 6 +++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/examples/tutorial/step_2/hello/alternatives/launcher/hello_application.e b/examples/tutorial/step_2/hello/alternatives/launcher/hello_application.e index 2eaef500..5cd06165 100644 --- a/examples/tutorial/step_2/hello/alternatives/launcher/hello_application.e +++ b/examples/tutorial/step_2/hello/alternatives/launcher/hello_application.e @@ -22,13 +22,10 @@ create feature {NONE} -- Initialization initialize - local - opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS do Precursor - --| Uncomment the following 2 lines, to read options from "ewf.ini" configuration file --- create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} opts.make_from_file ("ewf.ini") --- import_service_options (opts) + --| Uncomment the following line, to read options from "ewf.ini" configuration file +-- import_service_options (create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} opts.make_from_file ("ewf.ini")) end launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) diff --git a/library/server/ewsgi/src/implementation/wgi_response_stream.e b/library/server/ewsgi/src/implementation/wgi_response_stream.e index 82bf3a6b..8dc33690 100644 --- a/library/server/ewsgi/src/implementation/wgi_response_stream.e +++ b/library/server/ewsgi/src/implementation/wgi_response_stream.e @@ -106,7 +106,9 @@ feature -- Output operation put_file_content (f: FILE; a_offset: INTEGER; a_count: INTEGER) -- Send `a_count' bytes from the content of file `f' starting at offset `a_offset'. do - output.put_file_content (f, a_offset, a_count) + if a_count > 0 then + output.put_file_content (f, a_offset, a_count) + end end flush diff --git a/library/server/httpd/httpd_request_handler_i.e b/library/server/httpd/httpd_request_handler_i.e index 6ae119df..d2598206 100644 --- a/library/server/httpd/httpd_request_handler_i.e +++ b/library/server/httpd/httpd_request_handler_i.e @@ -170,6 +170,9 @@ feature -- Status change -- Report error occurred, with optional message `m'. do has_error := True + if m /= Void and then is_verbose then + log (m.as_string_8, debug_level) + end end reset_error @@ -313,7 +316,7 @@ feature -- Execution is_persistent_connection_requested := False else if is_verbose then - log (request_header, information_level) + log_with_separation_line (request_header, information_level) end process_request (l_socket) end @@ -590,6 +593,26 @@ feature -- Output logger_set: logger = a_logger end + log_with_separation_line (m: STRING; a_level: INTEGER) + -- Log message `m'. + require + is_verbose: is_verbose + local + s: STRING + do + if is_verbose and (verbose_level & a_level) = a_level then + create s.make (m.count + 42) + s.append (create {STRING}.make_filled ('-', 40)) + s.append_character ('%N') + s.append (m) + if attached logger as l_logger then + l_logger.log (s) + else + io.put_string (s + "%N") + end + end + end + log (m: STRING; a_level: INTEGER) -- Log message `m'. require diff --git a/library/server/wsf/src/wsf_response.e b/library/server/wsf/src/wsf_response.e index faf40a4f..62be0d3e 100644 --- a/library/server/wsf/src/wsf_response.e +++ b/library/server/wsf/src/wsf_response.e @@ -389,8 +389,10 @@ feature -- Body message_writable: message_writable not_too_big: a_offset + a_count <= f.count do - wgi_response.put_file_content (f, a_offset, a_count) - increment_transfered_content_length (a_count) + if a_count > 0 then + wgi_response.put_file_content (f, a_offset, a_count) + increment_transfered_content_length (a_count) + end end feature -- Chunk body