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