Skip to content

Commit e5644b4

Browse files
authored
[1.x] Fix some compile time warnings with .NET 8/9 (kapi2289#20)
* fix some compile time warnings * .net 8 * restore header keys * added .net 9 * update version in actions
1 parent 7b7629c commit e5644b4

File tree

8 files changed

+20
-8
lines changed

8 files changed

+20
-8
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup .NET
2020
uses: actions/setup-dotnet@v3
2121
with:
22-
dotnet-version: 6.0.x
22+
dotnet-version: 9.0.x
2323
- name: Restore dependencies
2424
run: dotnet restore
2525
- name: Build

InertiaCore/Extensions/Configure.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static async Task OnVersionChange(HttpContext context, IApplicationBuild
6969

7070
if (tempData.Any()) tempData.Keep();
7171

72-
context.Response.Headers.Add("X-Inertia-Location", context.RequestedUri());
72+
context.Response.Headers.Override("X-Inertia-Location", context.RequestedUri());
7373
context.Response.StatusCode = (int)HttpStatusCode.Conflict;
7474

7575
await context.Response.CompleteAsync();

InertiaCore/Extensions/InertiaExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@ internal static bool IsInertiaRequest(this HttpContext context) =>
3131
internal static bool IsInertiaRequest(this ActionContext context) => context.HttpContext.IsInertiaRequest();
3232

3333
internal static string ToCamelCase(this string s) => JsonNamingPolicy.CamelCase.ConvertName(s);
34+
35+
internal static bool Override<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
36+
{
37+
if (dictionary.ContainsKey(key))
38+
{
39+
dictionary[key] = value;
40+
return true;
41+
}
42+
43+
dictionary.Add(key, value);
44+
return false;
45+
}
3446
}

InertiaCore/InertiaCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ImplicitUsings>enable</ImplicitUsings>
44
<Nullable>enable</Nullable>
55
<Version>0.0.9</Version>
6-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
6+
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
77
<PackageId>AspNetCore.InertiaCore</PackageId>
88
<Authors>kapi2289</Authors>
99
<Description>Inertia.js ASP.NET Adapter. https://inertiajs.com/</Description>

InertiaCore/Response.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ protected internal void ProcessResponse()
8181

8282
protected internal JsonResult GetJson()
8383
{
84-
_context!.HttpContext.Response.Headers.Add("X-Inertia", "true");
85-
_context!.HttpContext.Response.Headers.Add("Vary", "Accept");
84+
_context!.HttpContext.Response.Headers.Override("X-Inertia", "true");
85+
_context!.HttpContext.Response.Headers.Override("Vary", "Accept");
8686
_context!.HttpContext.Response.StatusCode = 200;
8787

8888
return new JsonResult(_page, new JsonSerializerOptions

InertiaCore/Utils/InertiaActionFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void OnActionExecuted(ActionExecutedContext context)
3232
};
3333

3434
if (destinationUrl == null) return;
35-
context.HttpContext.Response.Headers.Add("Location", destinationUrl);
35+
context.HttpContext.Response.Headers.Override("Location", destinationUrl);
3636
context.Result = new StatusCodeResult((int)HttpStatusCode.RedirectMethod);
3737
}
3838

InertiaCore/Utils/LocationResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public async Task ExecuteResultAsync(ActionContext context)
1414
{
1515
if (context.IsInertiaRequest())
1616
{
17-
context.HttpContext.Response.Headers.Add("X-Inertia-Location", _url);
17+
context.HttpContext.Response.Headers.Override("X-Inertia-Location", _url);
1818
await new StatusCodeResult((int)HttpStatusCode.Conflict).ExecuteResultAsync(context);
1919
return;
2020
}

InertiaCoreTests/InertiaCoreTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

0 commit comments

Comments
 (0)