View Source Implementing Controller
Note: This page is being updated for OSS release. Please be patient.
- Controller action must receives a
Antikythera.Connstruct and returns aAntikythera.Conn. In other words, type signature of a controller action must beacion(Antikythera.Conn.t) :: Antikythera.Conn.t. - What controller action should do is, based on the request information in
Connstruct, to construct a newConnfilled with response information (HTTP status code, body, headers, etc.). Antikythera picks up the response information from the returnedConnand sends back to the request sender. - For this purpose many utility functions are defined in
Antikythera.Controller. Those functions are auto-imported when youuse Antikythera.Controllerin your controller module. - Controller action must return a response within 10 seconds.
- It is recommended that you set the client timeout value to 15 seconds or more. This is because the executor pool waits up to 5 seconds and the controller takes up to 10 seconds.
- Gzip compression of responses is done transparently when a request contains
accept-encoding: gzipheader.
Handling errors
- By default antikythera returns a simple error response to request sender in the following situations:
- An error occurs during execution of controller action.
- No controller action matches the request's method/path.
- Format of the request body does not conform to the value of
content-typeheader. - Websocket connections limit is reached.
- To customize response on error, you can define your gear's custom error handlers by:
- Add
YourGear.Controller.Errormodule. - Inside the module define the following functions:
error/2no_route/1bad_request/1bad_executor_pool_id/2(optional)ws_too_many_connections/1(optional)
- These functions must return a
Antikythera.Conn.tas in regular controller actions.
- Add
- Note that custom error handlers should do as little task as possible to avoid further troubles.
Response headers
- Before returning an HTTP response antikythera automatically adds the following response headers for security reasons:
x-frame-options:DENYx-xss-protection:1; mode=blockx-content-type-options:nosniffstrict-transport-security:max-age=31536000
- Gear implementations can explicitly set these headers; in this case antikythera respects the value and don't overwrite it.