Skip to content
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
34 changes: 33 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
- @azure Rule - Use Azure Best Practices: When generating code for Azure, running terminal commands for Azure, or performing operations related to Azure, invoke your `get_azure_best_practices` tool if available.
# Instructions for MyCSharp.HttpClientHints

## Projects

- `src/HttpClientHints`: package `MyCSharp.HttpClientHints` with the `HttpClientHints` record and `HttpClientHintsInterpreter`.
- `src/HttpClientHints.AspNetCore`: package `MyCSharp.HttpClientHints.AspNetCore` with the `Accept-CH` middleware, the `HttpContext` and `IHeaderDictionary` extensions and `IHttpClientHintsFeature`.
- `tests/*.UnitTests`: xUnit v3 tests on Microsoft.Testing.Platform. FluentAssertions is blocked; use `Assert`.
- `tests/HttpClientHints.NativeAot.Smoke`: Native AOT smoke test that roots both packages.
- `perf/HttpClientHints.Benchmarks`: BenchmarkDotNet benchmarks.

## Build and test

- The packages target .NET 8, 9, 10 and 11. Build with the .NET 11 SDK.
- `dotnet build -c Release` must not produce warnings: `TreatWarningsAsErrors` is enabled, with Roslynator, Meziantou and the trimming and AOT analyzers.
- Line and branch coverage of both packages must stay at 100 %: `just test-cov`.
- CI checks the formatting: `just format-check`.
- Native AOT: `dotnet publish tests/HttpClientHints.NativeAot.Smoke -c Release -f net11.0 -r <rid>` must publish without warnings, and the executable must exit with 0.

## Code

- Every C# file starts with `// Copyright © https://myCSharp.de - all rights reserved`.
- Do not use reflection or dynamic code generation; both packages are `IsAotCompatible`.
- Reading Client Hints is on the request path: avoid allocations, measure changes with the benchmarks.
- Public API is part of the NuGet packages: removing or changing members is a breaking change and needs a major version.

## Documentation

- `readme.md` and the package readmes in `src/*/readme.md` describe the current behavior only. Do not add version history such as "Since 3.2".
- Link NuGet packages to `https://nubrowse.com/packages/<PackageId>`.

## Commits

Use Conventional Commits, for example `feat:`, `fix:`, `perf:`, `docs:`, `test:`, `ci:` and `chore:`.
40 changes: 40 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Dependabot version updates
# https://docs.github.com/code-security/dependabot/working-with-dependabot/dependabot-options-reference

version: 2
updates:
- package-ecosystem: nuget
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 5
commit-message:
prefix: chore
include: scope
ignore:
# The packages reference the lowest version that supports .NET 8. A newer version would raise
# the minimum version for every consumer. NuGetAudit reports vulnerable versions in the build.
- dependency-name: Microsoft.Extensions.Primitives
groups:
analyzers:
patterns:
- Roslynator.*
- Meziantou.Analyzer
tests:
patterns:
- Microsoft.Testing.*
- xunit.*
benchmarks:
patterns:
- BenchmarkDotNet*

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: ci
groups:
github-actions:
patterns:
- "*"
5 changes: 4 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
global-json-file: ./global.json

- name: Calculate Version with NBGV
uses: dotnet/nbgv@master
uses: dotnet/nbgv@v0.5.2
id: nbgv
with:
setAllVars: true
Expand All @@ -64,6 +64,9 @@ jobs:
- name: Restore dependencies
run: dotnet restore

- name: Check formatting
run: dotnet format --verify-no-changes --no-restore --verbosity minimal

- name: Build
run: dotnet build --configuration ${{ inputs.configuration }} --no-restore /p:Version=${{ steps.nbgv.outputs.SemVer2 }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v6

- name: Download NuGet packages
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: nuget-packages
path: ./artifacts
Expand Down
10 changes: 9 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<Description>HTTP Client Hints for .NET</Description>
<Copyright>Copyright (c) 2024-2026 MyCSharp</Copyright>
<PackageProjectUrl>https://github.com/mycsharp/HttpClientHints</PackageProjectUrl>
<RepositoryUrl>https://github.com/mycsharp/HttpClientHints</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>UserAgent, User Agent, Client Hints, Browser, Client, Detector, Detection, Console, ASP, Desktop, Mobile</PackageTags>
<PackageReleaseNotes>https://github.com/mycsharp/HttpClientHints/releases</PackageReleaseNotes>
<!-- NuGet splits tags at spaces, so each tag is a single word -->
<PackageTags>client-hints;user-agent-client-hints;user-agent;sec-ch-ua;accept-ch;aspnetcore;http;browser;platform;mobile</PackageTags>
<PackageIcon>httpclienthints-logo.png</PackageIcon>
</PropertyGroup>

<PropertyGroup Label="Deterministic CI builds">
<!-- Maps source paths to /_/ so that the packages do not contain paths of the build agent -->
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>

<!-- Ensure the repository root res/httpclienthints-logo.png is packed into NuGet packages -->
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)res\httpclienthints-logo.png" Pack="true" PackagePath="" />
Expand Down
6 changes: 5 additions & 1 deletion MyCSharp.HttpClientHints.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{E23F6AE5-FF68-4E
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.github\workflows\ci.yml = .github\workflows\ci.yml
.github\dependabot.yml = .github\dependabot.yml
.github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml
.github\workflows\main-build.yml = .github\workflows\main-build.yml
.github\workflows\pr-validation.yml = .github\workflows\pr-validation.yml
.github\workflows\release-publish.yml = .github\workflows\release-publish.yml
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
global.json = global.json
Expand Down
12 changes: 11 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Security Policy

Please use the GitHub Issues functionality to report bugs.
## Reporting a vulnerability

Do not report security vulnerabilities in public GitHub issues.

Report them privately through [GitHub private vulnerability reporting](https://github.com/mycsharp/HttpClientHints/security/advisories/new). Only the maintainers can see the report. Please include the affected package and version, a description of the issue and, if possible, steps to reproduce it.

Fixes are released as new versions of the NuGet packages `MyCSharp.HttpClientHints` and `MyCSharp.HttpClientHints.AspNetCore`.

## Other bugs

Report bugs that are not security vulnerabilities in [GitHub issues](https://github.com/mycsharp/HttpClientHints/issues).
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ dotnet test -c Release --no-build

Line and branch coverage of both packages must stay at 100 %. CI collects coverage on every build and fails below this threshold. Run the same check locally with `just test-cov`, or call `./eng/Assert-CodeCoverage.ps1` after a test run with `--coverage --coverage-output-format cobertura`.

CI also checks the formatting with `dotnet format --verify-no-changes`. Run the same check locally with `just format-check`.

## Release

Every push to `main` builds and tests the solution and creates a draft GitHub release with the NuGet packages. Publishing that release runs `.github/workflows/release-publish.yml`, which pushes the packages to NuGet.org with [Trusted Publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing). The workflow exchanges a GitHub OIDC token for a NuGet API key that is valid for one hour, so the repository stores no NuGet API key.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Product>HTTP Client Hints Extensions for ASP.NET Core</Product>
<Description>HTTP Client Hints Extensions for ASP.NET Core</Description>
<Product>HTTP Client Hints for ASP.NET Core</Product>
<Description>Requests HTTP Client Hints with Accept-CH and reads them from the HttpContext in ASP.NET Core.</Description>
</PropertyGroup>

<PropertyGroup Label="Native AOT and trimming">
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClientHints/HttpClientHints.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Product>HTTP Client Agents</Product>
<Description>Reads HTTP Client Hints to identify Browsers, Platforms and Bots.</Description>
<Product>HTTP Client Hints</Product>
<Description>Reads HTTP Client Hints such as Sec-CH-UA, Sec-CH-UA-Platform and Sec-CH-UA-Mobile and decodes their structured values.</Description>
</PropertyGroup>

<PropertyGroup Label="Native AOT and trimming">
Expand Down