HTTP filters
Request filters are invoked when a request is received from an HTTP client, before it is forwarded to the HTTP server.
Response filters are invoked when a response is received from the HTTP server, before it is forwarded to the HTTP client.
Duplex filters are invoked for both requests and responses.
Filters are given the opportunity to look at the request/response and do whatever they want with it: let it through, modify it, or reject it. Unless it's rejected, the packet is then forwarded to its destination.
Context
All filters define the following variables, which can be accessed from the JavaScript code in filters:
log : A Logger object to output messages to the logging system
context : an object containing various objects. This context is visible to all filters for a given HTTP request. The following objects will always be available in filters, but some filters may also define additional objects.
context.request : a request object, available in all filters
context.response (only for response filters): a response object
context.filterContext : a context that is visible to all invocations of this filter, as long as the Gallium Data instance is up
context.threadContext : a context that is attached to the current thread. This is used in some advanced use cases, when using non-thread-safe objects.
context.projectContext : a context that is visible by all invocations of all filters in the project. Be careful when storing values in this context, as they never go away and can clog up memory if used excessively.
context.result: a result object used to indicate failure, or to override the request/response completely.
Request filter types
JavaScript request filter: can be invoked for any request from the clients
JSON request filter: can be invoked for any JSON request from the clients
Request logger: writes out selected requests to the log
Response filter types
JavaScript response filter: can be invoked for any response from the HTTP server
JSON response filter: can be invoked for any JSON response from the HTTP server
Replace response filter: can replace text in responses without any code
Response logger: writes out selected responses to the log
Duplex filter types
JavaScript duplex filter: can be invoked for both requests and responses