EiffelWeb provides a complete set of features and interface which helps building a wide range of possible requests.
Much of the information needed by CGI applications is made
available via environment variables. Programs using EiffelWeb can access this
information through the class
CGI_ENVIRONMENT.
These variables are usually used for the following purposes:
The browser sends in the In a stream containing the data relative to the user entry and selection at the applications starts. EiffelWeb stores each data element and its associated name within a Hash-Table, the feature form_data of class CGI_INTERFACE. You can access their values from your code with the interface defined in class CGI_FORMS, which allows you to retrieve text entries, to know whether a button was pressed or not, etc …
The response has to contain an HTTP header in order to be understood by the browser. Depending on the nature of the reply, an HTML page, a simple re-direction, an error notification … you will select different features and options. Your application must send at least a response header, indicating the status of the request if known. You may want to attach to it the text you wish to send back to the user. This text is usually written in HTML, so that it will display nicely on the user’s browser; you can use for this purpose the class HTML_PAGE. You may then send the header followed by your text using the features send_to_browser of classes CGI_RESPONSE_HEADER and HTML_PAGE.
Note: You may not write into a file before you have sent the answer to the browser.
You can access the cookies corresponding to a specific URL/domain thanks to the feature cookies, of class CGI_ENVIRONMENT. It is a hash-table, in which all the data with associated names as keys are stored.
To store a cookie on a machine, you can use the feature set_cookies, of class CGI_RESPONSE_HEADER.
The information the server sends back may be confidential. Follow these steps to protect the page content:
The Eiffel-Web application has the possibility to send a selection of different HTTP headers. They can be found in class CGI_RESPONSE_HEADER. In particular, it is advised to generate a status for each request, the value of the most common ones may be found in class CGI_COMMON_STATUS_TYPE.
Design by Contract is one of the greatest strengths of the Eiffel language. When
you usually run your application from EiffelStudio, you are notified when an
assertion is violated and the tool offers different options in order to be able
to find out its sources (feature and class tools, object inspectors, etc…).
However this cannot be applied to an EiffelWeb application, since it has to be
run on the server.
Therefore, EiffelWeb provides its own facilities for debugging. To test your
classes at run-time, all you need to do is to set the Boolean feature
is_debug_mode to
True in your root class (which should inherit from
CGI_INTERFACE). When your application crashes (because of an assertion or
a bug), the exception trace will be displayed on the screen.