Tuples for the HTTP server

Overview

Each time our controller end processing some request, it must return a tuple, which tells server what to do. We need some kind of protocol to talk to server to serve proper content or handle HTTP codes (200, 404, 501, etc.).

In order to tell server what to do, we need to return a situation-specific tuple from each accessible controller method.

Types of tuples

tuple

description

{redirect, URL}

HTTP code will be set to 302, user will be redirected to URL

{content, html, Data}

Data is a valid XHTML string, which will be served to the browser. MIME type is set to text/html

{content, text, Data}

Data is a plain text string, which will be served to the browser. MIME type is set to text/plain

{json, Data}

Data will be encoded to the JSON format and sent to the browser. MIME type is set to text/plain

{template, Template}

selected Template will be expanded as a response to the request. MIME type is set to text/html

template

when skipping dispatcher, the template specified in URL will be expanded

{custom, Custom}

Custom is passed to the server. This option is for all the types the framework doesn’t handle, but server does

{error, Code}

error with code Code is generated, template responsible for this kind of error (defined in errors.conf) is expanded

{headers, Headers, RetVal}

sets the given headers in the session. Headers is a list of tuples describing which headers should be set. Currently only setting cookies is supported. The valid formats are:

{cookie, CookieName, CookieValue} - sets the cookie with the name CookieName to the value CookieValue. The expiration date is set to the end of the session, path is set to /.

{cookie, CookieName, CookieValue, CookiePath} - does the same as above, but set path to CookiePath.

{cookie, CookieName, CookieValue, CookiePath, CookieExpDate} - does the same as above, but set the expiration date to CookieExpDate. The date should be in right format: DAY, DD-MMM-YYYY HH:MM:SS GMT

{content_length, Len} - where Len is either a string or an integer - specifies the content length of the response

RetVal should be the actual returning value - one of the tuples mentioned above (like {redirect, URL} or other).

Eptic/ServerTuples (last edited 2009-07-27 10:20:25 by insane)