Skip to content

Commit

Permalink
Merge pull request #94 from jamie-taylor-rjj/feature/add-net-8
Browse files Browse the repository at this point in the history
Feature/add net 8
  • Loading branch information
GaProgMan authored May 30, 2024
2 parents 25bbbf3 + 637d644 commit 31f75c1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Jamie Taylor
Copyright (c) 2024 Jamie Taylor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 9 additions & 0 deletions OwaspHeaders.Core.Tests/HttpContextExtensionsTests/TryAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ public void DoesntInjectHeader_When_Present()
var headerName = Guid.NewGuid().ToString();
var headerBody = Guid.NewGuid().ToString();

// ASP0019 states that:
// "IDictionary.Add will throw an ArgumentException when attempting to add a duplicate key."
// However, we've already done a check to see whether the
// Response.Headers object cannot contain this header (as we're in
// the setup stage of a test).
// So we'll disable the warning here then immediately restore it
// after we've done what we need to.
#pragma warning disable ASP0019
_context.Response.Headers.Add(headerName, headerBody);
#pragma warning restore ASP0019

// Act
var response = _context.TryAddHeader(headerName, headerBody);
Expand Down
10 changes: 10 additions & 0 deletions OwaspHeaders.Core.Tests/HttpContextExtensionsTests/TryRemove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ public void CanRemoveHeader_When_Present()
// Arrange
var headerName = Guid.NewGuid().ToString();
var headerBody = Guid.NewGuid().ToString();

// ASP0019 states that:
// "IDictionary.Add will throw an ArgumentException when attempting to add a duplicate key."
// However, we've already done a check to see whether the
// Response.Headers object cannot contain this header (as we're in
// the setup stage of a test).
// So we'll disable the warning here then immediately restore it
// after we've done what we need to.
#pragma warning disable ASP0019
_context.Response.Headers.Add(headerName, headerBody);
#pragma warning restore ASP0019

// Act
var response = _context.TryRemoveHeader(headerName);
Expand Down
2 changes: 1 addition & 1 deletion OwaspHeaders.Core.Tests/OwaspHeaders.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<VersionPrefix>8.0.0</VersionPrefix>
<Authors>Jamie Taylor</Authors>
<AssemblyName>OwaspHeaders.Core.Tests</AssemblyName>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ Please note: this middleware **DOES NOT SUPPORT BLAZOR OR WEBASSEMBLY APPLICATIO
- .NET SDKs vLatest
- 6.0
- 7.0
- 8.0&ast;
- 8.0
- an IDE (VS Code, Rider, or Visual Studio)
- [dotnet-format](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-format) global tool.

That's it.

&ast; = at the time of pushing version 8 of the repo (Dec 2nd, 2023), the .NET 8 SDK binaries are not available for some Linux distributions (such as Fedora). If v8.0 of .NET is not available for your chosen distro, remove the `net8.0` TFM from all csproj files in order to build and run the code.

## Pull Requests

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
Expand Down
11 changes: 10 additions & 1 deletion src/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ public static bool TryAddHeader(this HttpContext httpContext, string headerName,
}
try
{
httpContext.Response.Headers.Add(headerName, headerValue);
// ASP0019 states that:
// "IDictionary.Add will throw an ArgumentException when attempting to add a duplicate key."
// However, we've already done a check to see whether the
// Response.Headers object
// already contains a header with this name (in the above if statement).
// So we'll disable the warning here then immediately restore it
// after we've done what we need to.
#pragma warning disable ASP0019
httpContext.Response.Headers.Append(headerName, headerValue);
#pragma warning restore ASP0019
return true;
}
catch (ArgumentException)
Expand Down
4 changes: 2 additions & 2 deletions src/OwaspHeaders.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>An ASP.NET Core Middleware which adds the OWASP recommended HTTP headers for enhanced security.</Description>
<VersionPrefix>8.0.0</VersionPrefix>
<VersionPrefix>8.1.0</VersionPrefix>
<Authors>Jamie Taylor</Authors>
<AssemblyName>OwaspHeaders.Core</AssemblyName>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<PackageId>OwaspHeaders.Core</PackageId>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
Expand Down
2 changes: 1 addition & 1 deletion src/OwaspHeadersCore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>OwaspHeaders.Core</id>
<version>7.5.1</version>
<version>8.1.0</version>
<authors>GaProgMan</authors>
<owners>GaProgMan</owners>
<readme>docs\README-NuGet.md</readme>
Expand Down

0 comments on commit 31f75c1

Please sign in to comment.