The JavaScript response filter is the most flexible of all response filters. It can potentially be called for any response packet type, and can modify traffic in any way it sees fit.
Packet types : optional. If specified, a comma-separated list of packet types for which this filter should be called, for instance: ERR,OK. Spaces are ignored.
Client IPs: optional. If specified, a comma-separated (or line break separated) list of IP4 or IP6 addresses or regular expressions for IP addresses.
Users: optional. If specified, a comma-separated (or line break separated) list of user names or regular expressions for user names.
The following variables will always be defined when your JavaScript executes:
log : the log object
context : contains all the variables you'll commonly use:
packet : the packet being filtered
result : the result object, used to cancel the current packet if desired
filterContext: an object containing variables attached to this filter. Any changes to this object will be visible to all invocations of this filter.
connectionContext: an object containing variables attached to the connection. Any changes to this object will be visible to all filters defined on this connection.
In some cases, you may want to modify certain responses from the server, for instance by clearing a status flag in an OK packet (see the MySQL documentation for details):
let pkt = context.packet;
if (pkt.flags & 16) {
log.info("Clearing NO_GOOD_INDEX_USED flag");
pkt.clearStatusFlag(4);
}