Skip to content

Update copyright notices and improve code quality #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ indent_size = 2
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
file_header_template = Copyright © https://myCSharp.de - all rights reserved

# Organize usings
dotnet_sort_system_directives_first = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Mvc;

Expand Down
2 changes: 1 addition & 1 deletion samples/HttpClientHints.Samples.AspNetCoreMvc/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using MyCSharp.HttpClientHints.AspNetCore;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
Expand All @@ -23,13 +23,13 @@ public static class HttpClientHintsHttpContextExtensions
public static HttpClientHints GetClientHints(this HttpContext context)
{
// Check if client hints are already cached for this request
if (context.Items.TryGetValue(ClientHintsCacheKey, out var cached) && cached is HttpClientHints hints)
if (context.Items.TryGetValue(ClientHintsCacheKey, out object? cached) && cached is HttpClientHints hints)
{
return hints;
}

// Create and cache new client hints
var newHints = context.Request.Headers.GetClientHints();
HttpClientHints newHints = context.Request.Headers.GetClientHints();
context.Items[ClientHintsCacheKey] = newHints;
return newHints;
}
Expand All @@ -44,14 +44,14 @@ public static HttpClientHints GetClientHints(this IHeaderDictionary headers)
// User Agent
headers.TryGetValue("User-Agent", out StringValues userAgentValues);
string? userAgent = userAgentValues.Count > 0 ? userAgentValues[0] : null;

headers.TryGetValue("Sec-CH-UA", out StringValues uaValues);
string? ua = uaValues.Count > 0 ? uaValues[0] : null;

// Platform
headers.TryGetValue("Sec-CH-UA-Platform", out StringValues platformValues);
string? platform = platformValues.Count > 0 ? platformValues[0] : null;

headers.TryGetValue("Sec-CH-UA-Platform-Version", out StringValues platformVersionValues);
string? platformVersion = platformVersionValues.Count > 0 ? platformVersionValues[0] : null;

Expand All @@ -66,7 +66,7 @@ public static HttpClientHints GetClientHints(this IHeaderDictionary headers)
// Device
headers.TryGetValue("Sec-CH-UA-Model", out StringValues modelValues);
string? model = modelValues.Count > 0 ? modelValues[0] : null;

headers.TryGetValue("Sec-CH-UA-Mobile", out StringValues mobileValues);
bool? mobile = HttpClientHintsInterpreter.IsMobile(mobileValues.Count > 0 ? mobileValues[0] : null);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

namespace MyCSharp.HttpClientHints.AspNetCore;

Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientHints.AspNetCore/HttpClientHintsOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

namespace MyCSharp.HttpClientHints.AspNetCore;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright � https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientHints/HttpClientHints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.Extensions.Primitives;

Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientHints/HttpClientHintsInterpreter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

namespace MyCSharp.HttpClientHints;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
Expand All @@ -12,7 +12,7 @@ public class HttpClientHintsHttpContextExtensionsTests
public void GetClientHints_ReturnsCorrectValues_WhenHeadersArePresent()
{
// Arrange
HeaderDictionary headers = new HeaderDictionary
HeaderDictionary headers = new()
{
{ "User-Agent", new StringValues("TestUserAgent") },
{ "Sec-CH-UA", new StringValues("TestUA") },
Expand Down Expand Up @@ -65,7 +65,7 @@ public void GetClientHints_ReturnsNullValues_WhenHeadersAreMissing()
public void GetClientHints_ReturnsCorrectMobileValue_WhenMobileHeaderIsTrue()
{
// Arrange
HeaderDictionary headers = new HeaderDictionary
HeaderDictionary headers = new()
{
{ "Sec-CH-UA-Mobile", new StringValues("?1") } // true
};
Expand All @@ -81,7 +81,7 @@ public void GetClientHints_ReturnsCorrectMobileValue_WhenMobileHeaderIsTrue()
public void GetClientHints_ReturnsCorrectMobileValue_WhenMobileHeaderIsFalse()
{
// Arrange
HeaderDictionary headers = new HeaderDictionary
HeaderDictionary headers = new()
{
{ "Sec-CH-UA-Mobile", new StringValues("?0") } // false
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © myCSharp.de - all rights reserved
// Copyright © https://myCSharp.de - all rights reserved

using Xunit;

Expand Down