diff --git a/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e b/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e index 54762849..ee025be4 100644 --- a/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e +++ b/library/server/ewsgi/specification/stream/wgi_chunked_input_stream.e @@ -151,7 +151,7 @@ feature {NONE} -- Parser end end ensure - attached last_chunk as l_last_chunk implies l_last_chunk.count = chunk_upper - chunk_lower + attached last_chunk as l_last_chunk implies l_last_chunk.count = chunk_upper - chunk_lower + 1 end read_chunk_data diff --git a/library/server/wsf/tests/server/test.e b/library/server/wsf/tests/server/test.e new file mode 100644 index 00000000..5cd52363 --- /dev/null +++ b/library/server/wsf/tests/server/test.e @@ -0,0 +1,59 @@ +class + TEST + +inherit + WSF_DEFAULT_SERVICE + + TEST_SERVICE + +create + make + +feature {NONE} -- Initialization + + make + -- Initialize `Current'. + do + print ("Test Server that could be used for autotest%N") +-- base_url := "/test/" + + set_service_option ("port", 9091) + set_service_option ("verbose", True) + make_and_launch + end + +feature -- Helper + + server_log_path: STRING + local + fn: FILE_NAME + once + create fn.make_from_string ("server_test.log") + Result := fn.string + end + + server_log (m: STRING_8) + local + f: RAW_FILE + do + create f.make (server_log_path) + f.open_append + f.put_string (m) + f.put_character ('%N') + f.close + end + + base_url: detachable STRING + + test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8 + local + b: like base_url + do + b := base_url + if b = Void then + b := "" + end + Result := "/" + b + a_query_url + end + +end diff --git a/library/server/wsf/tests/server/test_service.e b/library/server/wsf/tests/server/test_service.e new file mode 100644 index 00000000..716e0b51 --- /dev/null +++ b/library/server/wsf/tests/server/test_service.e @@ -0,0 +1,191 @@ +note + description: "Summary description for {}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + TEST_SERVICE + +inherit + WSF_SERVICE + +feature -- Execution + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + local + q: detachable STRING_32 + n: NATURAL_64 + page: WSF_PAGE_RESPONSE + log_res: WSF_LOGGER_RESPONSE_WRAPPER + do + debug + server_log (req.request_uri) + if attached req.content_type as l_content_type then + server_log ("content_type:" + l_content_type.string) + end + end + if attached req.http_expect as l_expect and then l_expect.same_string ("100-continue") then + (create {EXECUTION_ENVIRONMENT}).sleep (900_000_000) -- 900 milliseconds + end + + create page.make + if attached req.request_uri as l_uri then + if l_uri.starts_with (test_url ("get/01")) then + page.set_status_code (200) + page.header.put_content_type_text_plain + page.put_string ("get-01") + create q.make_empty + + across + req.query_parameters as qcur + loop + if not q.is_empty then + q.append_character ('&') + end + q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation) + end + if not q.is_empty then + page.put_string ("(" + q + ")") + end + elseif l_uri.starts_with (test_url ("post/01")) then + page.put_header (200, <<["Content-Type", "text/plain"]>>) + page.put_string ("post-01") + create q.make_empty + + across + req.query_parameters as qcur + loop + if not q.is_empty then + q.append_character ('&') + end + q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation) + end + + if not q.is_empty then + page.put_string ("(" + q + ")") + end + + create q.make_empty +-- req.set_raw_input_data_recorded (True) + + across + req.form_parameters as fcur + loop + debug + server_log ("%Tform: " + fcur.item.name) + end + if not q.is_empty then + q.append_character ('&') + end + q.append (fcur.item.name.as_string_32 + "=" + fcur.item.string_representation) + end + +-- if attached req.raw_input_data as d then +-- server_log ("Raw data=" + d) +-- end + + if not q.is_empty then + page.put_string (" : " + q ) + end + elseif l_uri.starts_with (test_url ("post/file/01")) then + page.put_header (200, <<["Content-Type", "text/plain"]>>) + page.put_string ("post-file-01") + n := req.content_length_value + if n > 0 then + req.input.read_string (n.to_integer_32) + q := req.input.last_string + page.put_string ("%N" + q) + end + else + page.put_header (200, <<["Content-Type", "text/plain"]>>) + page.put_string ("Hello") + end + else + page.put_header (200, <<["Content-Type", "text/plain"]>>) + page.put_string ("Bye") + end + + if + attached new_file (req, "output.log") as l_out and + attached new_file (req, "error.log") as l_err + then + create log_res.make_from_response (res, l_out, l_err) + log_res.send (page) + + l_out.close + l_err.close + else + check False end + res.send (page) + end + end + + new_file (req: WSF_REQUEST; a_suffix: STRING): detachable FILE + local + dp, p, fp: FILE_NAME + d: DIRECTORY + i: INTEGER + f: detachable FILE + retried: INTEGER + do + if retried = 0 then + create dp.make_from_string ("logs") + create d.make (dp.string) + if not d.exists then + d.recursive_create_dir + end + if attached req.request_time_stamp as t then + create p.make_from_string (t.out) + else + create p.make_from_string ("") + end + + from + i := 0 + create fp.make_from_string (dp.string) + if p.is_empty then + fp.set_file_name (p.string + a_suffix) + else + fp.set_file_name (p.string + "-" + a_suffix) + end + create {PLAIN_TEXT_FILE} f.make (fp.string) + until + not f.exists + loop + i := i + 1 + create fp.make_from_string (dp.string) + if p.is_empty then + fp.set_file_name (p.string + i.out + "-" + a_suffix) + else + fp.set_file_name (p.string + "_" + i.out + "-" + a_suffix) + end + + f.make (fp.string) + end + f.open_write + elseif retried < 5 then + + -- Eventually another request created the file at the same time .. + f := new_file (req, a_suffix) + else + f := Void + end + Result := f + rescue + retried := retried + 1 + retry + end + +feature -- Helper + + server_log (s: STRING) + deferred + end + + test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8 + deferred + end + +end + diff --git a/library/server/wsf/tests/src/test_wsf_request.e b/library/server/wsf/tests/src/test_wsf_request.e index 96b7e3a5..8d086b67 100644 --- a/library/server/wsf/tests/src/test_wsf_request.e +++ b/library/server/wsf/tests/src/test_wsf_request.e @@ -17,7 +17,7 @@ inherit on_clean end - WSF_SERVICE + TEST_SERVICE undefine default_create end @@ -36,19 +36,26 @@ feature {NONE} -- Events wt: WORKER_THREAD e: EXECUTION_ENVIRONMENT do --- port_number := 9091 - port_number := 0 - base_url := "test/" - create app.make_custom (to_wgi_service, base_url) - web_app := app - - create wt.make (agent app.listen (port_number)) - wt.launch - create e - e.sleep (1_000_000_000 * 5) +-- port_number := 9091 -- Uncomment to use with server outside this process + if port_number = 0 then + server_log ("== Current directory: " + e.current_working_directory) - port_number := app.port + port_number := 0 + base_url := "/test/" + create app.make_custom (to_wgi_service, base_url) + web_app := app + + create wt.make (agent app.listen (port_number)) + wt.launch + e.sleep (1_000_000_000 * 5) + port_number := app.port + server_log ("Server port=" + port_number.out) + else + server_log ("Use existing server") + server_log ("== Current directory: " + e.current_working_directory) + + end end server_log_name: STRING @@ -74,99 +81,6 @@ feature {NONE} -- Events f.close end - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - local - q: detachable STRING_32 - n: NATURAL_64 - page: WSF_PAGE_RESPONSE - do - debug - server_log (req.request_uri) - if attached req.content_type as l_content_type then - server_log ("content_type:" + l_content_type.string) - end - end - - create page.make - if attached req.request_uri as l_uri then - if l_uri.starts_with (test_url ("get/01")) then - page.set_status_code (200) - page.header.put_content_type_text_plain - page.put_string ("get-01") - create q.make_empty - - across - req.query_parameters as qcur - loop - if not q.is_empty then - q.append_character ('&') - end - q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation) - end - if not q.is_empty then - page.put_string ("(" + q + ")") - end - elseif l_uri.starts_with (test_url ("post/01")) then - page.put_header (200, <<["Content-Type", "text/plain"]>>) - page.put_string ("post-01") - create q.make_empty - - across - req.query_parameters as qcur - loop - if not q.is_empty then - q.append_character ('&') - end - q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation) - end - - if not q.is_empty then - page.put_string ("(" + q + ")") - end - - create q.make_empty --- req.set_raw_input_data_recorded (True) - - across - req.form_parameters as fcur - loop - debug - server_log ("%Tform: " + fcur.item.name) - end - if not q.is_empty then - q.append_character ('&') - end - q.append (fcur.item.name.as_string_32 + "=" + fcur.item.string_representation) - end - --- if attached req.raw_input_data as d then --- server_log ("Raw data=" + d) --- end - - if not q.is_empty then - page.put_string (" : " + q ) - end - elseif l_uri.starts_with (test_url ("post/file/01")) then - page.put_header (200, <<["Content-Type", "text/plain"]>>) - page.put_string ("post-file-01") - n := req.content_length_value - if n > 0 then - req.input.read_string (n.to_integer_32) - q := req.input.last_string - page.put_string ("%N" + q) - end - else - page.put_header (200, <<["Content-Type", "text/plain"]>>) - page.put_string ("Hello") - end - else - page.put_header (200, <<["Content-Type", "text/plain"]>>) - page.put_string ("Bye") - end - - res.send (page) - end - test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8 local b: like base_url @@ -175,7 +89,7 @@ feature {NONE} -- Events if b = Void then b := "" end - Result := "/" + b + a_query_url + Result := b + a_query_url end on_clean diff --git a/library/server/wsf/tests/src/test_wsf_request_chunked_input.e b/library/server/wsf/tests/src/test_wsf_request_chunked_input.e index 5ee75346..945ca8e8 100644 --- a/library/server/wsf/tests/src/test_wsf_request_chunked_input.e +++ b/library/server/wsf/tests/src/test_wsf_request_chunked_input.e @@ -23,7 +23,7 @@ feature {NONE} -- Helpers adapted_context (ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_REQUEST_CONTEXT do Result := Precursor (ctx) - Result.headers.extend ("chunked", "Transfer-Encoding") + Result.headers.force ("chunked", "Transfer-Encoding") end feature -- Test routines diff --git a/library/server/wsf/tests/tests-safe.ecf b/library/server/wsf/tests/tests-safe.ecf index 63d3bafc..43f331af 100644 --- a/library/server/wsf/tests/tests-safe.ecf +++ b/library/server/wsf/tests/tests-safe.ecf @@ -1,25 +1,37 @@ - - - + + + /.git$ /EIFGENs$ /.svn$ - - - - + + + + + - + + + + + + + diff --git a/library/server/wsf/tests/tests.ecf b/library/server/wsf/tests/tests.ecf index 2afa7055..3eb67794 100644 --- a/library/server/wsf/tests/tests.ecf +++ b/library/server/wsf/tests/tests.ecf @@ -1,7 +1,7 @@ - - + + /.git$ /EIFGENs$ @@ -14,12 +14,16 @@ - - - + + + - + + + + +