From 80709578d64f29dfb9cb4b9fc07cae5a1a3e69ac Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 16 Jun 2015 20:34:57 +0200 Subject: [PATCH] Updated workbook Eiffel code to follow new EWF concurrent design. --- doc/workbook/basics/simple/application.e | 17 +- .../basics/simple/application_execution.e | 26 ++ doc/workbook/basics/simple_html/application.e | 57 +--- .../simple_html/application_execution.e | 66 ++++ .../generating_response/exel/application.e | 27 +- .../exel/application_execution.e | 36 +++ .../generating_response/headers/application.e | 48 +-- .../headers/application_execution.e | 57 ++++ .../generating_response/search/application.e | 163 +--------- .../search/application_execution.e | 172 ++++++++++ .../generating_response/status/application.e | 129 +------- .../status/application_execution.e | 138 ++++++++ .../handling_cookies/example/application.e | 133 +------- .../example/application_execution.e | 141 ++++++++ .../handling_request/form/get/application.e | 92 +----- .../form/get/application_execution.e | 101 ++++++ .../handling_request/form/post/application.e | 74 +---- .../form/post/application_execution.e | 83 +++++ .../headers/browser_name/application.e | 89 +---- .../browser_name/application_execution.e | 97 ++++++ .../headers/cgi_variables/application.e | 295 +---------------- .../cgi_variables/application_execution.e | 303 ++++++++++++++++++ .../headers/header_fields/application.e | 97 +----- .../header_fields/application_execution.e | 105 ++++++ .../upload_file/application.e | 49 +-- .../upload_file/application_execution.e | 58 ++++ 26 files changed, 1409 insertions(+), 1244 deletions(-) create mode 100644 doc/workbook/basics/simple/application_execution.e create mode 100644 doc/workbook/basics/simple_html/application_execution.e create mode 100644 doc/workbook/generating_response/exel/application_execution.e create mode 100644 doc/workbook/generating_response/headers/application_execution.e create mode 100644 doc/workbook/generating_response/search/application_execution.e create mode 100644 doc/workbook/generating_response/status/application_execution.e create mode 100644 doc/workbook/handling_cookies/example/application_execution.e create mode 100644 doc/workbook/handling_request/form/get/application_execution.e create mode 100644 doc/workbook/handling_request/form/post/application_execution.e create mode 100644 doc/workbook/handling_request/headers/browser_name/application_execution.e create mode 100644 doc/workbook/handling_request/headers/cgi_variables/application_execution.e create mode 100644 doc/workbook/handling_request/headers/header_fields/application_execution.e create mode 100644 doc/workbook/handling_request/upload_file/application_execution.e diff --git a/doc/workbook/basics/simple/application.e b/doc/workbook/basics/simple/application.e index 76fc8322..cf939f60 100644 --- a/doc/workbook/basics/simple/application.e +++ b/doc/workbook/basics/simple/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that Generates Plain Text" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,15 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - do - -- To send a response we need to setup, the status code and - -- the response headers. - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/plain"], ["Content-Length", "11"]>>) - res.put_string ("Hello World") - end - end diff --git a/doc/workbook/basics/simple/application_execution.e b/doc/workbook/basics/simple/application_execution.e new file mode 100644 index 00000000..28b1e2f3 --- /dev/null +++ b/doc/workbook/basics/simple/application_execution.e @@ -0,0 +1,26 @@ +note + description : "Basic Service that Generates Plain Text" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + do + -- To send a response we need to setup, the status code and + -- the response headers. + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/plain"], ["Content-Length", "11"]>>) + response.put_string ("Hello World") + end + +end diff --git a/doc/workbook/basics/simple_html/application.e b/doc/workbook/basics/simple_html/application.e index 77b1b02c..cf939f60 100644 --- a/doc/workbook/basics/simple_html/application.e +++ b/doc/workbook/basics/simple_html/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that Generate HTML" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,55 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - do - -- To send a response we need to setup, the status code and - -- the response headers. - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) - res.put_string (web_page) - end - - - web_page: STRING = "[ - - - - Resume - - - -
-
-

Objective

-

To take a position as a software engineer.

-

Experience

-

Junior Developer, Software Company (2010 - Present)

- -

Skills

-

Languages: C#, JavaScript, Python, Ruby, Eiffel

-

Frameworks: .NET, Node.js, Django, Ruby on Rails, EWF

-

Education

-

BS, Economics, My University

- -
- - - -]" - - end diff --git a/doc/workbook/basics/simple_html/application_execution.e b/doc/workbook/basics/simple_html/application_execution.e new file mode 100644 index 00000000..63204435 --- /dev/null +++ b/doc/workbook/basics/simple_html/application_execution.e @@ -0,0 +1,66 @@ +note + description : "Basic Service that Generate HTML" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + do + -- To send a response we need to setup, the status code and + -- the response headers. + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) + response.put_string (web_page) + end + + + web_page: STRING = "[ + + + + Resume + + + +
+
+

Objective

+

To take a position as a software engineer.

+

Experience

+

Junior Developer, Software Company (2010 - Present)

+ +

Skills

+

Languages: C#, JavaScript, Python, Ruby, Eiffel

+

Frameworks: .NET, Node.js, Django, Ruby on Rails, EWF

+

Education

+

BS, Economics, My University

+ +
+ + + +]" + + +end diff --git a/doc/workbook/generating_response/exel/application.e b/doc/workbook/generating_response/exel/application.e index ffd55d2b..cf939f60 100644 --- a/doc/workbook/generating_response/exel/application.e +++ b/doc/workbook/generating_response/exel/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that show how to use common Status Code" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,25 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - do - -- To send a response we need to setup, the status code and - -- the response headers. - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/csv"],["Content-Disposition","attachment;filename=Report.xls"],["Content-Length", sheet.count.out]>>) - res.put_string (sheet) - end - - -- ,["Content-Disposition","attachment;filename=Report.xls"] - - - sheet: STRING ="[ - Q1 Q2 Q3 Q4 Total -Cherries 78 87 92 29 =SUM(B2:E2) -Grapes 77 86 93 30 =SUM(B3:E3) - ]" - - end diff --git a/doc/workbook/generating_response/exel/application_execution.e b/doc/workbook/generating_response/exel/application_execution.e new file mode 100644 index 00000000..3c93fb5a --- /dev/null +++ b/doc/workbook/generating_response/exel/application_execution.e @@ -0,0 +1,36 @@ +note + description : "Basic Service that show how to use common Status Code" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + do + -- To send a response we need to setup, the status code and + -- the response headers. + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/csv"],["Content-Disposition","attachment;filename=Report.xls"],["Content-Length", sheet.count.out]>>) + response.put_string (sheet) + end + + -- ,["Content-Disposition","attachment;filename=Report.xls"] + + + sheet: STRING ="[ + Q1 Q2 Q3 Q4 Total +Cherries 78 87 92 29 =SUM(B2:E2) +Grapes 77 86 93 30 =SUM(B3:E3) + ]" + + +end diff --git a/doc/workbook/generating_response/headers/application.e b/doc/workbook/generating_response/headers/application.e index 6e28c660..cf939f60 100644 --- a/doc/workbook/generating_response/headers/application.e +++ b/doc/workbook/generating_response/headers/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that build a generic front end for the most used search engines." - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,46 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_message: STRING - do - -- (1) To send a response we need to setup, the status code and the response headers. --- res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) --- res.put_string (web_page) - - -- (2) Using put_header_line --- res.set_status_code ({HTTP_STATUS_CODE}.ok) --- res.put_header_line ("Content-Type:text/html") - res.put_header_line ("Content-Length:"+ web_page.count.out) - res.put_header_line ("Content-Type:text/plain") - - res.put_string (web_page) - end - - - -feature -- Home Page - - web_page: STRING = "[ - - - - EWF Headers Responses - - -
-

Example Header Response

-

Response headers

- -
- - - -]" end diff --git a/doc/workbook/generating_response/headers/application_execution.e b/doc/workbook/generating_response/headers/application_execution.e new file mode 100644 index 00000000..5b042d53 --- /dev/null +++ b/doc/workbook/generating_response/headers/application_execution.e @@ -0,0 +1,57 @@ +note + description : "Basic Service that build a generic front end for the most used search engines." + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_message: STRING + do + -- (1) To send a response we need to setup, the status code and the response headers. +-- response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) +-- response.put_string (web_page) + + -- (2) Using put_header_line +-- response.set_status_code ({HTTP_STATUS_CODE}.ok) +-- response.put_header_line ("Content-Type:text/html") + response.put_header_line ("Content-Length:"+ web_page.count.out) + response.put_header_line ("Content-Type:text/plain") + + response.put_string (web_page) + end + + + +feature -- Home Page + + web_page: STRING = "[ + + + + EWF Headers Responses + + +
+

Example Header Response

+

Response headers

+ +
+ + + +]" +end diff --git a/doc/workbook/generating_response/search/application.e b/doc/workbook/generating_response/search/application.e index 60a85660..cf939f60 100644 --- a/doc/workbook/generating_response/search/application.e +++ b/doc/workbook/generating_response/search/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that build a generic front end for the most used search engines." - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,161 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_message: STRING - do - -- To send a response we need to setup, the status code and - -- the response headers. - if req.is_get_request_method then - if req.path_info.same_string ("/") then - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) - res.put_string (web_page) - else - send_resouce_not_found (req, res) - end - elseif req.is_post_request_method then - if req.path_info.same_string ("/search") then - if attached {WSF_STRING} req.form_parameter ("query") as l_query then - if attached {WSF_STRING} req.form_parameter ("engine") as l_engine then - if attached {STRING} map.at (l_engine.value) as l_engine_url then - l_engine_url.append (l_query.value) - send_redirect (req, res, l_engine_url) - -- res.redirect_now (l_engine_url) - else - send_bad_request (req, res, " search engine: " + l_engine.value + " not supported,
try with Google or Bing") - end - else - send_bad_request (req, res, " search engine not selected") - end - else - send_bad_request (req, res, " form_parameter query is not present") - end - else - send_resouce_not_found (req, res) - end - else - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Method Not Allowed") - l_message.replace_substring_all ("$status", "Method Not Allowed 405") - -- Method not allowed - res.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - end - end - - -feature -- Engine Map - - map : STRING_TABLE[STRING] - do - create Result.make (2) - Result.put ("http://www.google.com/search?q=", "Google") - Result.put ("http://www.bing.com/search?q=", "Bing") - end - -feature -- Redirect - - send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32) - -- Redirect to `a_location' - local - h: HTTP_HEADER - do - create h.make - h.put_content_type_text_html - h.put_current_date - h.put_location (a_location) - res.set_status_code ({HTTP_STATUS_CODE}.see_other) - res.put_header_text (h.string) - end - -feature -- Bad Request - - send_bad_request (req: WSF_REQUEST; res: WSF_RESPONSE; description: STRING) - local - l_message: STRING - do - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Bad Request") - l_message.replace_substring_all ("$status", "Bad Request" + description) - res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - end - -feature -- Resource not found - - send_resouce_not_found (req: WSF_REQUEST; res: WSF_RESPONSE) - local - l_message: STRING - do - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Resource not found") - l_message.replace_substring_all ("$status", "Resource " + req.request_uri + " not found 404") - res.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - end - -feature -- Home Page - - web_page: STRING = "[ - - - - Generic Search Engine - - -
-

Generic Search Engine

-
-
- Search:
-
- -
- -
- -

-
- -
- - -
- - - -]" - -feature -- Generic Message - - message_template: STRING="[ - - - - $title - - - -
-
-

This page is an example of $status

- - - - -]" - - - - end diff --git a/doc/workbook/generating_response/search/application_execution.e b/doc/workbook/generating_response/search/application_execution.e new file mode 100644 index 00000000..1e3ebe08 --- /dev/null +++ b/doc/workbook/generating_response/search/application_execution.e @@ -0,0 +1,172 @@ +note + description : "Basic Service that build a generic front end for the most used search engines." + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_message: STRING + do + -- To send a response we need to setup, the status code and + -- the response headers. + if request.is_get_request_method then + if request.path_info.same_string ("/") then + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) + response.put_string (web_page) + else + send_resouce_not_found (request, response) + end + elseif request.is_post_request_method then + if request.path_info.same_string ("/search") then + if attached {WSF_STRING} request.form_parameter ("query") as l_query then + if attached {WSF_STRING} request.form_parameter ("engine") as l_engine then + if attached {STRING} map.at (l_engine.value) as l_engine_url then + l_engine_url.append (l_query.value) + send_redirect (request, response, l_engine_url) + -- response.redirect_now (l_engine_url) + else + send_bad_request (request, response, " search engine: " + l_engine.value + " not supported,
try with Google or Bing") + end + else + send_bad_request (request, response, " search engine not selected") + end + else + send_bad_request (request, response, " form_parameter query is not present") + end + else + send_resouce_not_found (request, response) + end + else + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Method Not Allowed") + l_message.replace_substring_all ("$status", "Method Not Allowed 405") + -- Method not allowed + response.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + response.put_string (l_message) + end + end + + +feature -- Engine Map + + map : STRING_TABLE[STRING] + do + create Result.make (2) + Result.put ("http://www.google.com/search?q=", "Google") + Result.put ("http://www.bing.com/search?q=", "Bing") + end + +feature -- Redirect + + send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32) + -- Redirect to `a_location' + local + h: HTTP_HEADER + do + create h.make + h.put_content_type_text_html + h.put_current_date + h.put_location (a_location) + res.set_status_code ({HTTP_STATUS_CODE}.see_other) + res.put_header_text (h.string) + end + +feature -- Bad Request + + send_bad_request (req: WSF_REQUEST; res: WSF_RESPONSE; description: STRING) + local + l_message: STRING + do + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Bad Request") + l_message.replace_substring_all ("$status", "Bad Request" + description) + res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + res.put_string (l_message) + end + +feature -- Resource not found + + send_resouce_not_found (req: WSF_REQUEST; res: WSF_RESPONSE) + local + l_message: STRING + do + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Resource not found") + l_message.replace_substring_all ("$status", "Resource " + req.request_uri + " not found 404") + res.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + res.put_string (l_message) + end + +feature -- Home Page + + web_page: STRING = "[ + + + + Generic Search Engine + + +
+

Generic Search Engine

+
+
+ Search:
+
+ +
+ +
+ +

+
+ +
+ + +
+ + + +]" + +feature -- Generic Message + + message_template: STRING="[ + + + + $title + + + +
+
+

This page is an example of $status

+ + + + +]" + + + + +end diff --git a/doc/workbook/generating_response/status/application.e b/doc/workbook/generating_response/status/application.e index 7aa03ac9..cf939f60 100644 --- a/doc/workbook/generating_response/status/application.e +++ b/doc/workbook/generating_response/status/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that a simple web page to show the most common status codes" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,127 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_message: STRING - do - -- To send a response we need to setup, the status code and - -- the response headers. - if req.is_get_request_method then - if req.path_info.same_string ("/") then - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) - res.put_string (web_page) - elseif req.path_info.same_string ("/redirect") then - send_redirect (req, res, "https://httpwg.github.io/") - elseif req.path_info.same_string ("/bad_request") then - -- Here you can do some logic for example log, send emails to register the error, before to send the response. - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Bad Request") - l_message.replace_substring_all ("$status", "Bad Request 400") - res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - elseif req.path_info.same_string ("/internal_error") then - -- Here you can do some logic for example log, send emails to register the error, before to send the response. - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Internal Server Error") - l_message.replace_substring_all ("$status", "Internal Server Error 500") - res.put_header ({HTTP_STATUS_CODE}.internal_server_error, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - else - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Resource not found") - l_message.replace_substring_all ("$status", "Resource not found 400") - res.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - end - else - create l_message.make_from_string (message_template) - l_message.replace_substring_all ("$title", "Method Not Allowed") - l_message.replace_substring_all ("$status", "Method Not Allowed 405") - -- Method not allowed - res.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) - res.put_string (l_message) - end - end - - -feature -- Home Page - - send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32) - -- Redirect to `a_location' - local - h: HTTP_HEADER - do - create h.make - h.put_content_type_text_html - h.put_current_date - h.put_location (a_location) - res.set_status_code ({HTTP_STATUS_CODE}.see_other) - res.put_header_text (h.string) - end - - web_page: STRING = "[ - - - - Example showing common status codes - - - -
-
-

This page is an example of Status Code 200

- -

Redirect Example

-

Click on the following link will redirect you to the HTTP Specifcation, we can do the redirect from the HTML directly but - here we want to show you an exmaple, where you can do something before to send a redirect Redirect

- -

Bad Request

-

Click on the following link, the server will answer with a 400 error, check the status code Bad Request

- -

Internal Server Error

-

Click on the following link, the server will answer with a 500 error, check the status code Internal Error

- -

Resource not found

-

Click on the following link or add to the end of the url something like /1030303 the server will answer with a 404 error, check the status code Not found

- -
- - - -]" - -feature -- Generic Message - - message_template: STRING="[ - - - - $title - - - -
-
-

This page is an example of $status

- - - - -]" - - - - end diff --git a/doc/workbook/generating_response/status/application_execution.e b/doc/workbook/generating_response/status/application_execution.e new file mode 100644 index 00000000..691513b6 --- /dev/null +++ b/doc/workbook/generating_response/status/application_execution.e @@ -0,0 +1,138 @@ +note + description : "Basic Service that a simple web page to show the most common status codes" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_message: STRING + do + -- To send a response we need to setup, the status code and + -- the response headers. + if request.is_get_request_method then + if request.path_info.same_string ("/") then + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>) + response.put_string (web_page) + elseif request.path_info.same_string ("/redirect") then + send_redirect (request, response, "https://httpwg.github.io/") + elseif request.path_info.same_string ("/bad_request") then + -- Here you can do some logic for example log, send emails to register the error, before to send the response. + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Bad Request") + l_message.replace_substring_all ("$status", "Bad Request 400") + response.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + response.put_string (l_message) + elseif request.path_info.same_string ("/internal_error") then + -- Here you can do some logic for example log, send emails to register the error, before to send the response. + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Internal Server Error") + l_message.replace_substring_all ("$status", "Internal Server Error 500") + response.put_header ({HTTP_STATUS_CODE}.internal_server_error, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + response.put_string (l_message) + else + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Resource not found") + l_message.replace_substring_all ("$status", "Resource not found 400") + response.put_header ({HTTP_STATUS_CODE}.not_found, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + response.put_string (l_message) + end + else + create l_message.make_from_string (message_template) + l_message.replace_substring_all ("$title", "Method Not Allowed") + l_message.replace_substring_all ("$status", "Method Not Allowed 405") + -- Method not allowed + response.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<["Content-Type", "text/html"], ["Content-Length", l_message.count.out]>>) + response.put_string (l_message) + end + end + + +feature -- Home Page + + send_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32) + -- Redirect to `a_location' + local + h: HTTP_HEADER + do + create h.make + h.put_content_type_text_html + h.put_current_date + h.put_location (a_location) + res.set_status_code ({HTTP_STATUS_CODE}.see_other) + res.put_header_text (h.string) + end + + web_page: STRING = "[ + + + + Example showing common status codes + + + +
+
+

This page is an example of Status Code 200

+ +

Redirect Example

+

Click on the following link will redirect you to the HTTP Specifcation, we can do the redirect from the HTML directly but + here we want to show you an exmaple, where you can do something before to send a redirect Redirect

+ +

Bad Request

+

Click on the following link, the server will answer with a 400 error, check the status code Bad Request

+ +

Internal Server Error

+

Click on the following link, the server will answer with a 500 error, check the status code Internal Error

+ +

Resource not found

+

Click on the following link or add to the end of the url something like /1030303 the server will answer with a 404 error, check the status code Not found

+ +
+ + + +]" + +feature -- Generic Message + + message_template: STRING="[ + + + + $title + + + +
+
+

This page is an example of $status

+ + + + +]" + + + + +end diff --git a/doc/workbook/handling_cookies/example/application.e b/doc/workbook/handling_cookies/example/application.e index 267333c4..cf939f60 100644 --- a/doc/workbook/handling_cookies/example/application.e +++ b/doc/workbook/handling_cookies/example/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that build a generic front to demonstrate the use of Cookies" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -21,133 +19,6 @@ feature {NONE} -- Initialization -- Initialize current service. do set_service_option ("port", 9090) - set_service_option ("verbose",True) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_message: STRING - l_header: HTTP_HEADER - l_time: HTTP_DATE - l_cookies: STRING - l_answer: STRING - do - -- all the cookies - create l_cookies.make_empty - across req.cookies as ic loop - l_cookies.append (ic.item.name) - l_cookies.append("
") - end - - if req.path_info.same_string ("/") then - create l_header.make - create l_answer.make_from_string (web_page) - if req.cookie ("_EWF_Cookie") = Void then - -- First access the the home page, find a cookie with specific name `_EWF_Cookie' - l_answer.replace_substring_all ("$header_title", "Hey, thanks for access our cool site, this is your first acess") - l_answer.replace_substring_all ("$cookies", l_cookies) - create l_time.make_now_utc - l_time.date_time.day_add (40) - l_header.put_cookie_with_expiration_date ("_EWF_Cookie", "EXAMPLE",l_time.date_time, "", Void, False, True) - else - -- No a new access - l_answer.replace_substring_all ("$header_title", "Welcome back, please check all the new things we have!!!") - l_answer.replace_substring_all ("$cookies", l_cookies) - end - l_header.put_content_type_text_html - l_header.put_content_length (l_answer.count) - res.put_header_text (l_header.string) - res.put_string (l_answer) - - elseif req.path_info.same_string ("/visitors") then - create l_header.make - create l_answer.make_from_string (visit_page) - if req.cookie ("_visits") = Void then - -- First access the the visit page, find a cookie with specific name `_visits' - l_answer.replace_substring_all ("$visit", "1") - l_answer.replace_substring_all ("$cookies", l_cookies) - create l_time.make_now_utc - l_time.date_time.day_add (40) - l_header.put_cookie_with_expiration_date ("_visits", "1",l_time.date_time, "/visitors", Void, False, True) - - else - if attached {WSF_STRING} req.cookie ("_visits") as l_visit then - create l_time.make_now_utc - l_time.date_time.day_add (40) - l_answer.replace_substring_all ("$visit", (l_visit.value.to_integer + 1).out ) - l_answer.replace_substring_all ("$cookies", l_cookies) - l_header.put_cookie_with_expiration_date ("_visits", (l_visit.value.to_integer + 1).out,l_time.date_time, "/visitors", Void, False, True) - end - end - create l_time.make_now_utc - l_time.date_time.second_add (120) - l_header.put_content_type_text_html - -- This cookie expires in 120 seconds, its valid for 120 seconds - l_header.put_cookie_with_expiration_date ("_Framework", "EWF",l_time.date_time, "/", Void, False, True) - -- This is a session cookie, valid only to the current browsing session. - l_header.put_cookie ("Session", "Cookie",Void, "/", Void, False, True) - l_header.put_content_length (l_answer.count) - res.add_header_text (l_header.string) - res.put_string (l_answer) - end - - end - -feature -- Home Page - - web_page: STRING = "[ - - - - EWF Handling Cookies - - -
-

$header_title

-
- -
- Visitors -
- -
-

Cookies for the home page

- $cookies -
- - -]" - - -visit_page: STRING = "[ - - - - EWF Handling Visit Page - - -
-

The number of visits is $visit

-
- -
-

Cookies for the Visit page

- $cookies -
-
- -
- Back to Home -
- - - - -]" - end diff --git a/doc/workbook/handling_cookies/example/application_execution.e b/doc/workbook/handling_cookies/example/application_execution.e new file mode 100644 index 00000000..56562904 --- /dev/null +++ b/doc/workbook/handling_cookies/example/application_execution.e @@ -0,0 +1,141 @@ +note + description : "Basic Service that build a generic front to demonstrate the use of Cookies" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_message: STRING + l_header: HTTP_HEADER + l_time: HTTP_DATE + l_cookies: STRING + l_answer: STRING + do + -- all the cookies + create l_cookies.make_empty + across request.cookies as ic loop + l_cookies.append (ic.item.name) + l_cookies.append("
") + end + + if request.path_info.same_string ("/") then + create l_header.make + create l_answer.make_from_string (web_page) + if request.cookie ("_EWF_Cookie") = Void then + -- First access the the home page, find a cookie with specific name `_EWF_Cookie' + l_answer.replace_substring_all ("$header_title", "Hey, thanks for access our cool site, this is your first acess") + l_answer.replace_substring_all ("$cookies", l_cookies) + create l_time.make_now_utc + l_time.date_time.day_add (40) + l_header.put_cookie_with_expiration_date ("_EWF_Cookie", "EXAMPLE",l_time.date_time, "", Void, False, True) + else + -- No a new access + l_answer.replace_substring_all ("$header_title", "Welcome back, please check all the new things we have!!!") + l_answer.replace_substring_all ("$cookies", l_cookies) + end + l_header.put_content_type_text_html + l_header.put_content_length (l_answer.count) + response.put_header_text (l_header.string) + response.put_string (l_answer) + + elseif request.path_info.same_string ("/visitors") then + create l_header.make + create l_answer.make_from_string (visit_page) + if request.cookie ("_visits") = Void then + -- First access the the visit page, find a cookie with specific name `_visits' + l_answer.replace_substring_all ("$visit", "1") + l_answer.replace_substring_all ("$cookies", l_cookies) + create l_time.make_now_utc + l_time.date_time.day_add (40) + l_header.put_cookie_with_expiration_date ("_visits", "1",l_time.date_time, "/visitors", Void, False, True) + + else + if attached {WSF_STRING} request.cookie ("_visits") as l_visit then + create l_time.make_now_utc + l_time.date_time.day_add (40) + l_answer.replace_substring_all ("$visit", (l_visit.value.to_integer + 1).out ) + l_answer.replace_substring_all ("$cookies", l_cookies) + l_header.put_cookie_with_expiration_date ("_visits", (l_visit.value.to_integer + 1).out,l_time.date_time, "/visitors", Void, False, True) + end + end + create l_time.make_now_utc + l_time.date_time.second_add (120) + l_header.put_content_type_text_html + -- This cookie expires in 120 seconds, its valid for 120 seconds + l_header.put_cookie_with_expiration_date ("_Framework", "EWF",l_time.date_time, "/", Void, False, True) + -- This is a session cookie, valid only to the current browsing session. + l_header.put_cookie ("Session", "Cookie",Void, "/", Void, False, True) + l_header.put_content_length (l_answer.count) + response.add_header_text (l_header.string) + response.put_string (l_answer) + end + + end + +feature -- Home Page + + web_page: STRING = "[ + + + + EWF Handling Cookies + + +
+

$header_title

+
+ +
+ Visitors +
+ +
+

Cookies for the home page

+ $cookies +
+ + +]" + + +visit_page: STRING = "[ + + + + EWF Handling Visit Page + + +
+

The number of visits is $visit

+
+ +
+

Cookies for the Visit page

+ $cookies +
+
+ +
+ Back to Home +
+ + + + +]" + +end diff --git a/doc/workbook/handling_request/form/get/application.e b/doc/workbook/handling_request/form/get/application.e index c857a0d8..cf939f60 100644 --- a/doc/workbook/handling_request/form/get/application.e +++ b/doc/workbook/handling_request/form/get/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that show how to handle a GET request" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,90 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - file: WSF_FILE_RESPONSE - l_parameter_names: STRING - l_answer: STRING - idioms: LIST[STRING] - l_raw_data: STRING - do - if req.is_get_request_method then - if req.path_info.same_string ("/") then - create file.make_html ("form.html") - res.send (file) - elseif req.path_info.same_string ("/search") then - - -- (1) the parameter is case sensitive - if not (attached req.query_parameter ("GIVEN-NAME")) then - -- Wrong `GIVEN-NAME' need to be in lower case. - end - - -- (2) Multiple values - if attached {WSF_MULTIPLE_STRING} req.query_parameter ("languages") as l_languages then - -- Get all the associated values - create {ARRAYED_LIST[STRING]} idioms.make (2) - across l_languages as ic loop idioms.force (ic.item.value) end - elseif attached {WSF_STRING} req.query_parameter ("languages") as l_language then - -- Single value - print (l_language.value) - else - -- Value Missing - end - - -- Read the all parameters names and his values. - create l_parameter_names.make_from_string ("

Parameters Names

") - l_parameter_names.append ("
") - create l_answer.make_from_string ("

Parameter Names and Values

") - l_answer.append ("
") - across req.query_parameters as ic loop - l_parameter_names.append (ic.item.key) - l_parameter_names.append ("
") - - l_answer.append (ic.item.key) - l_answer.append_character ('=') - if attached {WSF_STRING} req.query_parameter (ic.item.key) as l_value then - l_answer.append_string (l_value.value) - end - l_answer.append ("
") - end - - l_parameter_names.append ("
") - l_parameter_names.append_string (l_answer) - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>) - res.put_string (l_parameter_names) - elseif req.path_info.same_string ("/link") then - -- WSF_TABLE example - create l_parameter_names.make_from_string ("

Parameters Name

") - if attached {WSF_TABLE} req.query_parameter ("tab") as l_tab then - l_parameter_names.append ("
") - l_parameter_names.append (l_tab.name) - - from - l_tab.values.start - until - l_tab.values.after - loop - l_parameter_names.append ("
") - l_parameter_names.append (l_tab.values.key_for_iteration) - if attached {WSF_STRING} l_tab.value (l_tab.values.key_for_iteration) as l_value then - l_parameter_names.append ("=") - l_parameter_names.append (l_value.value) - end - l_tab.values.forth - end - l_parameter_names.append ("
") - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>) - res.put_string (l_parameter_names) - - end - else - -- Here we should handle unexpected errors. - end - end - end - end diff --git a/doc/workbook/handling_request/form/get/application_execution.e b/doc/workbook/handling_request/form/get/application_execution.e new file mode 100644 index 00000000..1fb05acd --- /dev/null +++ b/doc/workbook/handling_request/form/get/application_execution.e @@ -0,0 +1,101 @@ +note + description : "Basic Service that show how to handle a GET request" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + file: WSF_FILE_RESPONSE + l_parameter_names: STRING + l_answer: STRING + idioms: LIST[STRING] + l_raw_data: STRING + do + if request.is_get_request_method then + if request.path_info.same_string ("/") then + create file.make_html ("form.html") + response.send (file) + elseif request.path_info.same_string ("/search") then + + -- (1) the parameter is case sensitive + if not (attached request.query_parameter ("GIVEN-NAME")) then + -- Wrong `GIVEN-NAME' need to be in lower case. + end + + -- (2) Multiple values + if attached {WSF_MULTIPLE_STRING} request.query_parameter ("languages") as l_languages then + -- Get all the associated values + create {ARRAYED_LIST[STRING]} idioms.make (2) + across l_languages as ic loop idioms.force (ic.item.value) end + elseif attached {WSF_STRING} request.query_parameter ("languages") as l_language then + -- Single value + print (l_language.value) + else + -- Value Missing + end + + -- Read the all parameters names and his values. + create l_parameter_names.make_from_string ("

Parameters Names

") + l_parameter_names.append ("
") + create l_answer.make_from_string ("

Parameter Names and Values

") + l_answer.append ("
") + across request.query_parameters as ic loop + l_parameter_names.append (ic.item.key) + l_parameter_names.append ("
") + + l_answer.append (ic.item.key) + l_answer.append_character ('=') + if attached {WSF_STRING} request.query_parameter (ic.item.key) as l_value then + l_answer.append_string (l_value.value) + end + l_answer.append ("
") + end + + l_parameter_names.append ("
") + l_parameter_names.append_string (l_answer) + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>) + response.put_string (l_parameter_names) + elseif request.path_info.same_string ("/link") then + -- WSF_TABLE example + create l_parameter_names.make_from_string ("

Parameters Name

") + if attached {WSF_TABLE} request.query_parameter ("tab") as l_tab then + l_parameter_names.append ("
") + l_parameter_names.append (l_tab.name) + + from + l_tab.values.start + until + l_tab.values.after + loop + l_parameter_names.append ("
") + l_parameter_names.append (l_tab.values.key_for_iteration) + if attached {WSF_STRING} l_tab.value (l_tab.values.key_for_iteration) as l_value then + l_parameter_names.append ("=") + l_parameter_names.append (l_value.value) + end + l_tab.values.forth + end + l_parameter_names.append ("
") + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>) + response.put_string (l_parameter_names) + + end + else + -- Here we should handle unexpected errors. + end + end + end + +end diff --git a/doc/workbook/handling_request/form/post/application.e b/doc/workbook/handling_request/form/post/application.e index b388f390..cf939f60 100644 --- a/doc/workbook/handling_request/form/post/application.e +++ b/doc/workbook/handling_request/form/post/application.e @@ -1,13 +1,11 @@ note - description : "Reading Parameters from a HTML FORM (method POST) " - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,72 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - file: WSF_FILE_RESPONSE - l_parameter_names: STRING - l_answer: STRING - idioms: LIST[STRING] - l_raw_data: STRING - do - if req.is_get_request_method then - create file.make_html ("form.html") - res.send (file) - elseif req.is_post_request_method then - req.set_raw_input_data_recorded (True) - - -- (3) Read Raw Data - create l_raw_data.make_empty - req.read_input_data_into (l_raw_data) - - -- (1) the parameter is case sensitive - if not (attached req.form_parameter ("GIVEN-NAME")) then - -- Wrong `GIVEN-NAME' need to be in lower case. - end - - -- (2) Multiple values - if attached {WSF_MULTIPLE_STRING} req.form_parameter ("languages") as l_languages then - -- Get all the associated values - create {ARRAYED_LIST[STRING]} idioms.make (2) - across l_languages as ic loop idioms.force (ic.item.value) end - elseif attached {WSF_STRING} req.form_parameter ("langauges") as l_language then - -- Single value - print (l_language.value) - else - -- Value Missing - end - - -- Read the all parameters names and his values. - create l_parameter_names.make_from_string ("

Parameters Names

") - l_parameter_names.append ("
") - create l_answer.make_from_string ("

Parameter Names and Values

") - l_answer.append ("
") - - across req.form_parameters as ic loop - l_parameter_names.append (ic.item.key) - l_parameter_names.append ("
") - - l_answer.append (ic.item.key) - l_answer.append_character ('=') - if attached {WSF_STRING} req.form_parameter (ic.item.key) as l_value then - l_answer.append_string (l_value.value) - end - l_answer.append ("
") - end - - l_parameter_names.append ("
") - l_parameter_names.append_string (l_answer) - l_parameter_names.append ("
") - l_parameter_names.append ("

Raw content

") - l_parameter_names.append (l_raw_data) - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>) - res.put_string (l_parameter_names) - else - -- Here we should handle unexpected errors. - end - end - end diff --git a/doc/workbook/handling_request/form/post/application_execution.e b/doc/workbook/handling_request/form/post/application_execution.e new file mode 100644 index 00000000..d893804e --- /dev/null +++ b/doc/workbook/handling_request/form/post/application_execution.e @@ -0,0 +1,83 @@ +note + description : "Reading Parameters from a HTML FORM (method POST) " + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + file: WSF_FILE_RESPONSE + l_parameter_names: STRING + l_answer: STRING + idioms: LIST[STRING] + l_raw_data: STRING + do + if request.is_get_request_method then + create file.make_html ("form.html") + response.send (file) + elseif request.is_post_request_method then + request.set_raw_input_data_recorded (True) + + -- (3) Read Raw Data + create l_raw_data.make_empty + request.read_input_data_into (l_raw_data) + + -- (1) the parameter is case sensitive + if not (attached request.form_parameter ("GIVEN-NAME")) then + -- Wrong `GIVEN-NAME' need to be in lower case. + end + + -- (2) Multiple values + if attached {WSF_MULTIPLE_STRING} request.form_parameter ("languages") as l_languages then + -- Get all the associated values + create {ARRAYED_LIST[STRING]} idioms.make (2) + across l_languages as ic loop idioms.force (ic.item.value) end + elseif attached {WSF_STRING} request.form_parameter ("langauges") as l_language then + -- Single value + print (l_language.value) + else + -- Value Missing + end + + -- Read the all parameters names and his values. + create l_parameter_names.make_from_string ("

Parameters Names

") + l_parameter_names.append ("
") + create l_answer.make_from_string ("

Parameter Names and Values

") + l_answer.append ("
") + + across request.form_parameters as ic loop + l_parameter_names.append (ic.item.key) + l_parameter_names.append ("
") + + l_answer.append (ic.item.key) + l_answer.append_character ('=') + if attached {WSF_STRING} request.form_parameter (ic.item.key) as l_value then + l_answer.append_string (l_value.value) + end + l_answer.append ("
") + end + + l_parameter_names.append ("
") + l_parameter_names.append_string (l_answer) + l_parameter_names.append ("
") + l_parameter_names.append ("

Raw content

") + l_parameter_names.append (l_raw_data) + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>) + response.put_string (l_parameter_names) + else + -- Here we should handle unexpected errors. + end + end + +end diff --git a/doc/workbook/handling_request/headers/browser_name/application.e b/doc/workbook/handling_request/headers/browser_name/application.e index d793f479..cf939f60 100644 --- a/doc/workbook/handling_request/headers/browser_name/application.e +++ b/doc/workbook/handling_request/headers/browser_name/application.e @@ -1,14 +1,11 @@ note - description : "Basic Service that Read a Request, a " - date : "$Date$" - revision : "$Revision$" - EIS: "name=Browser detection using user agent","src=https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent", "protocol=url" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -22,88 +19,6 @@ feature {NONE} -- Initialization -- Initialize current service. do set_service_option ("port", 9090) - set_service_option ("verbose", true) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_raw_data: STRING - l_page_response: STRING - l_rows: STRING - do - create l_page_response.make_from_string (html_template) - if req.path_info.same_string ("/") then - - -- retrieve the user-agent - if attached req.http_user_agent as l_user_agent then - l_page_response.replace_substring_all ("$user_agent", l_user_agent) - l_page_response.replace_substring_all ("$browser", get_browser_name (l_user_agent)) - else - l_page_response.replace_substring_all ("$user_agent", "[]") - l_page_response.replace_substring_all ("$browser", "Unknown, the user-agent was not present.") - end - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>) - res.put_string (l_page_response) - end - end - - -feature -- Browser utility - - get_browser_name (a_user_agent: READABLE_STRING_8):READABLE_STRING_32 - -- Must contain Must not contain - -- Firefox Firefox/xyz Seamonkey/xyz - -- Seamonkey Seamonkey/xyz - -- Chrome Chrome/xyz Chromium/xyz - -- Chromium Chromium/xyz - -- Safari Safari/xyz Chrome/xyz - -- Chromium/xyz - -- Opera OPR/xyz [1] - -- Opera/xyz [2] - -- Internet Explorer ;MSIE xyz; Internet Explorer doesn't put its name in the BrowserName/VersionNumber format - - do - if - a_user_agent.has_substring ("Firefox") and then - not a_user_agent.has_substring ("Seamonkey") - then - Result := "Firefox" - elseif a_user_agent.has_substring ("Seamonkey") then - Result := "Seamonkey" - elseif a_user_agent.has_substring ("Chrome") and then not a_user_agent.has_substring ("Chromium")then - Result := "Chrome" - elseif a_user_agent.has_substring ("Chromium") then - Result := "Chromiun" - elseif a_user_agent.has_substring ("Safari") and then not (a_user_agent.has_substring ("Chrome") or else a_user_agent.has_substring ("Chromium")) then - Result := "Safari" - elseif a_user_agent.has_substring ("OPR") or else a_user_agent.has_substring ("Opera") then - Result := "Opera" - elseif a_user_agent.has_substring ("MSIE") or else a_user_agent.has_substring ("Trident")then - Result := "Internet Explorer" - else - Result := "Unknown" - end - end - - - html_template: STRING = "[ - - - - - - -

EWF service example: Showing Browser Dectection Using User-Agent


- - User Agent: $user_agent
- -

Enjoy using $browser

- - - ]" - - end diff --git a/doc/workbook/handling_request/headers/browser_name/application_execution.e b/doc/workbook/handling_request/headers/browser_name/application_execution.e new file mode 100644 index 00000000..8ef85fd0 --- /dev/null +++ b/doc/workbook/handling_request/headers/browser_name/application_execution.e @@ -0,0 +1,97 @@ +note + description : "Basic Service that Read a Request, a " + date : "$Date$" + revision : "$Revision$" + EIS: "name=Browser detection using user agent","src=https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent", "protocol=url" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_raw_data: STRING + l_page_response: STRING + l_rows: STRING + do + create l_page_response.make_from_string (html_template) + if request.path_info.same_string ("/") then + + -- retrieve the user-agent + if attached request.http_user_agent as l_user_agent then + l_page_response.replace_substring_all ("$user_agent", l_user_agent) + l_page_response.replace_substring_all ("$browser", browser_name (l_user_agent)) + else + l_page_response.replace_substring_all ("$user_agent", "[]") + l_page_response.replace_substring_all ("$browser", "Unknown, the user-agent was not present.") + end + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>) + response.put_string (l_page_response) + end + end + + +feature -- Browser utility + + browser_name (a_user_agent: READABLE_STRING_8): STRING_8 + -- Must contain Must not contain + -- Firefox Firefox/xyz Seamonkey/xyz + -- Seamonkey Seamonkey/xyz + -- Chrome Chrome/xyz Chromium/xyz + -- Chromium Chromium/xyz + -- Safari Safari/xyz Chrome/xyz + -- Chromium/xyz + -- Opera OPR/xyz [1] + -- Opera/xyz [2] + -- Internet Explorer ;MSIE xyz; Internet Explorer doesn't put its name in the BrowserName/VersionNumber format + + do + if + a_user_agent.has_substring ("Firefox") and then + not a_user_agent.has_substring ("Seamonkey") + then + Result := "Firefox" + elseif a_user_agent.has_substring ("Seamonkey") then + Result := "Seamonkey" + elseif a_user_agent.has_substring ("Chrome") and then not a_user_agent.has_substring ("Chromium")then + Result := "Chrome" + elseif a_user_agent.has_substring ("Chromium") then + Result := "Chromiun" + elseif a_user_agent.has_substring ("Safari") and then not (a_user_agent.has_substring ("Chrome") or else a_user_agent.has_substring ("Chromium")) then + Result := "Safari" + elseif a_user_agent.has_substring ("OPR") or else a_user_agent.has_substring ("Opera") then + Result := "Opera" + elseif a_user_agent.has_substring ("MSIE") or else a_user_agent.has_substring ("Trident")then + Result := "Internet Explorer" + else + Result := "Unknown" + end + end + + + html_template: STRING = "[ + + + + + + +

EWF service example: Showing Browser Dectection Using User-Agent


+ + User Agent: $user_agent
+ +

Enjoy using $browser

+ + + ]" + + +end diff --git a/doc/workbook/handling_request/headers/cgi_variables/application.e b/doc/workbook/handling_request/headers/cgi_variables/application.e index 718d5770..cf939f60 100644 --- a/doc/workbook/handling_request/headers/cgi_variables/application.e +++ b/doc/workbook/handling_request/headers/cgi_variables/application.e @@ -1,14 +1,11 @@ note - description : "Basic Service that shows the standard CGI variables" - date : "$Date$" - revision : "$Revision$" - EIS: "name=CGI specification","src=(https://tools.ietf.org/html/rfc3875", "protocol=url" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -22,294 +19,6 @@ feature {NONE} -- Initialization -- Initialize current service. do set_service_option ("port", 9090) - set_service_option ("verbose", true) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_raw_data: STRING - l_page_response: STRING - l_rows: STRING - do - create l_page_response.make_from_string (html_template) - if req.path_info.same_string ("/") then - - -- HTTP method - l_page_response.replace_substring_all ("$http_method", req.request_method) - -- URI - l_page_response.replace_substring_all ("$uri", req.path_info) - -- Protocol - l_page_response.replace_substring_all ("$protocol", req.server_protocol) - - -- Fill the table rows with CGI standard variables - create l_rows.make_empty - - -- Auth_type - l_rows.append ("") - l_rows.append ("") - l_rows.append ("AUTH_TYPE") - l_rows.append ("") - l_rows.append ("") - if attached req.auth_type as l_type then - l_rows.append (l_type) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - - -- Content length - l_rows.append ("") - l_rows.append ("") - l_rows.append ("CONTENT_LENGTH") - l_rows.append ("") - l_rows.append ("") - if attached req.content_length as l_content_length then - l_rows.append (l_content_length) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - -- Content length - l_rows.append ("") - l_rows.append ("") - l_rows.append ("CONTENT_TYPE") - l_rows.append ("") - l_rows.append ("") - if attached req.content_type as l_content_type then - l_rows.append (l_content_type.string) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - - -- Gateway interface - l_rows.append ("") - l_rows.append ("") - l_rows.append ("GATEWAY_INTERFACE") - l_rows.append ("") - l_rows.append ("") - if attached req.gateway_interface as l_gateway_interface then - l_rows.append (l_gateway_interface) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - - -- Path info - l_rows.append ("") - l_rows.append ("") - l_rows.append ("PATH_INFO") - l_rows.append ("") - l_rows.append ("") - if attached req.path_info as l_path_info then - l_rows.append (l_path_info) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - -- Path translated - l_rows.append ("") - l_rows.append ("") - l_rows.append ("PATH_TRANSLATED") - l_rows.append ("") - l_rows.append ("") - if attached req.path_translated as l_path_translated then - l_rows.append (l_path_translated) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - -- Query string - l_rows.append ("") - l_rows.append ("") - l_rows.append ("QUERY_STRING") - l_rows.append ("") - l_rows.append ("") - if attached req.query_string as l_query_string then - l_rows.append (l_query_string) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - -- Remote addr - l_rows.append ("") - l_rows.append ("") - l_rows.append ("REMOTE_ADDR") - l_rows.append ("") - l_rows.append ("") - l_rows.append (req.remote_addr) - l_rows.append ("") - l_rows.append ("") - - - -- Remote host - l_rows.append ("") - l_rows.append ("") - l_rows.append ("REMOTE_HOST") - l_rows.append ("") - l_rows.append ("") - if attached req.remote_host as l_remote_host then - l_rows.append (l_remote_host) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - - - -- Remote ident - l_rows.append ("") - l_rows.append ("") - l_rows.append ("REMOTE_IDENT") - l_rows.append ("") - l_rows.append ("") - if attached req.remote_ident as l_remote_ident then - l_rows.append (l_remote_ident) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - - -- Remote user - l_rows.append ("") - l_rows.append ("") - l_rows.append ("REMOTE_USER") - l_rows.append ("") - l_rows.append ("") - if attached req.remote_user as l_remote_user then - l_rows.append (l_remote_user) - else - l_rows.append ("Not present") - end - l_rows.append ("") - l_rows.append ("") - - - -- Request method - l_rows.append ("") - l_rows.append ("") - l_rows.append ("REQUEST_METHOD") - l_rows.append ("") - l_rows.append ("") - l_rows.append (req.request_method) - l_rows.append ("") - l_rows.append ("") - - - -- Script name - l_rows.append ("") - l_rows.append ("") - l_rows.append ("SCRIPT_NAME") - l_rows.append ("") - l_rows.append ("") - l_rows.append (req.script_name) - l_rows.append ("") - l_rows.append ("") - - -- Server name - l_rows.append ("") - l_rows.append ("") - l_rows.append ("SERVER_NAME") - l_rows.append ("") - l_rows.append ("") - l_rows.append (req.server_name) - l_rows.append ("") - l_rows.append ("") - - -- Server protocol - l_rows.append ("") - l_rows.append ("") - l_rows.append ("SERVER_PROTOCOL") - l_rows.append ("") - l_rows.append ("") - l_rows.append (req.server_protocol) - l_rows.append ("") - l_rows.append ("") - - -- Server software - l_rows.append ("") - l_rows.append ("") - l_rows.append ("SERVER_SOFTWARE") - l_rows.append ("") - l_rows.append ("") - l_rows.append (req.server_software) - l_rows.append ("") - l_rows.append ("") - - - l_page_response.replace_substring_all ("$rows", l_rows) - - -- Reading the raw header - if attached req.raw_header_data as l_raw_header then - l_page_response.replace_substring_all ("$raw_header", l_raw_header) - end - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>) - res.put_string (l_page_response) - end - end - - - - html_template: STRING = "[ - - - - - - - -

EWF service example: Showing Standard CGI Variables

- - HTTP METHOD:$http_method
- URI:$uri
- PROTOCOL:$protocol
- -
- - - - - - - - - $rows - -
CGI NameValue
- - -

Raw header

- - $raw_header - - - ]" - - end diff --git a/doc/workbook/handling_request/headers/cgi_variables/application_execution.e b/doc/workbook/handling_request/headers/cgi_variables/application_execution.e new file mode 100644 index 00000000..10063855 --- /dev/null +++ b/doc/workbook/handling_request/headers/cgi_variables/application_execution.e @@ -0,0 +1,303 @@ +note + description : "Basic Service that shows the standard CGI variables" + date : "$Date$" + revision : "$Revision$" + EIS: "name=CGI specification","src=(https://tools.ietf.org/html/rfc3875", "protocol=url" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_raw_data: STRING + l_page_response: STRING + l_rows: STRING + do + create l_page_response.make_from_string (html_template) + if request.path_info.same_string ("/") then + + -- HTTP method + l_page_response.replace_substring_all ("$http_method", request.request_method) + -- URI + l_page_response.replace_substring_all ("$uri", request.path_info) + -- Protocol + l_page_response.replace_substring_all ("$protocol", request.server_protocol) + + -- Fill the table rows with CGI standard variables + create l_rows.make_empty + + -- Auth_type + l_rows.append ("") + l_rows.append ("") + l_rows.append ("AUTH_TYPE") + l_rows.append ("") + l_rows.append ("") + if attached request.auth_type as l_type then + l_rows.append (l_type) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + + -- Content length + l_rows.append ("") + l_rows.append ("") + l_rows.append ("CONTENT_LENGTH") + l_rows.append ("") + l_rows.append ("") + if attached request.content_length as l_content_length then + l_rows.append (l_content_length) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + -- Content length + l_rows.append ("") + l_rows.append ("") + l_rows.append ("CONTENT_TYPE") + l_rows.append ("") + l_rows.append ("") + if attached request.content_type as l_content_type then + l_rows.append (l_content_type.string) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + + -- Gateway interface + l_rows.append ("") + l_rows.append ("") + l_rows.append ("GATEWAY_INTERFACE") + l_rows.append ("") + l_rows.append ("") + if attached request.gateway_interface as l_gateway_interface then + l_rows.append (l_gateway_interface) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + + -- Path info + l_rows.append ("") + l_rows.append ("") + l_rows.append ("PATH_INFO") + l_rows.append ("") + l_rows.append ("") + if attached request.path_info as l_path_info then + l_rows.append (l_path_info) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + -- Path translated + l_rows.append ("") + l_rows.append ("") + l_rows.append ("PATH_TRANSLATED") + l_rows.append ("") + l_rows.append ("") + if attached request.path_translated as l_path_translated then + l_rows.append (l_path_translated) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + -- Query string + l_rows.append ("") + l_rows.append ("") + l_rows.append ("QUERY_STRING") + l_rows.append ("") + l_rows.append ("") + if attached request.query_string as l_query_string then + l_rows.append (l_query_string) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + -- Remote addr + l_rows.append ("") + l_rows.append ("") + l_rows.append ("REMOTE_ADDR") + l_rows.append ("") + l_rows.append ("") + l_rows.append (request.remote_addr) + l_rows.append ("") + l_rows.append ("") + + + -- Remote host + l_rows.append ("") + l_rows.append ("") + l_rows.append ("REMOTE_HOST") + l_rows.append ("") + l_rows.append ("") + if attached request.remote_host as l_remote_host then + l_rows.append (l_remote_host) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + + + -- Remote ident + l_rows.append ("") + l_rows.append ("") + l_rows.append ("REMOTE_IDENT") + l_rows.append ("") + l_rows.append ("") + if attached request.remote_ident as l_remote_ident then + l_rows.append (l_remote_ident) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + + -- Remote user + l_rows.append ("") + l_rows.append ("") + l_rows.append ("REMOTE_USER") + l_rows.append ("") + l_rows.append ("") + if attached request.remote_user as l_remote_user then + l_rows.append (l_remote_user) + else + l_rows.append ("Not present") + end + l_rows.append ("") + l_rows.append ("") + + + -- Request method + l_rows.append ("") + l_rows.append ("") + l_rows.append ("REQUEST_METHOD") + l_rows.append ("") + l_rows.append ("") + l_rows.append (request.request_method) + l_rows.append ("") + l_rows.append ("") + + + -- Script name + l_rows.append ("") + l_rows.append ("") + l_rows.append ("SCRIPT_NAME") + l_rows.append ("") + l_rows.append ("") + l_rows.append (request.script_name) + l_rows.append ("") + l_rows.append ("") + + -- Server name + l_rows.append ("") + l_rows.append ("") + l_rows.append ("SERVER_NAME") + l_rows.append ("") + l_rows.append ("") + l_rows.append (request.server_name) + l_rows.append ("") + l_rows.append ("") + + -- Server protocol + l_rows.append ("") + l_rows.append ("") + l_rows.append ("SERVER_PROTOCOL") + l_rows.append ("") + l_rows.append ("") + l_rows.append (request.server_protocol) + l_rows.append ("") + l_rows.append ("") + + -- Server software + l_rows.append ("") + l_rows.append ("") + l_rows.append ("SERVER_SOFTWARE") + l_rows.append ("") + l_rows.append ("") + l_rows.append (request.server_software) + l_rows.append ("") + l_rows.append ("") + + + l_page_response.replace_substring_all ("$rows", l_rows) + + -- Reading the raw header + if attached request.raw_header_data as l_raw_header then + l_page_response.replace_substring_all ("$raw_header", l_raw_header) + end + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>) + response.put_string (l_page_response) + end + end + + + + html_template: STRING = "[ + + + + + + + +

EWF service example: Showing Standard CGI Variables

+ + HTTP METHOD:$http_method
+ URI:$uri
+ PROTOCOL:$protocol
+ +
+ + + + + + + + + $rows + +
CGI NameValue
+ + +

Raw header

+ + $raw_header + + + ]" + + +end diff --git a/doc/workbook/handling_request/headers/header_fields/application.e b/doc/workbook/handling_request/headers/header_fields/application.e index 4d0729b0..cf939f60 100644 --- a/doc/workbook/handling_request/headers/header_fields/application.e +++ b/doc/workbook/handling_request/headers/header_fields/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that Read Request Headers" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -21,97 +19,6 @@ feature {NONE} -- Initialization -- Initialize current service. do set_service_option ("port", 9090) - set_service_option ("verbose", true) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - l_raw_data: STRING - l_page_response: STRING - l_rows: STRING - do - create l_page_response.make_from_string (html_template) - if req.path_info.same_string ("/") then - - -- HTTP method - l_page_response.replace_substring_all ("$http_method", req.request_method) - -- URI - l_page_response.replace_substring_all ("$uri", req.path_info) - -- Protocol - l_page_response.replace_substring_all ("$protocol", req.server_protocol) - - -- Fill the table rows with HTTP Headers - create l_rows.make_empty - across req.meta_variables as ic loop - if ic.item.name.starts_with ("HTTP_") then - l_rows.append ("") - l_rows.append ("") - l_rows.append (ic.item.name) - l_rows.append ("") - l_rows.append ("") - l_rows.append (ic.item.value) - l_rows.append ("") - l_rows.append ("") - end - end - - l_page_response.replace_substring_all ("$rows", l_rows) - - -- Reading the raw header - if attached req.raw_header_data as l_raw_header then - l_page_response.replace_substring_all ("$raw_header", l_raw_header) - end - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>) - res.put_string (l_page_response) - end - end - - - - html_template: STRING = "[ - - - - - - - -

EWF service example: Showing Request Headers

- - HTTP METHOD:$http_method
- URI:$uri
- PROTOCOL:$protocol
- REQUEST TIME:$time
- -
- - - - - - - - - $rows - -
Header NameHeader Value
- - -

Raw header

- - $raw_header - - - ]" - - end diff --git a/doc/workbook/handling_request/headers/header_fields/application_execution.e b/doc/workbook/handling_request/headers/header_fields/application_execution.e new file mode 100644 index 00000000..9f3242fc --- /dev/null +++ b/doc/workbook/handling_request/headers/header_fields/application_execution.e @@ -0,0 +1,105 @@ +note + description : "Basic Service that Read Request Headers" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + l_raw_data: STRING + l_page_response: STRING + l_rows: STRING + do + create l_page_response.make_from_string (html_template) + if request.path_info.same_string ("/") then + + -- HTTP method + l_page_response.replace_substring_all ("$http_method", request.request_method) + -- URI + l_page_response.replace_substring_all ("$uri", request.path_info) + -- Protocol + l_page_response.replace_substring_all ("$protocol", request.server_protocol) + + -- Fill the table rows with HTTP Headers + create l_rows.make_empty + across request.meta_variables as ic loop + if ic.item.name.starts_with ("HTTP_") then + l_rows.append ("") + l_rows.append ("") + l_rows.append (ic.item.name) + l_rows.append ("") + l_rows.append ("") + l_rows.append (ic.item.value) + l_rows.append ("") + l_rows.append ("") + end + end + + l_page_response.replace_substring_all ("$rows", l_rows) + + -- Reading the raw header + if attached request.raw_header_data as l_raw_header then + l_page_response.replace_substring_all ("$raw_header", l_raw_header) + end + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>) + response.put_string (l_page_response) + end + end + + + + html_template: STRING = "[ + + + + + + + +

EWF service example: Showing Request Headers

+ + HTTP METHOD:$http_method
+ URI:$uri
+ PROTOCOL:$protocol
+ REQUEST TIME:$time
+ +
+ + + + + + + + + $rows + +
Header NameHeader Value
+ + +

Raw header

+ + $raw_header + + + ]" + + +end diff --git a/doc/workbook/handling_request/upload_file/application.e b/doc/workbook/handling_request/upload_file/application.e index b37c0790..cf939f60 100644 --- a/doc/workbook/handling_request/upload_file/application.e +++ b/doc/workbook/handling_request/upload_file/application.e @@ -1,13 +1,11 @@ note - description : "Basic Service that show how to Upload a file" - date : "$Date$" - revision : "$Revision$" + description: "Basic Service launcher" class APPLICATION inherit - WSF_DEFAULT_SERVICE + WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION] redefine initialize end @@ -23,47 +21,4 @@ feature {NONE} -- Initialization set_service_option ("port", 9090) end -feature -- Basic operations - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- Execute the incomming request - local - file: WSF_FILE_RESPONSE - l_answer: STRING - do - if req.is_get_request_method then - if req.path_info.same_string ("/") then - create file.make_html ("upload.html") - res.send (file) - else - -- Here we should handle unexpected errors. - end - elseif req.is_post_request_method then - if req.path_info.same_string ("/upload") then - -- Check if we have an uploaded file - if req.has_uploaded_file then - -- iterate over all the uploaded files - create l_answer.make_from_string ("

Uploaded File/s


") - across req.uploaded_files as ic loop - l_answer.append ("FileName:") - l_answer.append (ic.item.filename) - l_answer.append ("
Size:") - l_answer.append (ic.item.size.out) - l_answer.append ("
") - end - res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>) - res.put_string (l_answer) - else - -- Here we should handle unexpected errors. - create l_answer.make_from_string ("No uploaded files
") - create l_answer.append ("Back to Home") - res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>) - res.put_string (l_answer) - end - else - -- Handle error - end - end - end - end diff --git a/doc/workbook/handling_request/upload_file/application_execution.e b/doc/workbook/handling_request/upload_file/application_execution.e new file mode 100644 index 00000000..8186494e --- /dev/null +++ b/doc/workbook/handling_request/upload_file/application_execution.e @@ -0,0 +1,58 @@ +note + description : "Basic Service that show how to Upload a file" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION_EXECUTION + +inherit + WSF_EXECUTION + +create + make + +feature -- Basic operations + + execute + -- Execute the incomming request + local + file: WSF_FILE_RESPONSE + l_answer: STRING + do + if request.is_get_request_method then + if request.path_info.same_string ("/") then + create file.make_html ("upload.html") + response.send (file) + else + -- Here we should handle unexpected errors. + end + elseif request.is_post_request_method then + if request.path_info.same_string ("/upload") then + -- Check if we have an uploaded file + if request.has_uploaded_file then + -- iterate over all the uploaded files + create l_answer.make_from_string ("

Uploaded File/s


") + across request.uploaded_files as ic loop + l_answer.append ("FileName:") + l_answer.append (ic.item.filename) + l_answer.append ("
Size:") + l_answer.append (ic.item.size.out) + l_answer.append ("
") + end + response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>) + response.put_string (l_answer) + else + -- Here we should handle unexpected errors. + create l_answer.make_from_string ("No uploaded files
") + l_answer.append ("Back to Home") + response.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>) + response.put_string (l_answer) + end + else + -- Handle error + end + end + end + +end