TsgcWSRateLimiterMethods › IsMessageAllowed

IsMessageAllowed Method

Server hook: returns True if a message from IP passes rate limiting.

Syntax

function IsMessageAllowed(const aIP: string; const aMessage: string = ''): Boolean;

Parameters

NameTypeDescription
aIPconst stringIP address of the client sending the message. Used as the key for PerIP and burst protection.
aMessageconst stringOptional message payload or endpoint path. Passed to the PerEndpoint wildcard matcher so per-endpoint rules can see the URL / command being invoked. Defaults to an empty string.

Return Value

Returns True if the message should be processed, False if it should be rejected. (Boolean)

Remarks

Server-integration helper invoked automatically on every received message when the rate limiter is assigned to a server's RateLimiter property. Evaluates PerIP, PerEndpoint, PerAPIKey, PerUser, quotas and burst protection. Returns True immediately when Enabled is False. Use directly only from custom protocol code that is not covered by the built-in server integration.

Example

// Manual gate inside a custom OnMessage handler
procedure TForm1.ServerMessage(Connection: TsgcWSConnection; const Text: string);
begin
  if not sgcWSRateLimiter1.IsMessageAllowed(Connection.PeerIP, Text) then
  begin
    Connection.WriteData('Rate limited');
    Exit;
  end;
  ProcessCommand(Connection, Text);
end;

Back to Methods