Skip to content

Commit ab0004f

Browse files
authored
Add headers support to .NET server (#302)
Also fix the embarassing mistake of never actually sending the proper headers from the TDK client to make the backend server failover simulation work
1 parent 4304a1e commit ab0004f

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

client/src/cbltest/api/replicator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ async def start(self) -> None:
141141
payload.pinnedServerCert = self.pinned_server_cert
142142
payload.reset = self.reset
143143
payload.collections = self.collections
144+
payload.headers = self.headers
144145
req = self.__request_factory.create_request(
145146
TestServerRequestType.START_REPLICATOR, payload
146147
)

client/src/cbltest/v1/requests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ def __init__(self, database: str, endpoint: str):
459459
self.pinnedServerCert: str | None = None
460460
"""The PEM representation of the TLS certificate that the remote is using"""
461461

462+
self.headers: dict[str, str] | None = None
463+
"""The headers to include in the replication requests"""
464+
462465
def to_json(self) -> Any:
463466
"""Serializes the :class:`PostStartReplicatorRequestBody` to a JSON string"""
464467
raw = {
@@ -469,6 +472,7 @@ def to_json(self) -> Any:
469472
"enableDocumentListener": self.enableDocumentListener,
470473
"enableAutoPurge": self.enableAutoPurge,
471474
"pinnedServerCert": self.pinnedServerCert,
475+
"headers": self.headers,
472476
}
473477

474478
if self.collections is not None:

servers/dotnet/testserver.logic/Handlers/StartReplicatorHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,14 @@ internal readonly record struct StartReplicatorConfig
261261
public bool enableAutoPurge { get; init; }
262262

263263
public string? pinnedServerCert { get; init; }
264+
265+
public IReadOnlyDictionary<string, string?>? headers { get; init; }
264266

265267
[JsonConstructor]
266268
public StartReplicatorConfig(string database, string endpoint,
267269
string replicatorType, bool continuous, IReadOnlyList<StartReplicatorCollection> collections,
268270
StartReplicatorAuthenticator? authenticator = null, bool enableDocumentListener = false,
269-
bool enableAutoPurge = true, string? pinnedServerCert = null)
271+
bool enableAutoPurge = true, string? pinnedServerCert = null, IReadOnlyDictionary<string, string?>? headers = null)
270272
{
271273
this.database = database;
272274
this.endpoint = endpoint;
@@ -277,6 +279,7 @@ public StartReplicatorConfig(string database, string endpoint,
277279
this.enableDocumentListener = enableDocumentListener;
278280
this.enableAutoPurge = enableAutoPurge;
279281
this.pinnedServerCert = pinnedServerCert;
282+
this.headers = headers;
280283

281284
if (replicatorType.ToLowerInvariant() == "pull") {
282285
ReplicatorType = ReplicatorType.Pull;
@@ -360,7 +363,8 @@ public static Task StartReplicatorHandler(int version, Session session, JsonDocu
360363
EnableAutoPurge = deserializedBody.config.enableAutoPurge,
361364
PinnedServerCertificate = deserializedBody.config.pinnedServerCert != null
362365
? new(Encoding.ASCII.GetBytes(deserializedBody.config.pinnedServerCert))
363-
: null
366+
: null,
367+
Headers = deserializedBody.config.headers?.ToImmutableDictionary() ?? ImmutableDictionary<string, string?>.Empty,
364368
};
365369

366370
var (repl, id) = session.ObjectManager.RegisterObject(() => new Replicator(replConfig));

servers/dotnet/testserver.logic/testserver.logic.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<LangVersion>latest</LangVersion>
8-
<AssemblyVersion>1.1.0</AssemblyVersion>
8+
<AssemblyVersion>1.2.2</AssemblyVersion>
99
</PropertyGroup>
1010

1111
<ItemGroup>

0 commit comments

Comments
 (0)