Create your custom handlers

Incoming variables

Browser can send data to the server in several ways: headers, POST variables, GET variables, COOKIES variables, etc…

With UWS, you can use this data in your blueprints. These data are stored in the Connection object. Then you just have to use the following functions:

  • GetHeader to retrieve a header value using its name (eg. “User-Agent” header stores browser data).
  • GetGETVar to retrieve a GET value. GET variables are recognizable in the URL. They are sent this way:
  • GetPOSTVar to retrieve a POST value. Basically, Post variables are sent through forms. These variables are hidden: unlike GET vars, they don’t appear in the URL.
  • GetCOOKIEVar to retrieve a COOKIE value. Cookies values are stored in Cookies. This data is stored by the browser and is shared through a whole website. You can use cookies as an authentication proof, for instance.

For each one of these functions, the name of the variable to retrieve, as String, is needed as parameter. The return value is also a String. If the variable isn’t found, the returned value is empty.

Send response

In order to provide data to the client browser, you need to send a Response.

Response can be fully qualified using response status code, cookies, content type and redirection.

First of all, you can send a basic response in a comprehensive way by using the function ConstructResponseExt and specifying the response content. Basically, this function will create a new response, fill in the content with our value and set the response status code to 200 Found.

Once the response built, you have to send it with the SendResponse function.

Warning! The time needed by the event to complete and send the response will impact the performance. If your function lasts 2000ms to be completed and to send the response, the client browser will be stuck for at least 2000ms.

Enhanced response

You can enhance your response by specifying the response code, cookies, etc…

You can use ConstructResponse tu construct an empty response. Then save its reference and complete the response with other functions

You can add a cookie to this response. Such as ConstructResponseExt, ConstructCookieExt can be used to create a Cookie object with a name and a value. Remember, this cookie will be stored in the client’s browser.

Cookie can be customized with a max age, a specific domain, etc…