Skip to content

Commit 6b097f0

Browse files
committed
Support custom HTTP Headers in SyncClient constructor
1 parent 11ad6cf commit 6b097f0

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

NETCoreSync/NETCoreSync.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
<PackageProjectUrl>https://github.com/aldycool/NETCoreSync</PackageProjectUrl>
1010
<RepositoryUrl>https://github.com/aldycool/NETCoreSync</RepositoryUrl>
1111
<PackageTags>database sync synchronization framework NETCoreApp NETStandard Xamarin Forms</PackageTags>
12-
<PackageReleaseNotes>## v1.2.0 Release Notes
12+
<PackageReleaseNotes>## v1.2.1 Release Notes
1313

1414
### Added Features
15-
* Support conflict handling during `DeserializeJsonToExistingData` method
16-
* Support suppressing Exception during hook calls if updated with older time stamp (GlobalTimeStamp only)
15+
* Support custom HTTP Headers in `SyncClient` constructor
1716

1817
### Breaking Changes
19-
* `DeserializeJsonToExistingData` method signature change: adds `conflictType` parameter
18+
None
2019
</PackageReleaseNotes>
2120
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
22-
<Version>1.2.0</Version>
21+
<Version>1.2.1</Version>
22+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
2323
</PropertyGroup>
2424

2525
<ItemGroup>

NETCoreSync/SyncClient.cs

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class SyncClient
1515
private readonly string synchronizationId;
1616
private readonly SyncEngine syncEngine;
1717
private readonly string serverUrl;
18+
private readonly Dictionary<string, string> httpHeaders;
1819

1920
public enum SynchronizationMethodEnum
2021
{
@@ -23,10 +24,16 @@ public enum SynchronizationMethodEnum
2324
}
2425

2526
public SyncClient(string synchronizationId, SyncEngine syncEngine, string serverUrl)
27+
: this(synchronizationId, syncEngine, serverUrl, null)
28+
{
29+
}
30+
31+
public SyncClient(string synchronizationId, SyncEngine syncEngine, string serverUrl, Dictionary<string, string> httpHeaders)
2632
{
2733
this.synchronizationId = synchronizationId ?? throw new NullReferenceException(nameof(synchronizationId));
2834
this.syncEngine = syncEngine ?? throw new NullReferenceException(nameof(syncEngine));
2935
this.serverUrl = serverUrl ?? throw new NullReferenceException(nameof(serverUrl));
36+
this.httpHeaders = httpHeaders;
3037
}
3138

3239
public async Task<SyncResult> SynchronizeAsync(SynchronizationMethodEnum synchronizationMethod = SynchronizationMethodEnum.PushThenPull, Dictionary<string, object> customInfo = null)
@@ -345,6 +352,15 @@ private async Task SynchronizeGlobalTimeStamp(SynchronizationMethodEnum synchron
345352

346353
using (var httpClient = new HttpClient())
347354
{
355+
if (httpHeaders != null)
356+
{
357+
httpHeaders.ToList().ForEach(kvp =>
358+
{
359+
if (httpClient.DefaultRequestHeaders.Contains(kvp.Key)) httpClient.DefaultRequestHeaders.Remove(kvp.Key);
360+
httpClient.DefaultRequestHeaders.Add(kvp.Key, kvp.Value);
361+
});
362+
}
363+
348364
using (var multipartFormDataContent = new MultipartFormDataContent())
349365
{
350366
ByteArrayContent byteArrayContent = new ByteArrayContent(compressed);

0 commit comments

Comments
 (0)