From 302ae8d0307581889f981db02a16b8409aa6f215 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Wed, 27 Jul 2011 15:34:22 +0200 Subject: [PATCH] First step to extract the interface of the EWSGI specification into its own library Applied the changes --- library/server/ewsgi/ewsgi-safe.ecf | 1 + .../server/ewsgi/ewsgi_specification-safe.ecf | 18 +++++ .../{src => specification}/gw_application.e | 0 .../{src => specification}/gw_connector.e | 0 .../ewsgi/{src => specification}/gw_cookie.e | 0 .../gw_environment.e | 0 .../gw_environment_names.e | 0 .../gw_environment_variables.e | 0 .../gw_execution_variables.e | 0 .../context => specification}/gw_request.e | 0 .../gw_request_variables.e | 0 .../response => specification}/gw_response.e | 0 .../gw_uploaded_file_data.e | 0 .../context => specification}/gw_variables.e | 0 .../stream/gw_input_stream.e | 0 .../stream/gw_output_stream.e | 0 .../in_memory/gw_in_memory_response.e | 53 +++++++++++++-- .../gw_in_memory_response_application.e | 2 +- .../ewsgi/src/response/gw_buffered_response.e | 67 ++++++++++++++----- library/server/ewsgi/src/response/gw_header.e | 9 +-- .../ewsgi/src/response/gw_response_imp.e | 10 +-- 21 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 library/server/ewsgi/ewsgi_specification-safe.ecf rename library/server/ewsgi/{src => specification}/gw_application.e (100%) rename library/server/ewsgi/{src => specification}/gw_connector.e (100%) rename library/server/ewsgi/{src => specification}/gw_cookie.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_environment.e (100%) rename library/server/ewsgi/{src => specification}/gw_environment_names.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_environment_variables.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_execution_variables.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_request.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_request_variables.e (100%) rename library/server/ewsgi/{src/response => specification}/gw_response.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_uploaded_file_data.e (100%) rename library/server/ewsgi/{src/context => specification}/gw_variables.e (100%) rename library/server/ewsgi/{src => specification}/stream/gw_input_stream.e (100%) rename library/server/ewsgi/{src => specification}/stream/gw_output_stream.e (100%) diff --git a/library/server/ewsgi/ewsgi-safe.ecf b/library/server/ewsgi/ewsgi-safe.ecf index c8014c95..ce68e823 100644 --- a/library/server/ewsgi/ewsgi-safe.ecf +++ b/library/server/ewsgi/ewsgi-safe.ecf @@ -11,6 +11,7 @@ + diff --git a/library/server/ewsgi/ewsgi_specification-safe.ecf b/library/server/ewsgi/ewsgi_specification-safe.ecf new file mode 100644 index 00000000..6df5cf06 --- /dev/null +++ b/library/server/ewsgi/ewsgi_specification-safe.ecf @@ -0,0 +1,18 @@ + + + + + + /EIFGENs$ + /\.git$ + /\.svn$ + + + + + + + + + diff --git a/library/server/ewsgi/src/gw_application.e b/library/server/ewsgi/specification/gw_application.e similarity index 100% rename from library/server/ewsgi/src/gw_application.e rename to library/server/ewsgi/specification/gw_application.e diff --git a/library/server/ewsgi/src/gw_connector.e b/library/server/ewsgi/specification/gw_connector.e similarity index 100% rename from library/server/ewsgi/src/gw_connector.e rename to library/server/ewsgi/specification/gw_connector.e diff --git a/library/server/ewsgi/src/gw_cookie.e b/library/server/ewsgi/specification/gw_cookie.e similarity index 100% rename from library/server/ewsgi/src/gw_cookie.e rename to library/server/ewsgi/specification/gw_cookie.e diff --git a/library/server/ewsgi/src/context/gw_environment.e b/library/server/ewsgi/specification/gw_environment.e similarity index 100% rename from library/server/ewsgi/src/context/gw_environment.e rename to library/server/ewsgi/specification/gw_environment.e diff --git a/library/server/ewsgi/src/gw_environment_names.e b/library/server/ewsgi/specification/gw_environment_names.e similarity index 100% rename from library/server/ewsgi/src/gw_environment_names.e rename to library/server/ewsgi/specification/gw_environment_names.e diff --git a/library/server/ewsgi/src/context/gw_environment_variables.e b/library/server/ewsgi/specification/gw_environment_variables.e similarity index 100% rename from library/server/ewsgi/src/context/gw_environment_variables.e rename to library/server/ewsgi/specification/gw_environment_variables.e diff --git a/library/server/ewsgi/src/context/gw_execution_variables.e b/library/server/ewsgi/specification/gw_execution_variables.e similarity index 100% rename from library/server/ewsgi/src/context/gw_execution_variables.e rename to library/server/ewsgi/specification/gw_execution_variables.e diff --git a/library/server/ewsgi/src/context/gw_request.e b/library/server/ewsgi/specification/gw_request.e similarity index 100% rename from library/server/ewsgi/src/context/gw_request.e rename to library/server/ewsgi/specification/gw_request.e diff --git a/library/server/ewsgi/src/context/gw_request_variables.e b/library/server/ewsgi/specification/gw_request_variables.e similarity index 100% rename from library/server/ewsgi/src/context/gw_request_variables.e rename to library/server/ewsgi/specification/gw_request_variables.e diff --git a/library/server/ewsgi/src/response/gw_response.e b/library/server/ewsgi/specification/gw_response.e similarity index 100% rename from library/server/ewsgi/src/response/gw_response.e rename to library/server/ewsgi/specification/gw_response.e diff --git a/library/server/ewsgi/src/context/gw_uploaded_file_data.e b/library/server/ewsgi/specification/gw_uploaded_file_data.e similarity index 100% rename from library/server/ewsgi/src/context/gw_uploaded_file_data.e rename to library/server/ewsgi/specification/gw_uploaded_file_data.e diff --git a/library/server/ewsgi/src/context/gw_variables.e b/library/server/ewsgi/specification/gw_variables.e similarity index 100% rename from library/server/ewsgi/src/context/gw_variables.e rename to library/server/ewsgi/specification/gw_variables.e diff --git a/library/server/ewsgi/src/stream/gw_input_stream.e b/library/server/ewsgi/specification/stream/gw_input_stream.e similarity index 100% rename from library/server/ewsgi/src/stream/gw_input_stream.e rename to library/server/ewsgi/specification/stream/gw_input_stream.e diff --git a/library/server/ewsgi/src/stream/gw_output_stream.e b/library/server/ewsgi/specification/stream/gw_output_stream.e similarity index 100% rename from library/server/ewsgi/src/stream/gw_output_stream.e rename to library/server/ewsgi/specification/stream/gw_output_stream.e diff --git a/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response.e b/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response.e index 9a5bcd4e..c9179087 100644 --- a/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response.e +++ b/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response.e @@ -36,8 +36,31 @@ feature {NONE} -- Status output body.append (s) end +feature -- Status setting + + is_status_set: BOOLEAN + do + Result := status_code /= 0 + end + + set_status_code (a_code: INTEGER) + -- Set response status code + -- Should be done before sending any data back to the client + do + status_code := a_code + end + + status_code: INTEGER + -- Response status + feature -- Output operation + write_string (s: STRING) + -- Send the string `s' + do + write (s) + end + write_file_content (fn: STRING) -- Send the content of file `fn' local @@ -57,9 +80,27 @@ feature -- Output operation end end - write_header_object (h: GW_HEADER) - -- Send `header' to `output'. +feature -- Header output operation + + write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]]) + -- Send headers with status `a_status', and headers from `a_headers' + local + h: GW_HEADER + i,n: INTEGER do + set_status_code (a_status_code) + create h.make + if a_headers /= Void then + from + i := a_headers.lower + n := a_headers.upper + until + i > n + loop + h.put_header_key_value (a_headers[i].key, a_headers[i].value) + i := i + 1 + end + end header := h end @@ -67,10 +108,10 @@ feature {GW_APPLICATION} -- Commit commit (a_output: GW_OUTPUT_STREAM) do - a_output.put_status (status_code) - header.send_to (a_output) - write (body) - Precursor (a_output) + a_output.put_status_line (status_code) + a_output.put_string (header.string) + a_output.put_string (body) + a_output.flush end ;note diff --git a/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response_application.e b/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response_application.e index 7f98b878..bcb4d208 100644 --- a/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response_application.e +++ b/library/server/ewsgi/src/implementation/in_memory/gw_in_memory_response_application.e @@ -35,7 +35,7 @@ feature -- Factory Result.execution_variables.set_variable (request_count.out, "REQUEST_COUNT") end - new_response (a_output: GW_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE + new_response (req: GW_REQUEST; a_output: GW_OUTPUT_STREAM): GW_IN_MEMORY_RESPONSE do create {GW_IN_MEMORY_RESPONSE} Result.make end diff --git a/library/server/ewsgi/src/response/gw_buffered_response.e b/library/server/ewsgi/src/response/gw_buffered_response.e index 9cc43e06..4080d840 100644 --- a/library/server/ewsgi/src/response/gw_buffered_response.e +++ b/library/server/ewsgi/src/response/gw_buffered_response.e @@ -9,9 +9,6 @@ class inherit GW_RESPONSE - redefine - commit - end create {GW_APPLICATION} make @@ -33,15 +30,7 @@ feature {NONE} -- Initialization buffer_count: INTEGER -feature -- Status setting - - set_status_code (c: INTEGER) - -- Set the status code of the response - do - header.put_status (c) - end - -feature -- Output operation +feature {NONE} -- Core output operation write (s: STRING) -- Send the content of `s' @@ -71,6 +60,33 @@ feature -- Output operation end end +feature -- Status setting + + is_status_set: BOOLEAN + do + Result := status_code /= 0 + end + + set_status_code (a_code: INTEGER) + -- Set response status code + -- Should be done before sending any data back to the client + do + status_code := a_code + output.put_status_line (status_code) + --| We could also just append it to the `buffer' + end + + status_code: INTEGER + -- Response status + +feature -- Output operation + + write_string (s: STRING) + -- Send the string `s' + do + write (s) + end + write_file_content (fn: STRING) -- Send the content of file `fn' local @@ -90,12 +106,31 @@ feature -- Output operation end end - write_header_object (h: GW_HEADER) - -- Send `header' to `output'. +feature -- Header output operation + + write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]]) + -- Send headers with status `a_status', and headers from `a_headers' + local + h: GW_HEADER + i,n: INTEGER do - header := h + set_status_code (a_status_code) + create h.make + if a_headers /= Void then + from + i := a_headers.lower + n := a_headers.upper + until + i > n + loop + h.put_header_key_value (a_headers[i].key, a_headers[i].value) + i := i + 1 + end + end + write (h.string) end + feature {NONE} -- Implementation flush_buffer @@ -113,7 +148,7 @@ feature {GW_APPLICATION} -- Commit commit (a_output: GW_OUTPUT_STREAM) do flush_buffer - Precursor (a_output) + a_output.flush end ;note diff --git a/library/server/ewsgi/src/response/gw_header.e b/library/server/ewsgi/src/response/gw_header.e index a223d0a0..936f1ed7 100644 --- a/library/server/ewsgi/src/response/gw_header.e +++ b/library/server/ewsgi/src/response/gw_header.e @@ -2,7 +2,7 @@ note description: "[ Summary description for {GW_HEADER}. - Note the return status code is not part of the HTTP header + Note the return status code is not part of the HTTP header ]" legal: "See notice at end of class." status: "See notice at end of class." @@ -35,13 +35,6 @@ feature -- Access headers: LIST [STRING] -- Header's lines - send_to (res: GW_RESPONSE) - -- Send Current string representation to `a_output' - do - res.write_string (string) - --| Could be optimized - end - string: STRING -- String representation of the headers local diff --git a/library/server/ewsgi/src/response/gw_response_imp.e b/library/server/ewsgi/src/response/gw_response_imp.e index 480d6a48..e254d4e9 100644 --- a/library/server/ewsgi/src/response/gw_response_imp.e +++ b/library/server/ewsgi/src/response/gw_response_imp.e @@ -70,14 +70,6 @@ feature -- Output operation feature -- Header output operation - write_header_object (h: GW_HEADER) - -- Send `header' to `output'. - require - status_set: is_status_set - do - h.send_to (Current) - end - write_header (a_status_code: INTEGER; a_headers: detachable ARRAY [TUPLE [key: STRING; value: STRING]]) -- Send headers with status `a_status', and headers from `a_headers' local @@ -97,7 +89,7 @@ feature -- Header output operation i := i + 1 end end - write_header_object (h) + write (h.string) end feature {NONE} -- Implementation: Access