Processing Requests

EiffelWeb provides a complete set of features and interface which helps building a wide range of possible requests.

Basic CGI Handling

Accessing Environment Variables

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:

  • Getting information about the server itself
  • Checking the client browser
  • Restricting Access for specified Domains
  • Ensuring User Authentication and Identifications
  • Dealing with Cookies

Accessing Input Values

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.

Sending answers to the browser

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.

Dealing with Cookies

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.

Advanced Topics

EiffelWeb and Security

The information the server sends back may be confidential. Follow these steps to protect the page content:

  1. Create an HTML page, for example by using class HTML_PAGE.
  2. Store this page somewhere, with a random name.
  3. Create an instance of class CGI_RESPONSE_HEADER and choose the secure redirect option. Then call send_to_browser.

Complex Headers

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_TYPES .

Debugging facilities

Design by Contract is one of the greatest strengths of the Eiffel programming 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.

cached: 11/21/2024 8:42:40.000 AM