feat: add no-responders CONNECT validation and tests

Reject connections that send no_responders:true without headers:true,
since the 503 HMSG response requires header support. Add three tests:
connection rejection, acceptance with headers, and 503 delivery flow.
This commit is contained in:
Joseph Doherty
2026-02-22 23:56:49 -05:00
parent 04305447f9
commit 2fb14821e0
2 changed files with 126 additions and 0 deletions

View File

@@ -374,6 +374,15 @@ public sealed class NatsClient : IDisposable
Account.AddClient(Id);
}
// Validate no_responders requires headers
if (ClientOpts.NoResponders && !ClientOpts.Headers)
{
_logger.LogDebug("Client {ClientId} no_responders requires headers", Id);
await CloseWithReasonAsync(ClientClosedReason.NoRespondersRequiresHeaders,
NatsProtocol.ErrNoRespondersRequiresHeaders);
return;
}
_flags.SetFlag(ClientFlags.ConnectReceived);
_flags.SetFlag(ClientFlags.ConnectProcessFinished);
_logger.LogDebug("CONNECT received from client {ClientId}, name={ClientName}", Id, ClientOpts?.Name);