Skip to content

Commit

Permalink
fix: Use contentheaders for new versions of restsharp (#159)
Browse files Browse the repository at this point in the history
* Use contentheaders for new versions of restsharp

* New Guid fix

* Set event target to full url

* set target to use resource path

* use response uri

* Set hostname in platformdata

* Version bump

* install json dep

* Disable sdkconfig event for now

* update openfeature
  • Loading branch information
JamieSinn authored Aug 1, 2024
1 parent 68503f6 commit ff27783
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion DevCycle.SDK.Server.Cloud.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static async Task Main(string[] args)
.Set("nonSetValueBubbledCustomData4", new Value((object)null))
.Build();

Api.Instance.SetProvider(api.GetOpenFeatureProvider());
await Api.Instance.SetProviderAsync(api.GetOpenFeatureProvider());
FeatureClient oFeatureClient = Api.Instance.GetClient();
var allVariables = await api.AllVariables(DevCycleUser.FromEvaluationContext(ctx));
foreach (var readOnlyVariable in allVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion DevCycle.SDK.Server.Cloud/DevCycle.SDK.Server.Cloud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="JsonSubTypes" Version="1.9.0" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions DevCycle.SDK.Server.Common/DevCycle.SDK.Server.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OpenFeature" Version="1.3.1" />
<PackageReference Include="OpenFeature" Version="1.6.0" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions DevCycle.SDK.Server.Common/Model/Local/PlatformData.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Net;
using Newtonsoft.Json;

namespace DevCycle.SDK.Server.Common.Model.Local
Expand Down Expand Up @@ -53,15 +54,14 @@ public virtual string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}


public PlatformData()
{
Platform = DefaultPlatform;
PlatformVersion = DefaultPlatformVersion;
SdkType = DefaultSdkType.ToString().ToLower();
SdkVersion = DefaultSdkVersion;
HostName = null;
HostName = Dns.GetHostName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.9" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion DevCycle.SDK.Server.Local.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static async Task ClientInitialized(DevCycleUser user)
.Set("nonSetValueBubbledCustomData4", new Value((object)null))
.Build();

Api.Instance.SetProvider(api.GetOpenFeatureProvider());
await Api.Instance.SetProviderAsync(api.GetOpenFeatureProvider());
FeatureClient oFeatureClient = Api.Instance.GetClient();
var allVariables = await api.AllVariables(DevCycleUser.FromEvaluationContext(ctx));
foreach (var readOnlyVariable in allVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions DevCycle.SDK.Server.Local.MSTests/DevCycleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public void OpenFeatureUserParsing()
public async Task TestOpenFeatureInitialization()
{
var dvcClient = getTestClient();
OpenFeature.Api.Instance.SetProvider(dvcClient.GetOpenFeatureProvider());
await OpenFeature.Api.Instance.SetProviderAsync(dvcClient.GetOpenFeatureProvider());
FeatureClient client = OpenFeature.Api.Instance.GetClient();

var ctx = EvaluationContext.Builder().Set("user_id", "j_test").Build();
Expand All @@ -350,7 +350,7 @@ public async Task TestOpenFeatureInitialization()
public async Task TestOpenFeatureJSON()
{
using DevCycleLocalClient api = getTestClient();
OpenFeature.Api.Instance.SetProvider(api.GetOpenFeatureProvider());
await OpenFeature.Api.Instance.SetProviderAsync(api.GetOpenFeatureProvider());
FeatureClient client = OpenFeature.Api.Instance.GetClient();

string key = "json";

Check warning on line 356 in DevCycle.SDK.Server.Local.MSTests/DevCycleTest.cs

View workflow job for this annotation

GitHub Actions / run-example

The variable 'key' is assigned but its value is never used
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;
using DevCycle.SDK.Server.Local.Api;
Expand Down Expand Up @@ -34,8 +35,8 @@ private Tuple<EnvironmentConfigManager, MockHttpMessageHandler, MockedRequest> g
.Respond(statusCode,
new List<KeyValuePair<string, string>>()
{
new("test etag", "test etag value"),
new("Last-Modified", "timestamp")
new("Etag", "test etag value"),
new("Last-Modified", DateTime.Now.AddHours(-1).ToString(CultureInfo.InvariantCulture))
},
"application/json",
isError ? "" : config);
Expand Down
12 changes: 6 additions & 6 deletions DevCycle.SDK.Server.Local/Api/EventQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,27 @@ public virtual void QueueSDKConfigEvent(RestRequest request, RestResponse respon
new DevCycleUser(userId: $"{localBucketing.ClientUUID}@{Dns.GetHostName()}"));
QueueEvent(popU, new DevCycleEvent(
type: EventTypes.sdkConfig,
target: request.Resource,
target: response.ResponseUri?.ToString(),
value: -1,
metaData: new Dictionary<string, object>
{
{ "clientUUID", localBucketing.ClientUUID },
{
"reqEtag",
request.Parameters.GetParameters<HeaderParameter>().First(p => p.Name == "If-None-Match")
request.Parameters.GetParameters<HeaderParameter>().FirstOrDefault(p => p.Name == "If-None-Match")?.Value as string
},
{
"reqLastModified",
request.Parameters.GetParameters<HeaderParameter>().First(p => p.Name == "If-Modified-Since")
request.Parameters.GetParameters<HeaderParameter>().FirstOrDefault(p => p.Name == "If-Modified-Since")?.Value as string
},
{
"resEtag", response.Headers?.First(p => p.Name?.ToLower() == "etag")
"resEtag", response.Headers?.FirstOrDefault(p => p.Name?.ToLower() == "etag")?.Value as string
},
{
"resLastModified", response.Headers?.First(p => p.Name?.ToLower() == "last-modified")
"resLastModified", response.ContentHeaders?.FirstOrDefault(p => p.Name?.ToLower() == "last-modified")?.Value as string
},
{
"resRayId", response.Headers?.First(p => p.Name?.ToLower() == "cf-ray")
"resRayId", response.Headers?.FirstOrDefault(p => p.Name?.ToLower() == "cf-ray")?.Value as string
},
{
"resStatus", response.StatusCode
Expand Down
2 changes: 1 addition & 1 deletion DevCycle.SDK.Server.Local/Api/LocalBucketing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class LocalBucketing

public LocalBucketing()
{
ClientUUID = new Guid().ToString();
ClientUUID = Guid.NewGuid().ToString();
WasmMutex.Wait();
random = new Random();
pinnedAddresses = new HashSet<int>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class EnvironmentConfigManager : IDisposable

private bool PollingEnabled = true;

private string configEtag;
private string configLastModified;
private string configEtag = "";
private string configLastModified = "";

public EnvironmentConfigManager(
string sdkKey,
Expand Down Expand Up @@ -186,11 +186,11 @@ private async Task FetchConfigAsyncWithTask()
{
try
{
var lastModified = res.Headers?.FirstOrDefault(e => e.Name?.ToLower() == "last-modified");
var etag = res.Headers?.FirstOrDefault(e => e.Name?.ToLower() == "etag");
if (!string.IsNullOrEmpty(configLastModified) && lastModified != null && !string.IsNullOrEmpty((string)lastModified.Value) )
var lastModified = res.ContentHeaders?.FirstOrDefault(e => e.Name?.ToLower() == "last-modified")?.Value as string;
var etag = res.Headers?.FirstOrDefault(e => e.Name?.ToLower() == "etag")?.Value as string;
if (!string.IsNullOrEmpty(configLastModified) && lastModified != null && !string.IsNullOrEmpty(lastModified) )
{
var parsedHeader = Convert.ToDateTime((string)lastModified.Value);
var parsedHeader = Convert.ToDateTime(lastModified);
var storedHeader = Convert.ToDateTime(configLastModified);
// negative means that the stored header is before the returned parsed header
if (DateTime.Compare(storedHeader, parsedHeader) >= 0)
Expand All @@ -201,10 +201,10 @@ private async Task FetchConfigAsyncWithTask()
}

localBucketing.StoreConfig(sdkKey, res.Content);
configEtag = (string)etag?.Value;
configLastModified = (string)lastModified?.Value;
configEtag = etag;
configLastModified = lastModified;
logger.LogDebug("Config successfully initialized with etag: {ConfigEtag}, {lastmodified}", configEtag, configLastModified);
eventQueue?.QueueSDKConfigEvent(request, res);
//eventQueue?.QueueSDKConfigEvent(request, res);
}
catch (Exception e)
{
Expand Down
5 changes: 3 additions & 2 deletions DevCycle.SDK.Server.Local/DevCycle.SDK.Server.Local.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Wasmtime" Version="11.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Wasmtime" Version="22.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit ff27783

Please sign in to comment.