Icon Handling Server Requests

Information Before reading the following material, please be sure that you understand how the Elevate Web Builder Web Server and web server requests work by reading the Using the Web Server section of the Elevate Web Builder manual that is included with the Elevate Web Builder product installation.

Incoming Server Requests
When an incoming request is routed to a particular native server module and the library code is executed, an execution environment is obtained. These execution environments are cached for each server module in order to minimize module startup times.

The native server module memory is initialized once when the library is loaded and finalized when the library is unloaded. If any global initialization is required for a database engine or other support code, it should be placed in the initialization section of a source unit in the Delphi native server module project. Similarly, any global teardown code should be place in the finalization section of a source unit in the Delphi native server module project.

A global TEWBModule component instance is created for every incoming request to the web server. The incoming web server TEWBWebServerRequest instance is then routed to the TEWBModule instance's OnExecute event handler, if one is defined.

Warning Each module instance is executed in a separate thread, so you must make sure that all code included in an OnExecute event handler is completely thread-safe. Also, all native server modules are loaded into the web server process, so a fatal error such as a memory overwrite due to improper threading code in a native server module could cause the web server to fail.

Determining if a Request Is Secure

You can determine if a request is secure (using HTTPS) by examining the RequestSecure property of the incoming request.

Determining the Request Type

You can determine the request type by examining the RequestMethod property of the incoming request. HEAD requests are normally associated with static resources such as files, but they can be sent to modules when the content type of the resource being handled by the module is unknown to the client application.

Reading URL Parameters
The URL and any parameters included in the URL are specified in the request's RequestURL and RequestURLParams properties, respectively. The RequestURLParams property, however, is in its raw form. An easier way to examine the URL parameters would be to use the RequestParameters property. The RequestParameters property is a list of key-value pairs that represent all URL parameters.

Reading Request Cookies
Cookies are simple textual data that is persisted in the client across connections to the web server. Any cookies that apply to the request URL will automatically be sent by the client and will be available in the TEWBWebServerRequest RequestCookies property. The RequestCookies property is a list of key-value pairs that represent all cookies included with the request. See the Sending a Response section below for information on how to set cookies in responses.

Reading Request Content
Certain types of requests like HTTP POST requests are normally accompanied by content that is submitted as part of the request. The RequestContentType, RequestContentLength, RequestContent, and RequestContentStream properties of the request contain the content type, content length, and actual content.

HTML Form Submittals

When an HTML form is submitted to the URL for the module, the form data may be sent over using one of two formats. Depending upon value of the RequestContentType property, the web server will automatically perform some pre-processing of the incoming conent in the following ways:
  • application/x-www-form-urlencoded

    This is the default encoding for form submittals, and common for form submittals that do not include file uploads. The web server will pre-parse all textual form variables and make them accessible via the RequestFormValues property as a list of key-value pairs


  • multipart/form-data

    If a form submittal includes one or more file uploads, then the browser will use a special multi-part content encoding. The web server will still pre-parse all textual form variables and will also include any file content in the RequestContentParts property, with each file in its own TEWBHTTPContentPart instance. Each TEWBHTTPContentPart instance includes properties that can be used to determine how to deal with each content part:

    PropertyDescription
    ContentTransferEncodingThis property identifies the encoding of the file content contained in the Content and ContentStream properties. This is essential in knowing how to deal with the content.
    ContentFileNameThis property identifies the name of the file as provided by the client.
Sending a Response
The web server doesn't automatically send a response to an HTTP request once the OnExecute event handler terminates, so it is important that you send a response from within the OnExecute event handler. You can use one of several methods to send a response to the client's request:

MethodDescription
SendContentHeaderSends a response for a HEAD request.
SendCustomContentHeaderSends a custom content response for a HEAD request.
SendContentSends a UTF-8-encoded text response with a Content-Type header of "text/html; charset=utf-8" along with an optional status code and message.
SendCustomContentSends a UTF-8-encoded text response with a custom content type, encoding, and disposition.
SendRedirectSends a redirect response to a new URL along with an optional UTF-8-encoded text response with a Content-Type header of "text/html; charset=utf-8". By default, the redirect HTTP status code is 302, but you can specify a different status code.
SendErrorSends a status code and message along with an optional UTF-8-encoded text response with a Content-Type header of "text/plain; charset=utf-8".
SendContentStreamSends a UTF-8-encoded text stream response with a Content-Type header of "text/html; charset=utf-8" along with an optional status code and message.
SendCustomContentStreamSends a binary stream response with a custom content type, encoding, and disposition.

Warning If none of the above methods are called by the native server module and execution of the module terminates, the web server will not automatically send a response. This can cause the client application to hang and, eventually, time out waiting on a response that will never arrive.

Setting Cookies

As indicated above, any cookies that are stored on the client and are applicable to the request URL can be found in the RequestCookies property. You can add or modify these cookies using the TEWBWebServerRequest ResponseCookies or ResponseSessionCookies properties.

Information You must set any cookies before calling any of the TEWBWebServerRequest Send* methods detailed above, or the cookies will not be set properly on the client.
Image