Class: HTTPSession

server.HTTPSession

Base class representing a HTTP session. Connect to the request event in order to handle HTTP requests.

A session is identified by a session ID.

new server.HTTPSession ()

Properties:
Name Type Description
sessionId string

[readonly] The ID that identifies this session. The ID is assigned by the HTTP server.

user string

[readonly] The user ID associated with this session.

timeout number

(default: 60000) The session inactivity timeout in ms. The session closes automatically after this time of inactivity.

urlMapper function

(default: url => url) A function for mapping the request URL.

Example
HTTPSession {

    onRequest: req =>
    {
        if (req.method === "GET")
        {
            req.response(200, "OK")
            .body("You requested " + req.url.href)
            .send();
        }
        else
        {
            req.response(404, "Not Found")
            .send();
        }
    }

}

Extends

Methods

Closes this session. This removes this particular session instance from the parent HTTP server.

response (code, status)server.HTTPResponse Deprecated : Use the `response` method of server.HTTPServer.HTTPRequestEvent instead.

Creates and returns a response object.

Name Type Description
code number

The HTTP status code.

status string

The HTTP status text.

Returns:
Type Description
server.HTTPResponse The response object.

Events

server.HTTPSession.event:request

Is triggered when a request comes in.

Name Type Description
request server.HTTPServer.HTTPRequestEvent

The request event.

server.HTTPSession.event:responseReady

Is triggered when a response is ready to be sent. This allows to make modifications to the response before sending.

Example

WebSession {
   filesystem: localFs
   root: "/var/www"
   indexFile: "index.html"

   onResponseReady: r => { r.enableCrossOriginIsolation(); }
}
Name Type Description
response server.HTTPResponse

The response object.