WebGate

Creating Responses
Login

Creating Responses

Each request handler is expected to return an instance of the response structure type that has a SRFI-99 definition similar to the following one:

  (define-record-type (response message)
    #f #t
    status status-message)

A response is actually a subtype of a message (see Interpreting Parameters) and inherits its type, headers and body fields. In addition the message specifies the status code and status line message that should be returned to the webserver.

To create a response, you can use any of the following procedures:

  (make-response STATUS BODY [#:type TYPE] [#:headers HEADERS] [#:status-message STATUS-MESSAGE]) => RESPONSE
Creates a message given a numeric STATUS code and a string BODY. Optionally you may specify a content TYPE (which you probably should, since the default is application/octet-stream), additional HEADERS or an explicit STATUS-MESSAGE (the default is derived from the STATUS code).
  (collect-response STATUS THUNK [#:type TYPE] [#:headers HEADERS] [#:status-message STATUS-MESSAGE]) => RESPONSE
Works similar to make-response except that the message body is computed by invoking THUNK, which is expected to write the desired content to the current output port.
  (make-html-response STATUS HTML [#:headers HEADERS] [#:status-message STATUS-MESSAGE]) => RESPONSE
Works similar to make-response except that the message body is derived from a HTML5 rendering of the X-expression HTML. This expression must be an ELEMENT according to the following grammar:
  XEXPR   = ELEMENT | CONTENT
  ELEMENT = (list SYMBOL (list (list SYMBOL CONTENT ...) ...) XEXPR ...) ;; element optionally with attributes
          | (list SYMBOL XEXPR ...)                                      ;; element without attributes
  CONTENT = STRING                                                       ;; character data
          | SYMBOL                                                       ;; symbolic entity reference
          | INTEGER                                                      ;; numeric entity reference
The content type of the resulting message is text/html.
  (make-error-response STATUS MESSAGE [#:headers HEADERS] [#:status-message STATUS-MESSAGE]) => RESPONSE
Works similar to make-html-response but uses a predefined content document into which it only inserts the given error MESSAGE.