TsgcWSAPIKeyManagerMethods › ExtractKeyFromHeaders

ExtractKeyFromHeaders Method

Parses the Validation.HeaderName value out of a raw HTTP header block.

Syntax

function ExtractKeyFromHeaders(const aHeaders: string): string;

Parameters

NameTypeDescription
aHeadersconst stringRaw HTTP header block (typically Connection.HeadersRequest.Text) — one Name: Value pair per line.

Return Value

Header value trimmed of whitespace, or an empty string when the configured header is absent. Header-name matching is case-insensitive per RFC 7230. (string)

Remarks

Low-level parser used internally by IsRequestAuthorized. Reads the header named by Validation.HeaderName (default X-API-Key) from the supplied block. Exposed publicly so custom integrations can reuse the same parsing when they extract the key ahead of time (for example to log the incoming key prefix before calling ValidateKey). Note: this does not validate the key; pair it with ValidateKey to actually authorize the request.

Example

var
  vKey: string;
begin
  vKey := sgcWSAPIKeyManager1.ExtractKeyFromHeaders(Connection.HeadersRequest.Text);
  if vKey <> '' then
    Log('Incoming key prefix: ' + Copy(vKey, 1, 10) + '…');
end;

Back to Methods