TsgcWSAPIKeyManager › Methods › ExtractKeyFromHeaders
Parses the Validation.HeaderName value out of a raw HTTP header block.
function ExtractKeyFromHeaders(const aHeaders: string): string;
| Name | Type | Description |
|---|---|---|
aHeaders | const string | Raw HTTP header block (typically Connection.HeadersRequest.Text) — one Name: Value pair per line. |
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)
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.
var
vKey: string;
begin
vKey := sgcWSAPIKeyManager1.ExtractKeyFromHeaders(Connection.HeadersRequest.Text);
if vKey <> '' then
Log('Incoming key prefix: ' + Copy(vKey, 1, 10) + '…');
end;