From 26587a75fa7022d07d0c013d09906626c5556636 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 16:01:10 +0100 Subject: [PATCH 01/41] feat: source-generated regexes, Native AOT, faster detection and real-world test catalog - Replace the 121 runtime-compiled regexes of the public API with [GeneratedRegex], created on first access; the parser keeps its rules in HttpUserAgentRules - Make all packages trimming and Native AOT compatible (IsAotCompatible) and add a Native AOT smoke test with a CI job for net8.0 to net11.0 - Speed up robot and mobile detection with grouped SearchValues, robot anchors and a snapshot check for replaced HttpUserAgentStatics.Robots entries - Add Samsung Internet, Yandex Browser, UC Browser and 27 search engine, SEO and AI crawlers; restore the declared mobile device priority - Add a real-world user agent catalog for tests and benchmarks, enforce 100% line, branch and method coverage - Fix the core cache.size meter, keep Roslyn runtime assets out of tests and apps - Update README and package readmes Closes #3, closes #5, closes #36 --- .github/workflows/build-and-test.yml | 32 ++ Directory.Build.props | 22 +- MyCSharp.HttpUserAgentParser.sln | 7 + README.md | 141 ++--- .../HttpUserAgentParser.Benchmarks.csproj | 1 + .../RealWorldUserAgentBenchmarks.cs | 115 +++++ .../HttpContextExtensions.cs | 7 +- .../HttpUserAgentParser.AspNetCore.csproj | 4 + .../HttpUserAgentParserAccessor.cs | 11 +- ...ttpUserAgentParserAspNetCoreEventSource.cs | 42 +- .../HttpUserAgentParserAspNetCoreMeters.cs | 11 - .../HttpUserAgentParserAspNetCoreTelemetry.cs | 24 - src/HttpUserAgentParser.AspNetCore/readme.md | 21 +- .../HttpUserAgentParser.MemoryCache.csproj | 4 + ...HttpUserAgentParserMemoryCachedProvider.cs | 8 +- ...tpUserAgentParserMemoryCacheEventSource.cs | 59 ++- .../HttpUserAgentParserMemoryCacheMeters.cs | 2 - ...HttpUserAgentParserMemoryCacheTelemetry.cs | 2 - ...serAgentParserMemoryCacheTelemetryState.cs | 6 +- src/HttpUserAgentParser.MemoryCache/readme.md | 20 +- ...rAgentParserServiceCollectionExtensions.cs | 6 +- .../HttpUserAgentInformation.cs | 19 +- .../HttpUserAgentParser.cs | 120 ++--- .../HttpUserAgentParser.csproj | 4 + .../HttpUserAgentPlatformInformation.cs | 52 +- .../HttpUserAgentRegexes.cs | 213 ++++++++ src/HttpUserAgentParser/HttpUserAgentRules.cs | 435 ++++++++++++++++ .../HttpUserAgentStatics.cs | 484 ++++-------------- .../PriorityTokenMatcher.cs | 280 ++++++++++ .../HttpUserAgentParserEventSource.cs | 63 +-- .../Telemetry/HttpUserAgentParserMeters.cs | 7 +- .../Telemetry/HttpUserAgentParserTelemetry.cs | 2 - .../HttpUserAgentParserTelemetryState.cs | 3 - src/HttpUserAgentParser/readme.md | 32 +- ...entParserAspNetCoreMetersTelemetryTests.cs | 7 +- ...ParserAspNetCoreTelemetryInternalsTests.cs | 67 +++ ...AgentParserAspNetCoreTelemetryPathTests.cs | 51 ++ ...UserAgentParserAspNetCoreTelemetryTests.cs | 7 +- .../Telemetry/TelemetryCollection.cs | 15 + ...yCacheServiceCollectionExtensionssTests.cs | 16 + ...ParserMemoryCachedProviderCacheKeyTests.cs | 36 ++ ...ntParserMemoryCacheMetersTelemetryTests.cs | 7 +- ...arserMemoryCacheTelemetryInternalsTests.cs | 82 +++ ...gentParserMemoryCacheTelemetryPathTests.cs | 65 +++ ...serAgentParserMemoryCacheTelemetryTests.cs | 7 +- .../Telemetry/TelemetryCollection.cs | 15 + ...HttpUserAgentParser.NativeAot.Smoke.csproj | 35 ++ .../Program.cs | 77 +++ .../HttpUserAgentParser.TestHelpers.csproj | 4 + .../UserAgentCatalog.cs | 221 ++++++++ .../HttpUserAgentInformationTests.cs | 46 ++ .../HttpUserAgentParser.UnitTests.csproj | 1 + .../HttpUserAgentParserTests.cs | 20 - .../HttpUserAgentPlatformInformationTests.cs | 53 ++ ...pUserAgentStaticsRobotsReplacementTests.cs | 73 +++ .../HttpUserAgentStaticsTests.cs | 201 ++++++++ .../PriorityTokenMatcherTests.cs | 276 ++++++++++ ...HttpUserAgentParserMetersTelemetryTests.cs | 7 +- ...pUserAgentParserTelemetryInternalsTests.cs | 113 ++++ .../HttpUserAgentParserTelemetryPathTests.cs | 81 +++ .../HttpUserAgentParserTelemetryTests.cs | 7 +- .../Telemetry/TelemetryCollection.cs | 15 + .../UserAgentCatalogTests.cs | 86 ++++ 63 files changed, 3203 insertions(+), 747 deletions(-) create mode 100644 perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs create mode 100644 src/HttpUserAgentParser/HttpUserAgentRegexes.cs create mode 100644 src/HttpUserAgentParser/HttpUserAgentRules.cs create mode 100644 src/HttpUserAgentParser/PriorityTokenMatcher.cs create mode 100644 tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs create mode 100644 tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryPathTests.cs create mode 100644 tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/TelemetryCollection.cs create mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs create mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs create mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs create mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/TelemetryCollection.cs create mode 100644 tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj create mode 100644 tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs create mode 100644 tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c3fc704..850cda5 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -83,3 +83,35 @@ jobs: name: nuget-packages path: ./artifacts/*.nupkg retention-days: 30 + + native-aot: + name: Native AOT (${{ matrix.framework }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + framework: [net8.0, net9.0, net10.0, net11.0] + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: | + 8.0.x + 9.0.x + 10.0.x + 11.0.x + global-json-file: ./global.json + + - name: Install Native AOT prerequisites + run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev + + # The libraries are rooted completely: every trimming or AOT warning fails the publish. + - name: Publish smoke test with Native AOT + run: dotnet publish tests/HttpUserAgentParser.NativeAot.Smoke --configuration Release --framework ${{ matrix.framework }} --runtime linux-x64 --output ./artifacts/aot + + - name: Run smoke test + run: ./artifacts/aot/MyCSharp.HttpUserAgentParser.NativeAot.Smoke diff --git a/Directory.Build.props b/Directory.Build.props index 064e922..ba04fed 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -94,10 +94,9 @@ GeneratedCodeAttribute,CompilerGeneratedAttribute,ExcludeFromCodeCoverageAttribute **/*Program.cs;**/*Startup.cs;**/*GlobalUsings.cs true - - - 96 - line + + 100 + line,branch,method total @@ -129,6 +128,15 @@ [MyCSharp.HttpUserAgentParser.AspNetCore]* + + + build; analyzers + runtime; build; native; contentfiles; analyzers + + all @@ -144,15 +152,15 @@ all - runtime; build; native; contentfiles; analyzers + $(RoslynPackageIncludeAssets) all - runtime; build; native; contentfiles; analyzers + $(RoslynPackageIncludeAssets) all - runtime; build; native; contentfiles; analyzers + $(RoslynPackageIncludeAssets) all diff --git a/MyCSharp.HttpUserAgentParser.sln b/MyCSharp.HttpUserAgentParser.sln index 7596310..0a67c64 100644 --- a/MyCSharp.HttpUserAgentParser.sln +++ b/MyCSharp.HttpUserAgentParser.sln @@ -40,6 +40,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.Benchma EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.TestHelpers", "tests\HttpUserAgentParser.TestHelpers\HttpUserAgentParser.TestHelpers.csproj", "{165EE915-1A4F-4875-90CE-1A2AE1540AE7}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.NativeAot.Smoke", "tests\HttpUserAgentParser.NativeAot.Smoke\HttpUserAgentParser.NativeAot.Smoke.csproj", "{4E55304E-6429-429E-BBB6-7C096C38C96E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -78,6 +80,10 @@ Global {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Release|Any CPU.Build.0 = Release|Any CPU + {4E55304E-6429-429E-BBB6-7C096C38C96E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E55304E-6429-429E-BBB6-7C096C38C96E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E55304E-6429-429E-BBB6-7C096C38C96E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E55304E-6429-429E-BBB6-7C096C38C96E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -91,6 +97,7 @@ Global {39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} {A0D213E9-6408-46D1-AFAF-5096C2F6E027} = {FAAD18A0-E1B8-448D-B611-AFBDA8A89808} {165EE915-1A4F-4875-90CE-1A2AE1540AE7} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} + {4E55304E-6429-429E-BBB6-7C096C38C96E} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E8B0C994-0BF2-4692-9E22-E48B265B2804} diff --git a/README.md b/README.md index d29c0a7..270ef17 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ public void ConfigureServices(IServiceCollection services) // limit the total entries in the MemoryCache // each unique user agent string counts as one entry - options.CacheOptions.SizeLimit = 1024; // default is null (= no limit) + options.CacheOptions.SizeLimit = 1024; // default is 256 }); } ``` @@ -91,7 +91,7 @@ public void ConfigureServices(IServiceCollection services) ### ASP.NET Core -For ASP.NET Core applications, an accessor pattern (`IHttpUserAgentParserAccessor`) implementation can be registered additionally that independently retrieves the user agent based on the `HttpContextAccessor`. This requires the package [MyCSharp.HttpUserAgentParser.AspNetCore](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) +For ASP.NET Core applications, an accessor (`IHttpUserAgentParserAccessor`) can be registered additionally. It reads the `User-Agent` header of the `HttpContext` you pass in and parses it with the registered `IHttpUserAgentParserProvider`. It does not depend on `IHttpContextAccessor`. This requires the package [MyCSharp.HttpUserAgentParser.AspNetCore](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) ```csharp public void ConfigureServices(IServiceCollection services) @@ -106,12 +106,42 @@ public void ConfigureServices(IServiceCollection services) Now you can use ```csharp -public void MyMethod(IHttpUserAgentParserAccessor parserAccessor) +// e.g. in a controller, a minimal API handler or a middleware +public void MyMethod(IHttpUserAgentParserAccessor parserAccessor, HttpContext httpContext) { - HttpUserAgentInformation info = parserAccessor.Get(); + HttpUserAgentInformation? info = parserAccessor.Get(httpContext); // null if the request has no User-Agent header } ``` +If you only need the raw header value, use `httpContext.GetUserAgentString()`. + +## Detection rules + +`HttpUserAgentParser.Parse` checks, in this order: + +1. **Robots**: search engine crawlers (e.g. Googlebot, Bingbot, Applebot, DuckDuckBot, YandexBot), SEO crawlers (e.g. AhrefsBot, SemrushBot, Screaming Frog) and AI crawlers and AI user agents (e.g. GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, PerplexityBot, Amazonbot, Bytespider, CCBot) +2. **Platform**: Windows, macOS, iOS, Android, ChromeOS, Linux and others +3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) +4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Yandex Browser, UC Browser and others + +In every list the first matching entry wins. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome; iPadOS sends the macOS user agent by default. + +### `HttpUserAgentStatics` and regular expressions + +The parser does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` and `HttpUserAgentPlatformInformation.Regex` still provide regular expressions for your own matching. They are generated at compile time with `[GeneratedRegex]` (no runtime compilation, trimming and Native AOT compatible) and are only created on first access; the browser patterns capture the version in group 1. + +`HttpUserAgentStatics.Robots` is the array the parser uses: if you replace an entry, the parser honors it. + +## Native AOT and trimming + +All packages are annotated with `IsAotCompatible` and are verified by publishing a Native AOT smoke test for every target framework (`tests/HttpUserAgentParser.NativeAot.Smoke`): + +```shell +dotnet publish tests/HttpUserAgentParser.NativeAot.Smoke -c Release -f net11.0 -r linux-x64 +``` + +Meters work out of the box. EventCounters rely on `EventSource`, which is disabled by default in Native AOT apps; enable it with `true` in your app's project file if you use `WithTelemetry()`. + ## Telemetry (EventCounters) Telemetry is **opt-in** and **modular per package**. @@ -162,9 +192,9 @@ Core (`MyCSharp.HttpUserAgentParser`) - `parse-requests` - `parse-duration` (s) -- `cache-concurrentdictionary-hit` -- `cache-concurrentdictionary-miss` -- `cache-concurrentdictionary-size` +- `cache-hit` (`HttpUserAgentParserCachedProvider`) +- `cache-miss` (`HttpUserAgentParserCachedProvider`) +- `cache-size` (`HttpUserAgentParserCachedProvider`) MemoryCache (`MyCSharp.HttpUserAgentParser.MemoryCache`) @@ -380,44 +410,46 @@ Notes: Run the parser benchmarks with the .NET 11 runtime. ```shell +# 7 typical user agents dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks*" --inProcess +# mixed real-world workload (closest to production) +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*MixedWorkloadBenchmarks*" --inProcess +# every browser (current and previous browser version) and every crawler of the test catalog +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*BrowserUserAgentBenchmarks*" "*RobotUserAgentBenchmarks*" --inProcess ``` -### Uncached parser performance on .NET 11 +The user agents come from `tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs`, which the unit tests use as well. -BenchmarkDotNet 0.15.8 ran both implementations on .NET 11.0.0 x64, Windows 10, and an AMD Ryzen 9 9950X. The table shows mean time and allocated bytes per parse. +### Parser performance on .NET 11 -| User agent | Baseline (ns) | Current (ns) | Allocated in both runs | -| --- | ---: | ---: | ---: | -| Chrome on Windows | 723.10 | 300.91 | 40 B | -| Firefox on Linux | 569.95 | 360.02 | 32 B | -| Chrome on Android | 691.54 | 466.74 | 40 B | -| Safari on iPhone | 740.59 | 441.33 | 32 B | -| Applebot | 465.22 | 212.52 | 0 B | -| Googlebot | 9.87 | 8.45 | 0 B | -| Unknown client | 632.35 | 467.71 | 0 B | +BenchmarkDotNet 0.15.8 on .NET 11.0.0 x64, Windows 10 and an AMD Ryzen 9 9950X, without caching. The only allocation is the version string. -The mean parse time fell by 26% to 58% in six scenarios. The Googlebot timings overlapped within the reported uncertainty. +Mixed workload: the catalog user agents parsed in a loop, mean time per user agent. -### Reproduce the .NET 11 comparison +| Workload | Mean | Allocated | +| --- | ---: | ---: | +| 44 browser user agents | 291.6 ns | 38 B | +| 49 crawler user agents | 143.1 ns | 0 B | +| All 97 user agents | 223.5 ns | 18 B | -Build the parser from commit `36ec145` with the same SDK and target framework. The benchmark loads the baseline assembly alongside the current parser. +Single user agents: -```powershell -$baseline = "artifacts/performance-baseline" -New-Item -ItemType Directory -Path $baseline -Force | Out-Null -git archive -o artifacts/performance-baseline.tar 36ec145 -tar -xf artifacts/performance-baseline.tar -C $baseline -Copy-Item global.json $baseline +| User agent | Mean | Allocated | +| --- | ---: | ---: | +| Chrome on Windows | 261.2 ns | 40 B | +| Firefox on Linux | 372.0 ns | 32 B | +| Chrome on Android | 276.6 ns | 40 B | +| Safari on iPhone | 320.3 ns | 32 B | +| Applebot | 170.7 ns | 0 B | +| Googlebot | 9.96 ns | 0 B | +| Unknown client | 422.3 ns | 0 B | -Push-Location $baseline -dotnet build src/HttpUserAgentParser -c Release -p:TargetFrameworks=net11.0 -p:AssemblyName=MyCSharp.HttpUserAgentParser.Baseline -p:NoWarn=NU1510 -Pop-Location +Startup in a new process (median of 7 runs): -$env:BenchmarkBaselineAssembly = (Resolve-Path "$baseline/src/HttpUserAgentParser/bin/Release/net11.0/MyCSharp.HttpUserAgentParser.Baseline.dll").Path -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks*" --inProcess --warmupCount 6 --iterationCount 12 --iterationTime 150 -Remove-Item Env:BenchmarkBaselineAssembly -``` +| | Time | Allocated | +| --- | ---: | ---: | +| First `Parse` call | 9.6 ms | 129 KB | +| First use of all `HttpUserAgentStatics` regular expressions (43 platforms, 35 browsers) | 16.6 ms | 114 KB | ### Library comparison on .NET 11 @@ -425,16 +457,7 @@ Remove-Item Env:BenchmarkBaselineAssembly dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*LibraryComparison*" ``` -Mean time of MyCSharp per parse, compared with the previous run of the same benchmark on .NET 10: - -| MyCSharp | .NET 10 (previous) | .NET 11 (current) | Change | -| --- | ---: | ---: | ---: | -| Basic, Chrome Win10 | 939.54 ns | 352.10 ns | -62.5% | -| Basic, Google-Bot | 226.47 ns | 246.71 ns | +8.9% | -| Cached, Chrome Win10 | 24.59 ns | 23.67 ns | -3.7% | -| Cached, Google-Bot | 17.42 ns | 17.27 ns | -0.9% | - -Both runs used the ShortRun job (3 iterations), and the .NET 11 run executed in-process. The Google-Bot difference is within the measurement error of ±81.76 ns. +The ShortRun job (3 iterations) executes in-process. ```shell BenchmarkDotNet v0.15.8, Windows 10 (10.0.19045.7846/22H2/2022Update) @@ -446,21 +469,21 @@ Job=ShortRun Toolchain=InProcessEmitToolchain IterationCount=3 LaunchCount=1 WarmupCount=3 ``` -| Method | Categories | Data | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio | -|------------------- |----------- |------------- |-----------------:|------------------:|-----------------:|----------:|---------:|---------:|---------:|--------:|-----------:|------------:| -| MyCSharp | Basic | Chrome Win10 | 352.10 ns | 13.048 ns | 0.715 ns | 1.00 | 0.00 | - | - | - | 48 B | 1.00 | -| UAParser | Basic | Chrome Win10 | 13,082,281.25 ns | 22,274,660.073 ns | 1,220,949.286 ns | 37,155.21 | 3,003.78 | 656.2500 | 468.7500 | 93.7500 | 11654066 B | 242,793.04 | -| DeviceDetector.NET | Basic | Chrome Win10 | 6,607,830.21 ns | 762,385.537 ns | 41,788.924 ns | 18,767.01 | 107.96 | 335.9375 | 179.6875 | 46.8750 | 5529528 B | 115,198.50 | -| | | | | | | | | | | | | | -| MyCSharp | Basic | Google-Bot | 246.71 ns | 81.763 ns | 4.482 ns | 1.00 | 0.02 | - | - | - | - | NA | -| UAParser | Basic | Google-Bot | 11,954,723.96 ns | 21,157,406.984 ns | 1,159,708.874 ns | 48,467.98 | 4,144.52 | 718.7500 | 484.3750 | 31.2500 | 12010180 B | NA | -| DeviceDetector.NET | Basic | Google-Bot | 7,522,161.72 ns | 3,709,410.885 ns | 203,325.328 ns | 30,497.07 | 862.90 | 601.5625 | 125.0000 | 15.6250 | 10124476 B | NA | -| | | | | | | | | | | | | | -| MyCSharp | Cached | Chrome Win10 | 23.67 ns | 6.669 ns | 0.366 ns | 1.00 | 0.02 | - | - | - | - | NA | -| UAParser | Cached | Chrome Win10 | 150,205.97 ns | 71,587.994 ns | 3,923.980 ns | 6,348.06 | 166.56 | 2.1973 | - | - | 37402 B | NA | -| | | | | | | | | | | | | | -| MyCSharp | Cached | Google-Bot | 17.27 ns | 4.188 ns | 0.230 ns | 1.00 | 0.02 | - | - | - | - | NA | -| UAParser | Cached | Google-Bot | 126,053.13 ns | 20,806.184 ns | 1,140.457 ns | 7,298.43 | 102.15 | 2.6855 | - | - | 45834 B | NA | +| Method | Categories | Data | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio | +|------------------- |----------- |------------- |-----------------:|-----------------:|---------------:|----------:|---------:|---------:|---------:|--------:|-----------:|------------:| +| MyCSharp | Basic | Chrome Win10 | 290.42 ns | 21.325 ns | 1.169 ns | 1.00 | 0.00 | - | - | - | 48 B | 1.00 | +| UAParser | Basic | Chrome Win10 | 11,049,381.25 ns | 2,603,063.009 ns | 142,682.668 ns | 38,046.15 | 445.58 | 656.2500 | 468.7500 | 93.7500 | 11654118 B | 242,794.12 | +| DeviceDetector.NET | Basic | Chrome Win10 | 6,239,145.83 ns | 1,814,748.937 ns | 99,472.513 ns | 21,483.15 | 305.89 | 335.9375 | 179.6875 | 46.8750 | 5529599 B | 115,199.98 | +| | | | | | | | | | | | | | +| MyCSharp | Basic | Google-Bot | 246.81 ns | 96.469 ns | 5.288 ns | 1.00 | 0.03 | - | - | - | - | NA | +| UAParser | Basic | Google-Bot | 13,090,585.94 ns | 3,799,306.664 ns | 208,252.819 ns | 53,054.68 | 1,231.46 | 718.7500 | 484.3750 | 31.2500 | 12010207 B | NA | +| DeviceDetector.NET | Basic | Google-Bot | 7,389,143.49 ns | 348,698.377 ns | 19,113.335 ns | 29,947.37 | 563.38 | 609.3750 | 132.8125 | 23.4375 | 10124580 B | NA | +| | | | | | | | | | | | | | +| MyCSharp | Cached | Chrome Win10 | 24.20 ns | 16.275 ns | 0.892 ns | 1.00 | 0.05 | - | - | - | - | NA | +| UAParser | Cached | Chrome Win10 | 146,715.00 ns | 23,237.727 ns | 1,273.738 ns | 6,069.10 | 203.13 | 2.1973 | - | - | 37402 B | NA | +| | | | | | | | | | | | | | +| MyCSharp | Cached | Google-Bot | 18.58 ns | 0.046 ns | 0.002 ns | 1.00 | 0.00 | - | - | - | - | NA | +| UAParser | Cached | Google-Bot | 125,494.21 ns | 6,022.587 ns | 330.118 ns | 6,754.11 | 15.41 | 2.6855 | - | - | 45834 B | NA | ## Disclaimer diff --git a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParser.Benchmarks.csproj b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParser.Benchmarks.csproj index d447e90..f5a00ff 100644 --- a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParser.Benchmarks.csproj +++ b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParser.Benchmarks.csproj @@ -39,6 +39,7 @@ + diff --git a/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs new file mode 100644 index 0000000..0e5cd1e --- /dev/null +++ b/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs @@ -0,0 +1,115 @@ +// Copyright © https://myCSharp.de - all rights reserved + +#if BENCHMARK_BASELINE +extern alias Baseline; +#endif + +using BenchmarkDotNet.Attributes; +using MyCSharp.HttpUserAgentParser.TestHelpers; +using Parser = MyCSharp.HttpUserAgentParser.HttpUserAgentParser; + +namespace HttpUserAgentParser.Benchmarks; + +/// +/// Parses the browser user agents of : the most used browsers in their current and previous version. +/// +[MemoryDiagnoser] +public class BrowserUserAgentBenchmarks +{ + [ParamsSource(nameof(GetUserAgents))] + public BrowserUserAgent Data { get; set; } + + public static IEnumerable GetUserAgents() => UserAgentCatalog.Browsers; + + [Benchmark] + public string Parse() => Parser.Parse(Data.UserAgent).Name; + +#if BENCHMARK_BASELINE + [Benchmark(Baseline = true)] + public string ParseBaseline() => Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(Data.UserAgent).Name; +#endif +} + +/// +/// Parses the search engine, SEO and AI crawler user agents of . +/// +[MemoryDiagnoser] +public class RobotUserAgentBenchmarks +{ + [ParamsSource(nameof(GetUserAgents))] + public RobotUserAgent Data { get; set; } + + public static IEnumerable GetUserAgents() => UserAgentCatalog.Robots; + + [Benchmark] + public string Parse() => Parser.Parse(Data.UserAgent).Name; + +#if BENCHMARK_BASELINE + [Benchmark(Baseline = true)] + public string ParseBaseline() => Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(Data.UserAgent).Name; +#endif +} + +/// +/// Parses a mixed workload of real-world user agents in one loop, like a server that sees many different clients. +/// +/// +/// Single user agent benchmarks let Dynamic PGO specialize the code for exactly one input; +/// a mixed workload is closer to production. The reported time is per parsed user agent. +/// +[MemoryDiagnoser] +public class MixedWorkloadBenchmarks +{ + private const int OperationsPerInvoke = 1000; + + private string[] _userAgents; + + [Params("Browsers", "Robots", "All")] + public string Workload { get; set; } + + [GlobalSetup] + public void Setup() + { + IReadOnlyList source = Workload switch + { + "Browsers" => [.. UserAgentCatalog.Browsers.Select(static ua => ua.UserAgent)], + "Robots" => [.. UserAgentCatalog.Robots.Select(static ua => ua.UserAgent)], + _ => UserAgentCatalog.All, + }; + + // Repeat the workload to a fixed number of operations, so the per-operation time is comparable between workloads. + _userAgents = [.. Enumerable.Range(0, OperationsPerInvoke).Select(i => source[i % source.Count])]; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int Parse() + { + int robots = 0; + foreach (string userAgent in _userAgents) + { + if (Parser.Parse(userAgent).Type == MyCSharp.HttpUserAgentParser.HttpUserAgentType.Robot) + { + robots++; + } + } + + return robots; + } + +#if BENCHMARK_BASELINE + [Benchmark(Baseline = true, OperationsPerInvoke = OperationsPerInvoke)] + public int ParseBaseline() + { + int robots = 0; + foreach (string userAgent in _userAgents) + { + if (Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(userAgent).Type == Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentType.Robot) + { + robots++; + } + } + + return robots; + } +#endif +} diff --git a/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs b/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs index d6f2462..40f34e6 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs @@ -14,9 +14,14 @@ public static class HttpContextExtensions /// /// Returns the User-Agent header value /// + /// + /// Uses the strongly typed property, which Kestrel serves from a + /// pre-parsed known-header field instead of a dictionary lookup. + /// public static string? GetUserAgentString(this HttpContext httpContext) { - if (httpContext.Request.Headers.TryGetValue("User-Agent", out StringValues value)) + StringValues value = httpContext.Request.Headers.UserAgent; + if (value.Count > 0) { if (HttpUserAgentParserAspNetCoreTelemetry.IsEnabled) { diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj index ba7a8f0..8a27dc0 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj @@ -5,6 +5,10 @@ HTTP User Agent Parser Extensions for ASP.NET Core + + true + + true readme.md diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs index c5f87ed..a33fc05 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs @@ -6,10 +6,12 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore; /// -/// User Agent parser accessor. Implements +/// User Agent parser accessor. Reads the User-Agent header of the given and parses it +/// with the registered . /// /// -/// Creates a new instance of +/// The accessor does not depend on : the is passed explicitly, +/// e.g. from a controller, a minimal API handler or a middleware. /// public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAgentParser) : IHttpUserAgentParserAccessor @@ -17,13 +19,14 @@ public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAg private readonly IHttpUserAgentParserProvider _httpUserAgentParser = httpUserAgentParser; /// - /// User agent of current + /// Returns the User-Agent header of /// public string? GetHttpContextUserAgent(HttpContext httpContext) => httpContext.GetUserAgentString(); /// - /// Returns current of current + /// Returns the parsed of , + /// or if the request has no User-Agent header /// public HttpUserAgentInformation? Get(HttpContext httpContext) { diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs index 7a1fcab..c0f83ca 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; @@ -8,13 +7,7 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// /// EventSource for EventCounters emitted by MyCSharp.HttpUserAgentParser.AspNetCore. /// -/// -/// Provides EventCounter-based telemetry for User-Agent presence detection. -/// Counters are incremented only when the EventSource is enabled to minimize -/// overhead on hot paths. -/// [EventSource(Name = EventSourceName)] -[ExcludeFromCodeCoverage] public sealed class HttpUserAgentParserAspNetCoreEventSource : EventSource { /// @@ -31,9 +24,12 @@ public sealed class HttpUserAgentParserAspNetCoreEventSource : EventSource private readonly IncrementingEventCounter _userAgentMissing; /// - /// Initializes the EventCounters used by this EventSource. + /// Initializes all EventCounters used by this EventSource. /// - private HttpUserAgentParserAspNetCoreEventSource() + /// + /// Use ; the constructor is only accessible for tests. + /// + internal HttpUserAgentParserAspNetCoreEventSource() { _userAgentPresent = new IncrementingEventCounter("useragent-present", this) { @@ -49,47 +45,43 @@ private HttpUserAgentParserAspNetCoreEventSource() } /// - /// Increments the EventCounter for requests with a present User-Agent header. + /// Records a request with a User-Agent header. /// [NonEvent] internal void UserAgentPresent() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _userAgentPresent.Increment(); } - - _userAgentPresent?.Increment(); } /// - /// Increments the EventCounter for requests with a missing User-Agent header. + /// Records a request without a User-Agent header. /// [NonEvent] internal void UserAgentMissing() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _userAgentMissing.Increment(); } - - _userAgentMissing?.Increment(); } /// /// Releases all EventCounter resources used by this EventSource. /// /// - /// when called from Dispose; + /// when called from ; /// when called from a finalizer. /// + /// + /// Follows the pattern of the EventCounters documentation: the counters are released in both cases. + /// protected override void Dispose(bool disposing) { - if (disposing) - { - _userAgentPresent?.Dispose(); - _userAgentMissing?.Dispose(); - } + _userAgentPresent.Dispose(); + _userAgentMissing.Dispose(); base.Dispose(disposing); } diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index dba87f3..b220bfc 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; using MyCSharp.HttpUserAgentParser.Telemetry; @@ -15,7 +14,6 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// Instrument creation is performed once and guarded by a lock-free initialization /// check to minimize overhead on hot paths. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserAspNetCoreMeters { /// @@ -49,15 +47,6 @@ public static string GetMeterName(string? meterPrefix) private static Counter? s_userAgentPresent; private static Counter? s_userAgentMissing; - /// - /// Gets a value indicating whether meter-based telemetry is enabled. - /// - /// - /// Returns once the meter and counters have been initialized. - /// - public static bool IsEnabled - => Volatile.Read(ref s_initialized) != 0; - /// /// Enables meter-based telemetry and initializes all metric instruments. /// diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs index ca5d976..b893760 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; @@ -14,7 +13,6 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// The state is evaluated using lock-free, thread-safe reads and is intended /// to be checked on hot paths. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserAspNetCoreTelemetry { /// @@ -46,28 +44,6 @@ internal static class HttpUserAgentParserAspNetCoreTelemetry public static bool IsEnabled => Volatile.Read(ref s_enabledFlags) != 0; - /// - /// Gets a value indicating whether event counter telemetry is enabled. - /// - /// - /// Returns only if the event counter flag is set - /// and the underlying event source is enabled. - /// - public static bool AreCountersEnabled - => (Volatile.Read(ref s_enabledFlags) & EventCountersFlag) != 0 - && HttpUserAgentParserAspNetCoreEventSource.Log.IsEnabled(); - - /// - /// Gets a value indicating whether meter-based telemetry is enabled. - /// - /// - /// Returns only if the meter flag is set - /// and the meter provider is enabled. - /// - public static bool AreMetersEnabled - => (Volatile.Read(ref s_enabledFlags) & MetersFlag) != 0 - && HttpUserAgentParserAspNetCoreMeters.IsEnabled; - /// /// Enables EventCounter telemetry for the AspNetCore package. /// diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index 277a74d..a595db0 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -15,7 +15,7 @@ dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore Register a provider (any of the available ones) and then add the accessor: -The accessor pattern reads the `User-Agent` header from the current `HttpContext` and parses it using the registered provider. +The accessor reads the `User-Agent` header from the `HttpContext` you pass in and parses it using the registered provider. It does not depend on `IHttpContextAccessor`. ```csharp services @@ -26,12 +26,18 @@ services Usage: ```csharp -public sealed class MyController(IHttpUserAgentParserAccessor accessor) +public sealed class MyController(IHttpUserAgentParserAccessor accessor) : ControllerBase { - public HttpUserAgentInformation Get() => accessor.Get(); + [HttpGet] + public HttpUserAgentInformation? Get() => accessor.Get(HttpContext); // null without User-Agent header } + +// Minimal API +app.MapGet("/ua", (HttpContext context, IHttpUserAgentParserAccessor accessor) => accessor.Get(context)); ``` +The package is trimming and Native AOT compatible. + ### Just read the header If you only want the raw User-Agent string: @@ -58,8 +64,8 @@ services EventSource: `MyCSharp.HttpUserAgentParser.AspNetCore` (constant: `HttpUserAgentParserAspNetCoreEventSource.EventSourceName`) -- `user_agent.present` (incrementing) -- `user_agent.missing` (incrementing) +- `useragent-present` (incrementing) +- `useragent-missing` (incrementing) ### Monitor with dotnet-counters @@ -81,7 +87,7 @@ services ### Meter + instruments -Meter: `MyCSharp.HttpUserAgentParser.AspNetCore` (constant: `HttpUserAgentParserAspNetCoreMeters.MeterName`) +Meter: `mycsharp.http_user_agent_parser.aspnetcore` (the prefix `mycsharp.` can be changed with `WithAspNetCoreMeterTelemetryPrefix(...)`) - `user_agent.present` (counter) - `user_agent.missing` (counter) @@ -107,7 +113,6 @@ If you enabled **native meters** (see above), collect them via `AddMeter(...)`: ```csharp using OpenTelemetry.Metrics; -using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; -metrics.AddMeter(HttpUserAgentParserAspNetCoreMeters.MeterName); +metrics.AddMeter("mycsharp.http_user_agent_parser.aspnetcore"); ``` diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj index 2eae76e..3a072ca 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj @@ -5,6 +5,10 @@ HTTP User Agent Parser Extensions for IMemoryCache + + true + + true readme.md diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index d059628..1cac3ad 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Caching.Memory; using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; using MyCSharp.HttpUserAgentParser.Providers; @@ -69,11 +68,6 @@ public HttpUserAgentInformation Parse(string userAgent) /// /// Parses the user agent string using the memory cache without emitting telemetry. /// - /// - /// This method is excluded from code coverage as it mainly wires together - /// cache access and parsing logic without additional behavior. - /// - [ExcludeFromCodeCoverage] private HttpUserAgentInformation ParseWithoutTelemetry(CacheKey key) { return _memoryCache.GetOrCreate(key, static entry => @@ -120,7 +114,7 @@ private CacheKey GetKey(string userAgent) /// Implements as required by IMemoryCache /// to ensure correct key comparison semantics. /// - private class CacheKey : IEquatable // required for IMemoryCache + internal sealed class CacheKey : IEquatable // required for IMemoryCache { /// /// Gets or sets the raw User-Agent string. diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs index da71f14..7029dfa 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; @@ -9,7 +8,6 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// EventSource for EventCounters emitted by MyCSharp.HttpUserAgentParser.MemoryCache. /// [EventSource(Name = EventSourceName)] -[ExcludeFromCodeCoverage] public sealed class HttpUserAgentParserMemoryCacheEventSource : EventSource { /// @@ -17,13 +15,22 @@ public sealed class HttpUserAgentParserMemoryCacheEventSource : EventSource /// public const string EventSourceName = "MyCSharp.HttpUserAgentParser.MemoryCache"; + /// + /// Singleton instance of the EventSource. + /// internal static HttpUserAgentParserMemoryCacheEventSource Log { get; } = new(); - private readonly IncrementingEventCounter? _cacheHit; + private readonly IncrementingEventCounter _cacheHit; private readonly IncrementingEventCounter _cacheMiss; private readonly PollingCounter _cacheSize; - private HttpUserAgentParserMemoryCacheEventSource() + /// + /// Initializes all EventCounters and polling counters used by this EventSource. + /// + /// + /// Use ; the constructor is only accessible for tests. + /// + internal HttpUserAgentParserMemoryCacheEventSource() { _cacheHit = new IncrementingEventCounter("cache-hit", this) { @@ -44,43 +51,45 @@ private HttpUserAgentParserMemoryCacheEventSource() }; } + /// + /// Records a cache hit. + /// [NonEvent] internal void CacheHit() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _cacheHit.Increment(); } - - _cacheHit?.Increment(); } + /// + /// Records a cache miss. + /// [NonEvent] internal void CacheMiss() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _cacheMiss.Increment(); } - - _cacheMiss?.Increment(); } - [NonEvent] - internal static void CacheSizeIncrement() => HttpUserAgentParserMemoryCacheTelemetryState.CacheSizeIncrement(); - - [NonEvent] - internal static void CacheSizeDecrement() => HttpUserAgentParserMemoryCacheTelemetryState.CacheSizeDecrement(); - - /// + /// + /// Releases all EventCounter and PollingCounter resources used by this EventSource. + /// + /// + /// when called from ; + /// when called from a finalizer. + /// + /// + /// Follows the pattern of the EventCounters documentation: the counters are released in both cases. + /// protected override void Dispose(bool disposing) { - if (disposing) - { - _cacheHit?.Dispose(); - _cacheMiss?.Dispose(); - _cacheSize?.Dispose(); - } + _cacheHit.Dispose(); + _cacheMiss.Dispose(); + _cacheSize.Dispose(); base.Dispose(disposing); } diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 561f3ba..175b81c 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; using MyCSharp.HttpUserAgentParser.Telemetry; @@ -10,7 +9,6 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// /// System.Diagnostics.Metrics instruments emitted by MyCSharp.HttpUserAgentParser.MemoryCache. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserMemoryCacheMeters { private const string MeterNameSuffix = "http_user_agent_parser.memorycache"; diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs index 448de31..4b14f88 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; @@ -9,7 +8,6 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// /// Opt-in switch for MemoryCache package telemetry. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserMemoryCacheTelemetry { // Bit flags to track which telemetry systems are enabled. diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs index 7dc525f..689f832 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs @@ -1,17 +1,13 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; - namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// /// Holds telemetry state for tracking the size of the HTTP User-Agent parser memory cache. /// /// -/// This class is excluded from code coverage as it contains only simple -/// thread-safe state management logic. +/// The state is updated with atomic operations, so it is safe in concurrent scenarios. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserMemoryCacheTelemetryState { private static long s_cacheSize; diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/readme.md index fcdaaba..a015172 100644 --- a/src/HttpUserAgentParser.MemoryCache/readme.md +++ b/src/HttpUserAgentParser.MemoryCache/readme.md @@ -33,7 +33,7 @@ public sealed class MyService(IHttpUserAgentParserProvider parser) services.AddHttpUserAgentMemoryCachedParser(options => { options.CacheEntryOptions.SlidingExpiration = TimeSpan.FromMinutes(60); // default is 1 day - options.CacheOptions.SizeLimit = 1024; // default is null (= no limit) + options.CacheOptions.SizeLimit = 1024; // default is 256 }); ``` @@ -68,9 +68,9 @@ services EventSource: `MyCSharp.HttpUserAgentParser.MemoryCache` (constant: `HttpUserAgentParserMemoryCacheEventSource.EventSourceName`) -- `user_agent_parser.cache.hit` (incrementing) -- `user_agent_parser.cache.miss` (incrementing) -- `user_agent_parser.cache.size` (polling) +- `cache-hit` (incrementing) +- `cache-miss` (incrementing) +- `cache-size` (polling) ### Monitor with dotnet-counters @@ -101,11 +101,11 @@ services ### Meter + instruments -Meter: `MyCSharp.HttpUserAgentParser.MemoryCache` (constant: `HttpUserAgentParserMemoryCacheMeters.MeterName`) +Meter: `mycsharp.http_user_agent_parser.memorycache` (constant: `HttpUserAgentParserMemoryCachedProvider.MeterName`) -- `user_agent_parser.cache.hit` (counter) -- `user_agent_parser.cache.miss` (counter) -- `user_agent_parser.cache.size` (observable gauge) +- `cache.hit` (counter) +- `cache.miss` (counter) +- `cache.size` (observable gauge) ## Export to OpenTelemetry / Application Insights @@ -134,9 +134,9 @@ If you enabled **native meters** (see above), collect them via `AddMeter(...)`: ```csharp using OpenTelemetry.Metrics; -using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using MyCSharp.HttpUserAgentParser.MemoryCache; -metrics.AddMeter(HttpUserAgentParserMemoryCacheMeters.MeterName); +metrics.AddMeter(HttpUserAgentParserMemoryCachedProvider.MeterName); ``` ### Application Insights listener registration diff --git a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs index 23b96bc..dcd433d 100644 --- a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs +++ b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; @@ -31,7 +32,10 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentCach /// /// Registers as singleton to /// - public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser( + /// + /// is created by the dependency injection container; its public constructors are preserved for trimming and Native AOT. + /// + public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>( this IServiceCollection services) where TProvider : class, IHttpUserAgentParserProvider { // create options diff --git a/src/HttpUserAgentParser/HttpUserAgentInformation.cs b/src/HttpUserAgentParser/HttpUserAgentInformation.cs index fc54e9b..05ccbc3 100644 --- a/src/HttpUserAgentParser/HttpUserAgentInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentInformation.cs @@ -5,7 +5,7 @@ namespace MyCSharp.HttpUserAgentParser; /// /// Analyzed user agent /// -public readonly struct HttpUserAgentInformation +public readonly struct HttpUserAgentInformation : IEquatable { /// /// Full User Agent string @@ -72,4 +72,21 @@ internal static HttpUserAgentInformation CreateForBrowser(string userAgent, Http /// internal static HttpUserAgentInformation CreateForUnknown(string userAgent, HttpUserAgentPlatformInformation? platform, string? deviceName) => new(userAgent, platform, HttpUserAgentType.Unknown, name: null, version: null, deviceName); + + /// + /// Returns if all properties of both instances are equal (ordinal string comparison). + /// + public bool Equals(HttpUserAgentInformation other) + => Type == other.Type + && string.Equals(UserAgent, other.UserAgent, StringComparison.Ordinal) + && string.Equals(Name, other.Name, StringComparison.Ordinal) + && string.Equals(Version, other.Version, StringComparison.Ordinal) + && string.Equals(MobileDeviceType, other.MobileDeviceType, StringComparison.Ordinal) + && Nullable.Equals(Platform, other.Platform); + + /// + public override bool Equals(object? obj) => obj is HttpUserAgentInformation other && Equals(other); + + /// + public override int GetHashCode() => HashCode.Combine(UserAgent, Type, Name, Version); } diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 8c9b3eb..e811536 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -60,9 +60,9 @@ private static HttpUserAgentInformation ParseInternal(string userAgent) HttpUserAgentPlatformInformation? platform = GetPlatform(userAgent); string? mobileDeviceType = GetMobileDevice(userAgent); - if (TryGetBrowser(userAgent, out (string Name, string? Version)? browser)) + if (GetBrowser(userAgent) is { } browser) { - return HttpUserAgentInformation.CreateForBrowser(userAgent, platform, browser?.Name, browser?.Version, mobileDeviceType); + return HttpUserAgentInformation.CreateForBrowser(userAgent, platform, browser.Name, browser.Version, mobileDeviceType); } return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType); @@ -78,14 +78,14 @@ private static HttpUserAgentInformation ParseInternal(string userAgent) /// public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent) { + // Rules are sorted by frequency, so a sequential scan usually stops after a few tokens. + // (Measured with a mixed real-world workload, this beats vectorized token groups here.) ReadOnlySpan ua = userAgent.AsSpan(); - foreach ((string Token, string Name, HttpUserAgentPlatformType PlatformType) in HttpUserAgentStatics.s_platformRules) + foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { - if (ContainsIgnoreCase(ua, Token)) + if (ContainsIgnoreCase(ua, token)) { - return new HttpUserAgentPlatformInformation( - HttpUserAgentStatics.GetPlatformRegexForToken(Token), - Name, PlatformType); + return platform; } } @@ -108,48 +108,36 @@ public static (string Name, string? Version)? GetBrowser(string userAgent) { ReadOnlySpan ua = userAgent.AsSpan(); - foreach ((string Name, string DetectToken, string? VersionToken) in HttpUserAgentStatics.s_browserRules) + // Rules are evaluated in priority order (specific browsers before the browsers their user agents contain). + foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) { - if (!TryIndexOf(ua, DetectToken, out int detectIndex)) + if (!TryIndexOf(ua, detectToken, out int detectIndex)) { continue; } - // Version token may differ (e.g., Safari uses "Version/") + int versionSearchStart = detectIndex + detectToken.Length; - int versionSearchStart; - // For rules without a specific version token, ensure pattern Token/ - if (string.IsNullOrEmpty(VersionToken)) + if (versionToken is null) { - int afterDetect = detectIndex + DetectToken.Length; - if (afterDetect >= ua.Length || ua[afterDetect] != '/') + // For rules without a specific version token, ensure pattern Token/ + if (versionSearchStart >= ua.Length || ua[versionSearchStart] != '/') { // Likely a misspelling or partial token (e.g., Edgg, Oprea, Chromee) continue; } } - if (!string.IsNullOrEmpty(VersionToken)) + else if (TryIndexOf(ua, versionToken, out int versionTokenIndex)) { - if (TryIndexOf(ua, VersionToken!, out int vtIndex)) - { - versionSearchStart = vtIndex + VersionToken!.Length; - } - else - { - // If specific version token wasn't found, fall back to detect token area - versionSearchStart = detectIndex + DetectToken.Length; - } - } - else - { - versionSearchStart = detectIndex + DetectToken.Length; + // Version token may differ (e.g., Safari uses "Version/") + versionSearchStart = versionTokenIndex + versionToken.Length; } - ReadOnlySpan search = ua.Slice(versionSearchStart); + // Otherwise (version token not found) the version is searched after the detect token. + ReadOnlySpan search = ua[versionSearchStart..]; if (TryExtractVersion(search, out Range range)) { - string? version = search[range].ToString(); - return (Name, version); + return (name, search[range].ToString()); } // If we didn't find a version for this rule, try next rule @@ -173,26 +161,38 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri public static string? GetRobot(string userAgent) { ReadOnlySpan ua = userAgent.AsSpan(); - (string Key, string Value)[] robots = HttpUserAgentStatics.Robots; + (string Key, string Value)[] robots = HttpUserAgentRules.Robots; #if NET9_0_OR_GREATER + string[] defaultKeys = HttpUserAgentRules.DefaultRobotKeys; + + // Googlebot, by far the most common robot, comes first: if the entry is unchanged and matches, it wins. (string firstKey, string firstValue) = robots[0]; - if (ContainsIgnoreCase(ua, firstKey)) + if (ReferenceEquals(firstKey, defaultKeys[0]) && ContainsIgnoreCase(ua, firstKey)) { return firstValue; } - int index = 1; - foreach (SearchValues group in HttpUserAgentStatics.s_robotTokenGroups) + if (HttpUserAgentRules.AreRobotsUnchanged()) { - bool containsDefaultRobot = ua.ContainsAny(group); - int end = Math.Min(index + HttpUserAgentStatics.TokenGroupSize, robots.Length); - for (; index < end; index++) + // Few vectorized passes over the anchors rule out most user agents (browsers) before the full key search. + if (!HttpUserAgentRules.RobotAnchorMatcher.ContainsAny(ua)) { - (string key, string value) = robots[index]; + return null; + } - // The public array is mutable. Check any keys callers have replaced. - if ((containsDefaultRobot || !ReferenceEquals(key, HttpUserAgentStatics.s_defaultRobotKeys[index])) - && ContainsIgnoreCase(ua, key)) + int index = HttpUserAgentRules.RobotMatcher.Find(ua, 1, out _); + return index >= 0 ? robots[index].Value : null; + } + + // The public array is mutable and callers replaced entries: default keys are filtered by group, + // replaced keys are checked one by one, in array order. + foreach (ref readonly PriorityTokenGroup group in HttpUserAgentRules.RobotMatcher.Groups) + { + bool mayMatchDefaultKey = group.MayMatch(ua); + for (int i = group.Start; i < group.End; i++) + { + (string key, string value) = robots[i]; + if ((mayMatchDefaultKey || !ReferenceEquals(key, defaultKeys[i])) && ContainsIgnoreCase(ua, key)) { return value; } @@ -225,38 +225,8 @@ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? /// public static string? GetMobileDevice(string userAgent) { - ReadOnlySpan ua = userAgent.AsSpan(); -#if NET9_0_OR_GREATER - ReadOnlySpan keys = HttpUserAgentStatics.Mobiles.Keys.AsSpan(); - ReadOnlySpan values = HttpUserAgentStatics.Mobiles.Values.AsSpan(); - for (int i = 0; i < HttpUserAgentStatics.s_mobileTokenGroups.Length; i++) - { - if (!ua.ContainsAny(HttpUserAgentStatics.s_mobileTokenGroups[i])) - { - continue; - } - - int start = i * HttpUserAgentStatics.TokenGroupSize; - int end = Math.Min(start + HttpUserAgentStatics.TokenGroupSize, keys.Length); - for (int j = start; j < end; j++) - { - if (ContainsIgnoreCase(ua, keys[j])) - { - return values[j]; - } - } - } -#else - foreach ((string key, string value) in HttpUserAgentStatics.Mobiles) - { - if (ContainsIgnoreCase(ua, key)) - { - return value; - } - } -#endif - - return null; + int index = HttpUserAgentRules.MobileMatcher.Find(userAgent, 0, out _); + return index >= 0 ? HttpUserAgentRules.Mobiles[index].Value : null; } /// diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.csproj b/src/HttpUserAgentParser/HttpUserAgentParser.csproj index 55b2dab..fcfa165 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.csproj +++ b/src/HttpUserAgentParser/HttpUserAgentParser.csproj @@ -5,6 +5,10 @@ Parses user agents for Browser, Platform and Bots. + + true + + true readme.md diff --git a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs index 68563e4..f417208 100644 --- a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs @@ -7,23 +7,61 @@ namespace MyCSharp.HttpUserAgentParser; /// /// Information about the user agent platform /// -/// -/// Creates a new instance of -/// -public readonly struct HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentPlatformType platformType) +public readonly struct HttpUserAgentPlatformInformation : IEquatable { + private readonly Regex? _regex; + private readonly HttpUserAgentPlatformRegexId _regexId; + + /// + /// Creates a new instance of + /// + public HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentPlatformType platformType) + { + _regex = regex; + Name = name; + PlatformType = platformType; + } + + /// + /// Creates a platform information whose source-generated is resolved on first access. + /// + internal HttpUserAgentPlatformInformation(HttpUserAgentPlatformRegexId regexId, string name, HttpUserAgentPlatformType platformType) + { + _regexId = regexId; + Name = name; + PlatformType = platformType; + } + /// /// Regex-pattern that matches this user agent string /// - public Regex Regex { get; } = regex; + /// + /// The built-in platforms use source-generated regular expressions that are created on first access. + /// The parser does not use this regex; it is provided for consumers that want to match the platform themselves. + /// + public Regex Regex => _regex ?? HttpUserAgentRegexes.GetPlatformRegex(_regexId)!; /// /// Name of the platform /// - public string Name { get; } = name; + public string Name { get; } /// /// Specific platform type aka family /// - public HttpUserAgentPlatformType PlatformType { get; } = platformType; + public HttpUserAgentPlatformType PlatformType { get; } + + /// + /// Returns if both instances describe the same platform with the same instance. + /// + public bool Equals(HttpUserAgentPlatformInformation other) + => PlatformType == other.PlatformType + && string.Equals(Name, other.Name, StringComparison.Ordinal) + && ReferenceEquals(Regex, other.Regex); + + /// + public override bool Equals(object? obj) => obj is HttpUserAgentPlatformInformation other && Equals(other); + + /// + public override int GetHashCode() => HashCode.Combine(Name, PlatformType); } diff --git a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs new file mode 100644 index 0000000..18169ff --- /dev/null +++ b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs @@ -0,0 +1,213 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Text.RegularExpressions; + +namespace MyCSharp.HttpUserAgentParser; + +/// +/// Identifies the source-generated regex of a platform rule. +/// +/// +/// The id lets resolve its lazily, +/// so parsing never has to instantiate a regex. +/// +internal enum HttpUserAgentPlatformRegexId : byte +{ + None = 0, + WindowsNt100, + WindowsNt63, + WindowsNt62, + WindowsNt61, + WindowsNt60, + WindowsNt52, + WindowsNt51, + WindowsNt50, + WindowsNt40, + WinNt40, + WinNtSpace40, + WinNt, + Windows98, + Win98, + Windows95, + Win95, + WindowsPhone, + Windows, + Android, + BlackBerry, + IPhone, + IPad, + IPod, + CrOS, + OsX, + PpcMac, + FreeBsd, + Ppc, + Linux, + Debian, + SunOs, + BeOs, + ApacheBench, + Aix, + Irix, + Osf, + HpUx, + NetBsd, + Bsdi, + OpenBsd, + Gnu, + Unix, + Symbian, +} + +/// +/// Source-generated regular expressions exposed by the public API +/// (, and +/// ). +/// +/// +/// The parser itself does not execute regular expressions. The patterns are generated at compile time, +/// so they need neither runtime compilation (Reflection.Emit) nor regex parsing, are trimming and Native AOT +/// compatible, and are only instantiated on first access. +/// Platform patterns equal Regex.Escape(token), browser patterns equal {token}.*?([0-9\.]+). +/// +internal static partial class HttpUserAgentRegexes +{ + private const RegexOptions Options = RegexOptions.IgnoreCase; + private const int MatchTimeoutMilliseconds = 1000; + + /// + /// Returns the source-generated regex for , or for . + /// + public static Regex? GetPlatformRegex(HttpUserAgentPlatformRegexId id) => id switch + { + HttpUserAgentPlatformRegexId.WindowsNt100 => WindowsNt100(), + HttpUserAgentPlatformRegexId.WindowsNt63 => WindowsNt63(), + HttpUserAgentPlatformRegexId.WindowsNt62 => WindowsNt62(), + HttpUserAgentPlatformRegexId.WindowsNt61 => WindowsNt61(), + HttpUserAgentPlatformRegexId.WindowsNt60 => WindowsNt60(), + HttpUserAgentPlatformRegexId.WindowsNt52 => WindowsNt52(), + HttpUserAgentPlatformRegexId.WindowsNt51 => WindowsNt51(), + HttpUserAgentPlatformRegexId.WindowsNt50 => WindowsNt50(), + HttpUserAgentPlatformRegexId.WindowsNt40 => WindowsNt40(), + HttpUserAgentPlatformRegexId.WinNt40 => WinNt40(), + HttpUserAgentPlatformRegexId.WinNtSpace40 => WinNtSpace40(), + HttpUserAgentPlatformRegexId.WinNt => WinNt(), + HttpUserAgentPlatformRegexId.Windows98 => Windows98(), + HttpUserAgentPlatformRegexId.Win98 => Win98(), + HttpUserAgentPlatformRegexId.Windows95 => Windows95(), + HttpUserAgentPlatformRegexId.Win95 => Win95(), + HttpUserAgentPlatformRegexId.WindowsPhone => WindowsPhone(), + HttpUserAgentPlatformRegexId.Windows => Windows(), + HttpUserAgentPlatformRegexId.Android => Android(), + HttpUserAgentPlatformRegexId.BlackBerry => BlackBerry(), + HttpUserAgentPlatformRegexId.IPhone => IPhone(), + HttpUserAgentPlatformRegexId.IPad => IPad(), + HttpUserAgentPlatformRegexId.IPod => IPod(), + HttpUserAgentPlatformRegexId.CrOS => CrOS(), + HttpUserAgentPlatformRegexId.OsX => OsX(), + HttpUserAgentPlatformRegexId.PpcMac => PpcMac(), + HttpUserAgentPlatformRegexId.FreeBsd => FreeBsd(), + HttpUserAgentPlatformRegexId.Ppc => Ppc(), + HttpUserAgentPlatformRegexId.Linux => Linux(), + HttpUserAgentPlatformRegexId.Debian => Debian(), + HttpUserAgentPlatformRegexId.SunOs => SunOs(), + HttpUserAgentPlatformRegexId.BeOs => BeOs(), + HttpUserAgentPlatformRegexId.ApacheBench => ApacheBench(), + HttpUserAgentPlatformRegexId.Aix => Aix(), + HttpUserAgentPlatformRegexId.Irix => Irix(), + HttpUserAgentPlatformRegexId.Osf => Osf(), + HttpUserAgentPlatformRegexId.HpUx => HpUx(), + HttpUserAgentPlatformRegexId.NetBsd => NetBsd(), + HttpUserAgentPlatformRegexId.Bsdi => Bsdi(), + HttpUserAgentPlatformRegexId.OpenBsd => OpenBsd(), + HttpUserAgentPlatformRegexId.Gnu => Gnu(), + HttpUserAgentPlatformRegexId.Unix => Unix(), + HttpUserAgentPlatformRegexId.Symbian => Symbian(), + _ => null, + }; + + // Platforms: pattern = Regex.Escape(token) + [GeneratedRegex(@"windows\ nt\ 10\.0", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt100(); + [GeneratedRegex(@"windows\ nt\ 6\.3", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt63(); + [GeneratedRegex(@"windows\ nt\ 6\.2", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt62(); + [GeneratedRegex(@"windows\ nt\ 6\.1", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt61(); + [GeneratedRegex(@"windows\ nt\ 6\.0", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt60(); + [GeneratedRegex(@"windows\ nt\ 5\.2", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt52(); + [GeneratedRegex(@"windows\ nt\ 5\.1", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt51(); + [GeneratedRegex(@"windows\ nt\ 5\.0", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt50(); + [GeneratedRegex(@"windows\ nt\ 4\.0", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsNt40(); + [GeneratedRegex(@"winnt4\.0", Options, MatchTimeoutMilliseconds)] private static partial Regex WinNt40(); + [GeneratedRegex(@"winnt\ 4\.0", Options, MatchTimeoutMilliseconds)] private static partial Regex WinNtSpace40(); + [GeneratedRegex(@"winnt", Options, MatchTimeoutMilliseconds)] private static partial Regex WinNt(); + [GeneratedRegex(@"windows\ 98", Options, MatchTimeoutMilliseconds)] private static partial Regex Windows98(); + [GeneratedRegex(@"win98", Options, MatchTimeoutMilliseconds)] private static partial Regex Win98(); + [GeneratedRegex(@"windows\ 95", Options, MatchTimeoutMilliseconds)] private static partial Regex Windows95(); + [GeneratedRegex(@"win95", Options, MatchTimeoutMilliseconds)] private static partial Regex Win95(); + [GeneratedRegex(@"windows\ phone", Options, MatchTimeoutMilliseconds)] private static partial Regex WindowsPhone(); + [GeneratedRegex(@"windows", Options, MatchTimeoutMilliseconds)] private static partial Regex Windows(); + [GeneratedRegex(@"android", Options, MatchTimeoutMilliseconds)] private static partial Regex Android(); + [GeneratedRegex(@"blackberry", Options, MatchTimeoutMilliseconds)] private static partial Regex BlackBerry(); + [GeneratedRegex(@"iphone", Options, MatchTimeoutMilliseconds)] private static partial Regex IPhone(); + [GeneratedRegex(@"ipad", Options, MatchTimeoutMilliseconds)] private static partial Regex IPad(); + [GeneratedRegex(@"ipod", Options, MatchTimeoutMilliseconds)] private static partial Regex IPod(); + [GeneratedRegex(@"cros", Options, MatchTimeoutMilliseconds)] private static partial Regex CrOS(); + [GeneratedRegex(@"os\ x", Options, MatchTimeoutMilliseconds)] private static partial Regex OsX(); + [GeneratedRegex(@"ppc\ mac", Options, MatchTimeoutMilliseconds)] private static partial Regex PpcMac(); + [GeneratedRegex(@"freebsd", Options, MatchTimeoutMilliseconds)] private static partial Regex FreeBsd(); + [GeneratedRegex(@"ppc", Options, MatchTimeoutMilliseconds)] private static partial Regex Ppc(); + [GeneratedRegex(@"linux", Options, MatchTimeoutMilliseconds)] private static partial Regex Linux(); + [GeneratedRegex(@"debian", Options, MatchTimeoutMilliseconds)] private static partial Regex Debian(); + [GeneratedRegex(@"sunos", Options, MatchTimeoutMilliseconds)] private static partial Regex SunOs(); + [GeneratedRegex(@"beos", Options, MatchTimeoutMilliseconds)] private static partial Regex BeOs(); + [GeneratedRegex(@"apachebench", Options, MatchTimeoutMilliseconds)] private static partial Regex ApacheBench(); + [GeneratedRegex(@"aix", Options, MatchTimeoutMilliseconds)] private static partial Regex Aix(); + [GeneratedRegex(@"irix", Options, MatchTimeoutMilliseconds)] private static partial Regex Irix(); + [GeneratedRegex(@"osf", Options, MatchTimeoutMilliseconds)] private static partial Regex Osf(); + [GeneratedRegex(@"hp-ux", Options, MatchTimeoutMilliseconds)] private static partial Regex HpUx(); + [GeneratedRegex(@"netbsd", Options, MatchTimeoutMilliseconds)] private static partial Regex NetBsd(); + [GeneratedRegex(@"bsdi", Options, MatchTimeoutMilliseconds)] private static partial Regex Bsdi(); + [GeneratedRegex(@"openbsd", Options, MatchTimeoutMilliseconds)] private static partial Regex OpenBsd(); + [GeneratedRegex(@"gnu", Options, MatchTimeoutMilliseconds)] private static partial Regex Gnu(); + [GeneratedRegex(@"unix", Options, MatchTimeoutMilliseconds)] private static partial Regex Unix(); + [GeneratedRegex(@"symbian", Options, MatchTimeoutMilliseconds)] private static partial Regex Symbian(); + + // Browsers: pattern = "{token}.*?([0-9\.]+)" + // The numbered group is public behavior: consumers read the version from Groups[1], so ExplicitCapture must not be used. +#pragma warning disable MA0023 // Use RegexOptions.ExplicitCapture or named groups + [GeneratedRegex(@"OPR.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserOpr(); + [GeneratedRegex(@"Flock.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserFlock(); + [GeneratedRegex(@"Edge.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserEdge(); + [GeneratedRegex(@"EdgA.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserEdgA(); + [GeneratedRegex(@"Edg.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserEdg(); + [GeneratedRegex(@"Vivaldi.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserVivaldi(); + [GeneratedRegex(@"Brave Chrome.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserBraveChrome(); + [GeneratedRegex(@"Chrome.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserChrome(); + [GeneratedRegex(@"CriOS.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserCriOS(); + [GeneratedRegex(@"Opera.*?Version.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserOperaVersion(); + [GeneratedRegex(@"Opera.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserOpera(); + [GeneratedRegex(@"MSIE.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserMsie(); + [GeneratedRegex(@"Internet Explorer.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserInternetExplorer(); + [GeneratedRegex(@"Trident.* rv.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserTridentRv(); + [GeneratedRegex(@"Shiira.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserShiira(); + [GeneratedRegex(@"Firefox.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserFirefox(); + [GeneratedRegex(@"FxiOS.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserFxiOS(); + [GeneratedRegex(@"Chimera.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserChimera(); + [GeneratedRegex(@"Phoenix.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserPhoenix(); + [GeneratedRegex(@"Firebird.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserFirebird(); + [GeneratedRegex(@"Camino.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserCamino(); + [GeneratedRegex(@"Netscape.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserNetscape(); + [GeneratedRegex(@"OmniWeb.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserOmniWeb(); + [GeneratedRegex(@"Version.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserVersion(); + [GeneratedRegex(@"Mozilla.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserMozilla(); + [GeneratedRegex(@"Konqueror.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserKonqueror(); + [GeneratedRegex(@"icab.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserICab(); + [GeneratedRegex(@"Lynx.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserLynx(); + [GeneratedRegex(@"Links.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserLinks(); + [GeneratedRegex(@"hotjava.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserHotJava(); + [GeneratedRegex(@"amaya.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserAmaya(); + [GeneratedRegex(@"IBrowse.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserIBrowse(); + [GeneratedRegex(@"Maxthon.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserMaxthon(); + [GeneratedRegex(@"ipod touch.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserIPodTouch(); + [GeneratedRegex(@"Ubuntu.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserUbuntu(); +#pragma warning restore MA0023 +} diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs new file mode 100644 index 0000000..6b9d59f --- /dev/null +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -0,0 +1,435 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Collections.Frozen; +#if NET9_0_OR_GREATER +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +#endif + +namespace MyCSharp.HttpUserAgentParser; + +/// +/// Detection rules used by . +/// +/// +/// The rules live outside of so that parsing never triggers the initialization +/// of the public regex-based collections. In every table the order defines the priority: the first matching rule wins. +/// +internal static class HttpUserAgentRules +{ + /// Marker type of the robot . + internal readonly struct RobotDetector; + + /// Marker type of the robot anchor . + internal readonly struct RobotAnchorDetector; + + /// Marker type of the mobile device . + internal readonly struct MobileDetector; + + /// + /// Platform rules, sorted by frequency (most common platforms first, specific versions before generic tokens). + /// + internal static readonly (string Token, HttpUserAgentPlatformInformation Platform)[] Platforms = + [ + // Most common: Windows (specific versions before generic) + ("windows nt 10.0", new(HttpUserAgentPlatformRegexId.WindowsNt100, "Windows 10", HttpUserAgentPlatformType.Windows)), + ("windows nt 6.1", new(HttpUserAgentPlatformRegexId.WindowsNt61, "Windows 7", HttpUserAgentPlatformType.Windows)), + ("windows nt 6.3", new(HttpUserAgentPlatformRegexId.WindowsNt63, "Windows 8.1", HttpUserAgentPlatformType.Windows)), + ("windows nt 6.2", new(HttpUserAgentPlatformRegexId.WindowsNt62, "Windows 8", HttpUserAgentPlatformType.Windows)), + ("windows nt 6.0", new(HttpUserAgentPlatformRegexId.WindowsNt60, "Windows Vista", HttpUserAgentPlatformType.Windows)), + // Android (very common on mobile) + ("android", new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android)), + // iOS devices (very common) + ("iphone", new(HttpUserAgentPlatformRegexId.IPhone, "iOS", HttpUserAgentPlatformType.IOS)), + ("ipad", new(HttpUserAgentPlatformRegexId.IPad, "iOS", HttpUserAgentPlatformType.IOS)), + ("ipod", new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS)), + // ChromeOS (must be before "os x" to avoid false match with "CrOS") + ("cros", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), + // Mac OS (common) + ("os x", new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS)), + // Linux (common) + ("linux", new(HttpUserAgentPlatformRegexId.Linux, "Linux", HttpUserAgentPlatformType.Linux)), + // Other Windows versions + ("windows phone", new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows)), + ("windows nt 5.2", new(HttpUserAgentPlatformRegexId.WindowsNt52, "Windows 2003", HttpUserAgentPlatformType.Windows)), + ("windows nt 5.1", new(HttpUserAgentPlatformRegexId.WindowsNt51, "Windows XP", HttpUserAgentPlatformType.Windows)), + ("windows nt 5.0", new(HttpUserAgentPlatformRegexId.WindowsNt50, "Windows 2000", HttpUserAgentPlatformType.Windows)), + ("windows nt 4.0", new(HttpUserAgentPlatformRegexId.WindowsNt40, "Windows NT 4.0", HttpUserAgentPlatformType.Windows)), + ("winnt4.0", new(HttpUserAgentPlatformRegexId.WinNt40, "Windows NT 4.0", HttpUserAgentPlatformType.Windows)), + ("winnt 4.0", new(HttpUserAgentPlatformRegexId.WinNtSpace40, "Windows NT", HttpUserAgentPlatformType.Windows)), + ("winnt", new(HttpUserAgentPlatformRegexId.WinNt, "Windows NT", HttpUserAgentPlatformType.Windows)), + ("windows 98", new(HttpUserAgentPlatformRegexId.Windows98, "Windows 98", HttpUserAgentPlatformType.Windows)), + ("win98", new(HttpUserAgentPlatformRegexId.Win98, "Windows 98", HttpUserAgentPlatformType.Windows)), + ("windows 95", new(HttpUserAgentPlatformRegexId.Windows95, "Windows 95", HttpUserAgentPlatformType.Windows)), + ("win95", new(HttpUserAgentPlatformRegexId.Win95, "Windows 95", HttpUserAgentPlatformType.Windows)), + ("windows", new(HttpUserAgentPlatformRegexId.Windows, "Unknown Windows OS", HttpUserAgentPlatformType.Windows)), + // Less common platforms + ("blackberry", new(HttpUserAgentPlatformRegexId.BlackBerry, "BlackBerry", HttpUserAgentPlatformType.BlackBerry)), + ("ppc mac", new(HttpUserAgentPlatformRegexId.PpcMac, "Power PC Mac", HttpUserAgentPlatformType.MacOS)), + ("debian", new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux)), + ("freebsd", new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Linux)), + ("ppc", new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.Linux)), + ("gnu", new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux)), + ("unix", new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix)), + ("openbsd", new(HttpUserAgentPlatformRegexId.OpenBsd, "OpenBSD", HttpUserAgentPlatformType.Unix)), + ("symbian", new(HttpUserAgentPlatformRegexId.Symbian, "Symbian OS", HttpUserAgentPlatformType.Symbian)), + ("sunos", new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Generic)), + ("beos", new(HttpUserAgentPlatformRegexId.BeOs, "BeOS", HttpUserAgentPlatformType.Generic)), + ("apachebench", new(HttpUserAgentPlatformRegexId.ApacheBench, "ApacheBench", HttpUserAgentPlatformType.Generic)), + ("aix", new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Generic)), + ("irix", new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Generic)), + ("osf", new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Generic)), + ("hp-ux", new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Windows)), + ("netbsd", new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Generic)), + ("bsdi", new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Generic)), + ]; + + /// + /// Browser token rules for detection and version extraction. + /// Sorted by specificity first, then frequency - more specific tokens must come before generic ones + /// (e.g., Edge/Opera before Chrome, since Edge/Opera UAs contain "Chrome"). + /// + internal static readonly (string Name, string DetectToken, string? VersionToken)[] Browsers = + [ + // Most specific browsers first (contain Chrome/Mozilla in their UA) + ("Opera", "OPR", null), + ("Opera", "Opera", "Version/"), + ("Opera", "Opera", null), + ("Edge", "Edg", null), + ("Edge", "Edge", null), + ("Edge", "EdgA", null), + ("Edge", "EdgiOS", null), + ("Brave", "Brave Chrome", null), + ("Vivaldi", "Vivaldi", null), + ("Flock", "Flock", null), + // Chromium based browsers with their own token (their UAs contain "Chrome/" as well) + ("Samsung Internet", "SamsungBrowser", null), + ("Yandex Browser", "YaBrowser", null), + ("UC Browser", "UCBrowser", null), + ("UC Browser", "UCMobile", null), + // Common browsers + ("Chrome", "Chrome", null), + ("Chrome", "CriOS", null), + ("Safari", "Version/", "Version/"), + ("Firefox", "Firefox", null), + ("Firefox", "FxiOS", null), + // Internet Explorer (legacy but still in use - MSIE before Trident to avoid false matches) + ("Internet Explorer", "MSIE", "MSIE "), + ("Internet Explorer", "Trident", "rv:"), + ("Internet Explorer", "Internet Explorer", null), + // Less common browsers + ("Maxthon", "Maxthon", null), + ("Netscape", "Netscape", null), + ("Konqueror", "Konqueror", null), + ("OmniWeb", "OmniWeb", null), + ("Shiira", "Shiira", null), + ("Chimera", "Chimera", null), + ("Camino", "Camino", null), + ("Firebird", "Firebird", null), + ("Phoenix", "Phoenix", null), + ("iCab", "icab", null), + ("Lynx", "Lynx", null), + ("Links", "Links", null), + ("HotJava", "hotjava", null), + ("Amaya", "amaya", null), + ("IBrowse", "IBrowse", null), + ("Apple iPod", "ipod touch", null), + ("Ubuntu Web Browser", "Ubuntu", null), + ]; + + /// + /// Robot rules. This array instance is exposed as ; entries replaced by callers are honored. + /// + internal static readonly (string Key, string Value)[] Robots = + [ + ( "googlebot", "Googlebot" ), + ( "meta-externalagent", "meta-externalagent" ), + ( "openai.com/searchbot", "OAI-SearchBot" ), + ( "CCBot", "CCBot" ), + ( "archive.org/details/archive.org_bot", "archive.org" ), + ( "opensiteexplorer.org/dotbot", "DotBot" ), + ( "awario.com/bots.html", "AwarioBot" ), + ( "Turnitin", "Turnitin" ), + ( "openai.com/gptbot", "GPTBot" ), + ( "perplexity.ai/perplexitybot", "PerplexityBot" ), + ( "developer.amazon.com/support/amazonbot", "Amazonbot" ), + ( "trendictionbot", "trendictionbot" ), + ( "openai.com/searchbot", "OAI-SearchBot" ), + ( "Bytespider", "Bytespider" ), + ( "MojeekBot", "MojeekBot" ), + ( "SeekportBot", "SeekportBot" ), + ( "googleweblight", "Google Web Light" ), + ( "PetalBot", "PetalBot"), + ( "DuplexWeb-Google", "DuplexWeb-Google"), + ( "Storebot-Google", "Storebot-Google"), + ( "msnbot", "MSNBot"), + ( "baiduspider", "Baiduspider"), + ( "Google Favicon", "Google Favicon"), + ( "Jobboerse", "Jobboerse"), + ( "bingbot", "BingBot"), + ( "BingPreview", "Bing Preview"), + ( "slurp", "Slurp"), + ( "yahoo", "Yahoo"), + ( "ask jeeves", "Ask Jeeves"), + ( "fastcrawler", "FastCrawler"), + ( "infoseek", "InfoSeek Robot 1.0"), + ( "lycos", "Lycos"), + ( "YandexBot", "YandexBot"), + ( "YandexImages", "YandexImages"), + ( "mediapartners-google", "Mediapartners Google"), + ( "apis-google", "APIs Google"), + ( "CRAZYWEBCRAWLER", "Crazy Webcrawler"), + ( "AdsBot-Google-Mobile", "AdsBot Google Mobile"), + ( "adsbot-google", "AdsBot Google"), + ( "feedfetcher-google", "FeedFetcher-Google"), + ( "google-read-aloud", "Google-Read-Aloud"), + ( "curious george", "Curious George"), + ( "ia_archiver", "Alexa Crawler"), + ( "MJ12bot", "Majestic"), + ( "Uptimebot", "Uptimebot"), + ( "CheckMarkNetwork", "CheckMark"), + ( "facebookexternalhit", "Facebook"), + ( "adscanner", "AdScanner"), + ( "AhrefsBot", "Ahrefs"), + ( "BLEXBot", "BLEXBot"), + ( "DotBot", "OpenSite"), + ( "Mail.RU_Bot", "Mail.ru"), + ( "MegaIndex", "MegaIndex"), + ( "SemrushBot", "SEMRush"), + ( "SEOkicks", "SEOkicks"), + ( "seoscanners.net", "SEO Scanners"), + ( "Sistrix", "Sistrix" ), + ( "WhatsApp", "WhatsApp" ), + ( "CensysInspect", "CensysInspect" ), + ( "InternetMeasurement", "InternetMeasurement" ), + ( "Barkrowler", "Barkrowler" ), + ( "BrightEdge", "BrightEdge" ), + ( "ImagesiftBot", "ImagesiftBot" ), + ( "Cotoyogi", "Cotoyogi" ), + ( "Applebot", "Applebot" ), + ( "360Spider", "360Spider" ), + ( "GeedoProductSearch", "GeedoProductSearch" ), + // Search engine crawlers + ( "Google-InspectionTool", "Google-InspectionTool" ), + ( "GoogleOther", "GoogleOther" ), + ( "Google-CloudVertexBot", "Google-CloudVertexBot" ), + ( "DuckDuckBot", "DuckDuckBot" ), + ( "SeznamBot", "SeznamBot" ), + ( "Sogou web spider", "Sogou" ), // "Sogou" alone would match the Sogou browser + ( "Yeti/", "Naver Yeti" ), + ( "Qwantbot", "Qwantbot" ), + // SEO crawlers + ( "AhrefsSiteAudit", "Ahrefs Site Audit" ), + ( "SiteAuditBot", "SiteAuditBot" ), + ( "rogerbot", "rogerbot" ), + ( "Screaming Frog SEO Spider", "Screaming Frog SEO Spider" ), + ( "DataForSeoBot", "DataForSeoBot" ), + ( "serpstatbot", "serpstatbot" ), + // AI crawlers and AI user agents (Claude-SearchBot and Claude-User contain "claudebot@anthropic.com") + ( "ChatGPT-User", "ChatGPT-User" ), + ( "Claude-SearchBot", "Claude-SearchBot" ), + ( "Claude-User", "Claude-User" ), + ( "ClaudeBot", "ClaudeBot" ), + ( "Perplexity-User", "Perplexity-User" ), + ( "Amazonbot", "Amazonbot" ), + ( "meta-externalfetcher", "meta-externalfetcher" ), + ( "cohere-ai", "cohere-ai" ), + ( "Diffbot", "Diffbot" ), + ( "MistralAI-User", "MistralAI-User" ), + ( "DuckAssistBot", "DuckAssistBot" ), + ( "AI2Bot", "AI2Bot" ), + ( "YouBot", "YouBot" ), + ]; + +#if NET9_0_OR_GREATER + /// + /// The default robot keys, used to detect entries replaced by callers. + /// + internal static readonly string[] DefaultRobotKeys = Array.ConvertAll(Robots, static robot => robot.Key); + + /// + /// Robot token matcher over the default keys. "googlebot" gets its own group: it is by far the most common robot. + /// + internal static readonly PriorityTokenMatcher RobotMatcher = new(DefaultRobotKeys, 1); + + /// + /// Short substrings ("anchors") of the default robot keys. Every key contains at least one anchor, + /// so a user agent without any anchor cannot match a default key. The few anchors need far fewer vectorized + /// passes than all keys, which makes the common case (a browser) cheap. + /// + internal static readonly string[] CuratedRobotAnchors = + [ + "bot", "spider", "crawl", "google", "-user", "external", "slurp", "yahoo", + "jeeves", "infoseek", "lycos", "yandex", "curious", "archiver", "turnitin", "jobboerse", + "bingpreview", "checkmark", "adscanner", "megaindex", "seo", "sistrix", "whatsapp", "censys", + "measurement", "barkrowler", "brightedge", "cotoyogi", "geedo", "ahrefs", "cohere", "yeti/", + ]; + + /// + /// Matcher over the robot anchors, see . + /// + internal static readonly PriorityTokenMatcher RobotAnchorMatcher = new(CreateRobotAnchors(DefaultRobotKeys, CuratedRobotAnchors)); + + /// + /// Returns plus every key that contains none of them, + /// so the anchors always cover all . + /// + internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAnchors) + { + List anchors = [.. curatedAnchors]; + foreach (string key in keys) + { + if (!anchors.Exists(anchor => key.Contains(anchor, StringComparison.OrdinalIgnoreCase))) + { + anchors.Add(key); + } + } + + return [.. anchors]; + } + + /// + /// Raw contents (string references) of at startup. + /// + private static readonly byte[] s_robotsSnapshot = CreateRobotsSnapshot(); + + /// + /// Returns if no entry of has been replaced. + /// + /// + /// Compares the string references of all entries with the startup snapshot in a single vectorized operation, + /// which is much cheaper than checking every entry on each parse. + /// + internal static bool AreRobotsUnchanged() => GetRawContents(Robots).SequenceEqual(s_robotsSnapshot); + + private static byte[] CreateRobotsSnapshot() + { + // Pin the default strings: their addresses must stay valid identities for the lifetime of the process. + // (String literals are allocated on the frozen heap anyway, so this does not restrict the GC in practice.) + foreach ((string key, string value) in Robots) + { + _ = GCHandle.Alloc(key, GCHandleType.Pinned); + _ = GCHandle.Alloc(value, GCHandleType.Pinned); + } + + return GetRawContents(Robots).ToArray(); + } + + private static ReadOnlySpan GetRawContents((string Key, string Value)[] robots) + => MemoryMarshal.CreateReadOnlySpan( + ref Unsafe.As<(string Key, string Value), byte>(ref MemoryMarshal.GetArrayDataReference(robots)), + robots.Length * Unsafe.SizeOf<(string Key, string Value)>()); +#endif + + /// + /// Mobile device rules in priority order: the most specific match wins. + /// + /// + /// + /// Legacy devices and browsers + /// Devices and manufacturers (e.g. "Samsung" before the "Android" operating system) + /// Operating systems + /// Mobile browsers + /// Carriers and other + /// Generic fallbacks ("mobile", ...) + /// + /// A token that contains another token comes first ("palmsource" before "palm", "nintendo dsi" before "nintendo ds", + /// "SymbianOS" before "symbian"). + /// The order is explicit on purpose: the enumeration order of a (frozen) dictionary is unspecified and must not decide the priority. + /// + internal static readonly (string Key, string Value)[] Mobiles = + [ + // Legacy + ("mobileexplorer", "Mobile Explorer"), + ("palmsource", "Palm"), + ("palmscape", "Palmscape"), + // Phones and manufacturers + ("motorola", "Motorola"), + ("nokia", "Nokia"), + ("palm", "Palm"), + ("ipad", "Apple iPad"), + ("ipod", "Apple iPod"), + ("iphone", "Apple iPhone"), + ("sony", "Sony Ericsson"), + ("ericsson", "Sony Ericsson"), + ("blackberry", "BlackBerry"), + ("cocoon", "O2 Cocoon"), + ("blazer", "Treo"), + ("lg", "LG"), + ("amoi", "Amoi"), + ("xda", "XDA"), + ("mda", "MDA"), + ("vario", "Vario"), + ("htc", "HTC"), + ("samsung", "Samsung"), + ("sharp", "Sharp"), + ("sie-", "Siemens"), + ("alcatel", "Alcatel"), + ("benq", "BenQ"), + ("ipaq", "HP iPaq"), + ("mot-", "Motorola"), + ("playstation portable", "PlayStation Portable"), + ("playstation 3", "PlayStation 3"), + ("playstation vita", "PlayStation Vita"), + ("hiptop", "Danger Hiptop"), + ("nec-", "NEC"), + ("panasonic", "Panasonic"), + ("philips", "Philips"), + ("sagem", "Sagem"), + ("sanyo", "Sanyo"), + ("spv", "SPV"), + ("zte", "ZTE"), + ("sendo", "Sendo"), + ("nintendo dsi", "Nintendo DSi"), + ("nintendo ds", "Nintendo DS"), + ("nintendo 3ds", "Nintendo 3DS"), + ("wii", "Nintendo Wii"), + ("open web", "Open Web"), + ("openweb", "OpenWeb"), + // Operating systems + ("android", "Android"), + ("SymbianOS", "SymbianOS"), + ("symbian", "Symbian"), + ("elaine", "Palm"), + ("series60", "Symbian S60"), + ("windows ce", "Windows CE"), + // Browsers + ("obigo", "Obigo"), + ("netfront", "Netfront Browser"), + ("openwave", "Openwave Browser"), + ("mobilexplorer", "Mobile Explorer"), + ("operamini", "Opera Mini"), + ("opera mini", "Opera Mini"), + ("opera mobi", "Opera Mobile"), + ("fennec", "Firefox Mobile"), + // Other + ("digital paths", "Digital Paths"), + ("avantgo", "AvantGo"), + ("xiino", "Xiino"), + ("novarra", "Novarra Transcoder"), + ("vodafone", "Vodafone"), + ("docomo", "NTT DoCoMo"), + ("o2", "O2"), + // Fallback + ("mobile", "Generic Mobile"), + ("wireless", "Generic Mobile"), + ("j2me", "Generic Mobile"), + ("midp", "Generic Mobile"), + ("cldc", "Generic Mobile"), + ("up.link", "Generic Mobile"), + ("up.browser", "Generic Mobile"), + ("smartphone", "Generic Mobile"), + ("cellphone", "Generic Mobile"), + ]; + + /// + /// Mobile token matcher. + /// + internal static readonly PriorityTokenMatcher MobileMatcher = new(Array.ConvertAll(Mobiles, static rule => rule.Key)); + + /// + /// Creates the public, case-insensitive lookup of . + /// + internal static FrozenDictionary CreateMobileDictionary() + => Mobiles.ToFrozenDictionary(static rule => rule.Key, static rule => rule.Value, StringComparer.OrdinalIgnoreCase); +} diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index e994f77..8c13aa1 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -1,8 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -#if NET9_0_OR_GREATER -using System.Buffers; -#endif using System.Collections.Frozen; using System.Text.RegularExpressions; @@ -11,416 +8,123 @@ namespace MyCSharp.HttpUserAgentParser; /// /// Parser settings /// +/// +/// The parser does not read , , or ; +/// they are provided for consumers. is shared with the parser: replaced entries are honored. +/// All regular expressions are source-generated (no runtime compilation, trimming and Native AOT compatible). +/// public static class HttpUserAgentStatics { - /// - /// Regex defauls for platform mappings - /// - private const RegexOptions DefaultPlatformsRegexFlags = RegexOptions.IgnoreCase | RegexOptions.Compiled; - - /// - /// Creates default platform mapping regex - /// - private static Regex CreateDefaultPlatformRegex(string key) => new(Regex.Escape($"{key}"), - DefaultPlatformsRegexFlags, matchTimeout: TimeSpan.FromMilliseconds(1000)); - /// /// Platforms /// + /// + /// The of each entry is created on first access. + /// public static readonly HashSet Platforms = [ - new(CreateDefaultPlatformRegex("windows nt 10.0"), "Windows 10", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 6.3"), "Windows 8.1", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 6.2"), "Windows 8", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 6.1"), "Windows 7", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 6.0"), "Windows Vista", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 5.2"), "Windows 2003", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 5.1"), "Windows XP", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 5.0"), "Windows 2000", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows nt 4.0"), "Windows NT 4.0", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("winnt4.0"), "Windows NT 4.0", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("winnt 4.0"), "Windows NT", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("winnt"), "Windows NT", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows 98"), "Windows 98", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("win98"), "Windows 98", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows 95"), "Windows 95", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("win95"), "Windows 95", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows phone"), "Windows Phone", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("windows"), "Unknown Windows OS", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("android"), "Android", HttpUserAgentPlatformType.Android), - new(CreateDefaultPlatformRegex("blackberry"), "BlackBerry", HttpUserAgentPlatformType.BlackBerry), - new(CreateDefaultPlatformRegex("iphone"), "iOS", HttpUserAgentPlatformType.IOS), - new(CreateDefaultPlatformRegex("ipad"), "iOS", HttpUserAgentPlatformType.IOS), - new(CreateDefaultPlatformRegex("ipod"), "iOS", HttpUserAgentPlatformType.IOS), - new(CreateDefaultPlatformRegex("cros"), "ChromeOS", HttpUserAgentPlatformType.ChromeOS), - new(CreateDefaultPlatformRegex("os x"), "Mac OS X", HttpUserAgentPlatformType.MacOS), - new(CreateDefaultPlatformRegex("ppc mac"), "Power PC Mac", HttpUserAgentPlatformType.MacOS), - new(CreateDefaultPlatformRegex("freebsd"), "FreeBSD", HttpUserAgentPlatformType.Linux), - new(CreateDefaultPlatformRegex("ppc"), "Macintosh", HttpUserAgentPlatformType.Linux), - new(CreateDefaultPlatformRegex("linux"), "Linux", HttpUserAgentPlatformType.Linux), - new(CreateDefaultPlatformRegex("debian"), "Debian", HttpUserAgentPlatformType.Linux), - new(CreateDefaultPlatformRegex("sunos"), "Sun Solaris", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("beos"), "BeOS", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("apachebench"), "ApacheBench", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("aix"), "AIX", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("irix"), "Irix", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("osf"), "DEC OSF", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("hp-ux"), "HP-UX", HttpUserAgentPlatformType.Windows), - new(CreateDefaultPlatformRegex("netbsd"), "NetBSD", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("bsdi"), "BSDi", HttpUserAgentPlatformType.Generic), - new(CreateDefaultPlatformRegex("openbsd"), "OpenBSD", HttpUserAgentPlatformType.Unix), - new(CreateDefaultPlatformRegex("gnu"), "GNU/Linux", HttpUserAgentPlatformType.Linux), - new(CreateDefaultPlatformRegex("unix"), "Unknown Unix OS", HttpUserAgentPlatformType.Unix), - new(CreateDefaultPlatformRegex("symbian"), "Symbian OS", HttpUserAgentPlatformType.Symbian), - ]; - - /// - /// Fast-path platform token rules for zero-allocation Contains checks - /// Sorted by frequency for better performance (most common platforms first) - /// - internal static readonly (string Token, string Name, HttpUserAgentPlatformType PlatformType)[] s_platformRules = - [ - // Most common: Windows (specific versions before generic) - ("windows nt 10.0", "Windows 10", HttpUserAgentPlatformType.Windows), - ("windows nt 6.1", "Windows 7", HttpUserAgentPlatformType.Windows), - ("windows nt 6.3", "Windows 8.1", HttpUserAgentPlatformType.Windows), - ("windows nt 6.2", "Windows 8", HttpUserAgentPlatformType.Windows), - ("windows nt 6.0", "Windows Vista", HttpUserAgentPlatformType.Windows), - // Android (very common on mobile) - ("android", "Android", HttpUserAgentPlatformType.Android), - // iOS devices (very common) - ("iphone", "iOS", HttpUserAgentPlatformType.IOS), - ("ipad", "iOS", HttpUserAgentPlatformType.IOS), - ("ipod", "iOS", HttpUserAgentPlatformType.IOS), - // ChromeOS (must be before "os x" to avoid false match with "CrOS") - ("cros", "ChromeOS", HttpUserAgentPlatformType.ChromeOS), - // Mac OS (common) - ("os x", "Mac OS X", HttpUserAgentPlatformType.MacOS), - // Linux (common) - ("linux", "Linux", HttpUserAgentPlatformType.Linux), - // Other Windows versions - ("windows phone", "Windows Phone", HttpUserAgentPlatformType.Windows), - ("windows nt 5.2", "Windows 2003", HttpUserAgentPlatformType.Windows), - ("windows nt 5.1", "Windows XP", HttpUserAgentPlatformType.Windows), - ("windows nt 5.0", "Windows 2000", HttpUserAgentPlatformType.Windows), - ("windows nt 4.0", "Windows NT 4.0", HttpUserAgentPlatformType.Windows), - ("winnt4.0", "Windows NT 4.0", HttpUserAgentPlatformType.Windows), - ("winnt 4.0", "Windows NT", HttpUserAgentPlatformType.Windows), - ("winnt", "Windows NT", HttpUserAgentPlatformType.Windows), - ("windows 98", "Windows 98", HttpUserAgentPlatformType.Windows), - ("win98", "Windows 98", HttpUserAgentPlatformType.Windows), - ("windows 95", "Windows 95", HttpUserAgentPlatformType.Windows), - ("win95", "Windows 95", HttpUserAgentPlatformType.Windows), - ("windows", "Unknown Windows OS", HttpUserAgentPlatformType.Windows), - // Less common platforms - ("blackberry", "BlackBerry", HttpUserAgentPlatformType.BlackBerry), - ("ppc mac", "Power PC Mac", HttpUserAgentPlatformType.MacOS), - ("debian", "Debian", HttpUserAgentPlatformType.Linux), - ("freebsd", "FreeBSD", HttpUserAgentPlatformType.Linux), - ("ppc", "Macintosh", HttpUserAgentPlatformType.Linux), - ("gnu", "GNU/Linux", HttpUserAgentPlatformType.Linux), - ("unix", "Unknown Unix OS", HttpUserAgentPlatformType.Unix), - ("openbsd", "OpenBSD", HttpUserAgentPlatformType.Unix), - ("symbian", "Symbian OS", HttpUserAgentPlatformType.Symbian), - ("sunos", "Sun Solaris", HttpUserAgentPlatformType.Generic), - ("beos", "BeOS", HttpUserAgentPlatformType.Generic), - ("apachebench", "ApacheBench", HttpUserAgentPlatformType.Generic), - ("aix", "AIX", HttpUserAgentPlatformType.Generic), - ("irix", "Irix", HttpUserAgentPlatformType.Generic), - ("osf", "DEC OSF", HttpUserAgentPlatformType.Generic), - ("hp-ux", "HP-UX", HttpUserAgentPlatformType.Windows), - ("netbsd", "NetBSD", HttpUserAgentPlatformType.Generic), - ("bsdi", "BSDi", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.WindowsNt100, "Windows 10", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt63, "Windows 8.1", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt62, "Windows 8", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt61, "Windows 7", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt60, "Windows Vista", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt52, "Windows 2003", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt51, "Windows XP", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt50, "Windows 2000", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsNt40, "Windows NT 4.0", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WinNt40, "Windows NT 4.0", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WinNtSpace40, "Windows NT", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WinNt, "Windows NT", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.Windows98, "Windows 98", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.Win98, "Windows 98", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.Windows95, "Windows 95", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.Win95, "Windows 95", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.Windows, "Unknown Windows OS", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android), + new(HttpUserAgentPlatformRegexId.BlackBerry, "BlackBerry", HttpUserAgentPlatformType.BlackBerry), + new(HttpUserAgentPlatformRegexId.IPhone, "iOS", HttpUserAgentPlatformType.IOS), + new(HttpUserAgentPlatformRegexId.IPad, "iOS", HttpUserAgentPlatformType.IOS), + new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS), + new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS), + new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS), + new(HttpUserAgentPlatformRegexId.PpcMac, "Power PC Mac", HttpUserAgentPlatformType.MacOS), + new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Linux), + new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.Linux), + new(HttpUserAgentPlatformRegexId.Linux, "Linux", HttpUserAgentPlatformType.Linux), + new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux), + new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.BeOs, "BeOS", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.ApacheBench, "ApacheBench", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Windows), + new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.OpenBsd, "OpenBSD", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux), + new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.Symbian, "Symbian OS", HttpUserAgentPlatformType.Symbian), ]; - // Precompiled platform regex map to attach to PlatformInformation without per-call allocations - private static readonly FrozenDictionary s_platformRegexMap = s_platformRules - .ToFrozenDictionary(p => p.Token, p => CreateDefaultPlatformRegex(p.Token), StringComparer.OrdinalIgnoreCase); - - internal static Regex GetPlatformRegexForToken(string token) => s_platformRegexMap[token]; - - /// - /// Regex defauls for browser mappings - /// - private const RegexOptions DefaultBrowserRegexFlags = RegexOptions.IgnoreCase | RegexOptions.Compiled; - /// - /// Creates default browser mapping regex - /// - private static Regex CreateDefaultBrowserRegex(string key) - => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags, matchTimeout: TimeSpan.FromMilliseconds(1000)); - /// /// Browsers /// + /// + /// Each pattern is {token}.*?([0-9\.]+); the first group captures the version. + /// public static readonly FrozenDictionary Browsers = new Dictionary() { - { CreateDefaultBrowserRegex("OPR"), "Opera" }, - { CreateDefaultBrowserRegex("Flock"), "Flock" }, - { CreateDefaultBrowserRegex("Edge"), "Edge" }, - { CreateDefaultBrowserRegex("EdgA"), "Edge" }, - { CreateDefaultBrowserRegex("Edg"), "Edge" }, - { CreateDefaultBrowserRegex("Vivaldi"), "Vivaldi" }, - { CreateDefaultBrowserRegex("Brave Chrome"), "Brave" }, - { CreateDefaultBrowserRegex("Chrome"), "Chrome" }, - { CreateDefaultBrowserRegex("CriOS"), "Chrome" }, - { CreateDefaultBrowserRegex("Opera.*?Version"), "Opera" }, - { CreateDefaultBrowserRegex("Opera"), "Opera" }, - { CreateDefaultBrowserRegex("MSIE"), "Internet Explorer" }, - { CreateDefaultBrowserRegex("Internet Explorer"), "Internet Explorer" }, - { CreateDefaultBrowserRegex("Trident.* rv"), "Internet Explorer" }, - { CreateDefaultBrowserRegex("Shiira"), "Shiira" }, - { CreateDefaultBrowserRegex("Firefox"), "Firefox" }, - { CreateDefaultBrowserRegex("FxiOS"), "Firefox" }, - { CreateDefaultBrowserRegex("Chimera"), "Chimera" }, - { CreateDefaultBrowserRegex("Phoenix"), "Phoenix" }, - { CreateDefaultBrowserRegex("Firebird"), "Firebird" }, - { CreateDefaultBrowserRegex("Camino"), "Camino" }, - { CreateDefaultBrowserRegex("Netscape"), "Netscape" }, - { CreateDefaultBrowserRegex("OmniWeb"), "OmniWeb" }, - { CreateDefaultBrowserRegex("Version"), "Safari" }, // https://github.com/mycsharp/HttpUserAgentParser/issues/34 - { CreateDefaultBrowserRegex("Mozilla"), "Mozilla" }, - { CreateDefaultBrowserRegex("Konqueror"), "Konqueror" }, - { CreateDefaultBrowserRegex("icab"), "iCab" }, - { CreateDefaultBrowserRegex("Lynx"), "Lynx" }, - { CreateDefaultBrowserRegex("Links"), "Links" }, - { CreateDefaultBrowserRegex("hotjava"), "HotJava" }, - { CreateDefaultBrowserRegex("amaya"), "Amaya" }, - { CreateDefaultBrowserRegex("IBrowse"), "IBrowse" }, - { CreateDefaultBrowserRegex("Maxthon"), "Maxthon" }, - { CreateDefaultBrowserRegex("ipod touch"), "Apple iPod" }, - { CreateDefaultBrowserRegex("Ubuntu"), "Ubuntu Web Browser" }, + { HttpUserAgentRegexes.BrowserOpr(), "Opera" }, + { HttpUserAgentRegexes.BrowserFlock(), "Flock" }, + { HttpUserAgentRegexes.BrowserEdge(), "Edge" }, + { HttpUserAgentRegexes.BrowserEdgA(), "Edge" }, + { HttpUserAgentRegexes.BrowserEdg(), "Edge" }, + { HttpUserAgentRegexes.BrowserVivaldi(), "Vivaldi" }, + { HttpUserAgentRegexes.BrowserBraveChrome(), "Brave" }, + { HttpUserAgentRegexes.BrowserChrome(), "Chrome" }, + { HttpUserAgentRegexes.BrowserCriOS(), "Chrome" }, + { HttpUserAgentRegexes.BrowserOperaVersion(), "Opera" }, + { HttpUserAgentRegexes.BrowserOpera(), "Opera" }, + { HttpUserAgentRegexes.BrowserMsie(), "Internet Explorer" }, + { HttpUserAgentRegexes.BrowserInternetExplorer(), "Internet Explorer" }, + { HttpUserAgentRegexes.BrowserTridentRv(), "Internet Explorer" }, + { HttpUserAgentRegexes.BrowserShiira(), "Shiira" }, + { HttpUserAgentRegexes.BrowserFirefox(), "Firefox" }, + { HttpUserAgentRegexes.BrowserFxiOS(), "Firefox" }, + { HttpUserAgentRegexes.BrowserChimera(), "Chimera" }, + { HttpUserAgentRegexes.BrowserPhoenix(), "Phoenix" }, + { HttpUserAgentRegexes.BrowserFirebird(), "Firebird" }, + { HttpUserAgentRegexes.BrowserCamino(), "Camino" }, + { HttpUserAgentRegexes.BrowserNetscape(), "Netscape" }, + { HttpUserAgentRegexes.BrowserOmniWeb(), "OmniWeb" }, + { HttpUserAgentRegexes.BrowserVersion(), "Safari" }, // https://github.com/mycsharp/HttpUserAgentParser/issues/34 + { HttpUserAgentRegexes.BrowserMozilla(), "Mozilla" }, + { HttpUserAgentRegexes.BrowserKonqueror(), "Konqueror" }, + { HttpUserAgentRegexes.BrowserICab(), "iCab" }, + { HttpUserAgentRegexes.BrowserLynx(), "Lynx" }, + { HttpUserAgentRegexes.BrowserLinks(), "Links" }, + { HttpUserAgentRegexes.BrowserHotJava(), "HotJava" }, + { HttpUserAgentRegexes.BrowserAmaya(), "Amaya" }, + { HttpUserAgentRegexes.BrowserIBrowse(), "IBrowse" }, + { HttpUserAgentRegexes.BrowserMaxthon(), "Maxthon" }, + { HttpUserAgentRegexes.BrowserIPodTouch(), "Apple iPod" }, + { HttpUserAgentRegexes.BrowserUbuntu(), "Ubuntu Web Browser" }, }.ToFrozenDictionary(); - /// - /// Browser token rules for detection and version extraction. - /// Sorted by specificity first, then frequency - more specific tokens must come before generic ones - /// (e.g., Edge/Opera before Chrome, since Edge/Opera UAs contain "Chrome") - /// - internal static readonly (string Name, string DetectToken, string? VersionToken)[] s_browserRules = - [ - // Most specific browsers first (contain Chrome/Mozilla in their UA) - ("Opera", "OPR", null), - ("Opera", "Opera", "Version/"), - ("Opera", "Opera", null), - ("Edge", "Edg", null), - ("Edge", "Edge", null), - ("Edge", "EdgA", null), - ("Edge", "EdgiOS", null), - ("Brave", "Brave Chrome", null), - ("Vivaldi", "Vivaldi", null), - ("Flock", "Flock", null), - // Common browsers - ("Chrome", "Chrome", null), - ("Chrome", "CriOS", null), - ("Safari", "Version/", "Version/"), - ("Firefox", "Firefox", null), - ("Firefox", "FxiOS", null), - // Internet Explorer (legacy but still in use - MSIE before Trident to avoid false matches) - ("Internet Explorer", "MSIE", "MSIE "), - ("Internet Explorer", "Trident", "rv:"), - ("Internet Explorer", "Internet Explorer", null), - // Less common browsers - ("Maxthon", "Maxthon", null), - ("Netscape", "Netscape", null), - ("Konqueror", "Konqueror", null), - ("OmniWeb", "OmniWeb", null), - ("Shiira", "Shiira", null), - ("Chimera", "Chimera", null), - ("Camino", "Camino", null), - ("Firebird", "Firebird", null), - ("Phoenix", "Phoenix", null), - ("iCab", "icab", null), - ("Lynx", "Lynx", null), - ("Links", "Links", null), - ("HotJava", "hotjava", null), - ("Amaya", "amaya", null), - ("IBrowse", "IBrowse", null), - ("Apple iPod", "ipod touch", null), - ("Ubuntu Web Browser", "Ubuntu", null), - ]; - /// /// Mobiles /// - public static readonly FrozenDictionary Mobiles = new Dictionary(StringComparer.InvariantCultureIgnoreCase) - { - // Legacy - { "mobileexplorer", "Mobile Explorer" }, - { "palmsource", "Palm" }, - { "palmscape", "Palmscape" }, - // Phones and Manufacturers - { "motorola", "Motorola" }, - { "nokia", "Nokia" }, - { "palm", "Palm" }, - { "ipad", "Apple iPad" }, - { "ipod", "Apple iPod" }, - { "iphone", "Apple iPhone" }, - { "sony", "Sony Ericsson" }, - { "ericsson", "Sony Ericsson" }, - { "blackberry", "BlackBerry" }, - { "cocoon", "O2 Cocoon" }, - { "blazer", "Treo" }, - { "lg", "LG" }, - { "amoi", "Amoi" }, - { "xda", "XDA" }, - { "mda", "MDA" }, - { "vario", "Vario" }, - { "htc", "HTC" }, - { "samsung", "Samsung" }, - { "sharp", "Sharp" }, - { "sie-", "Siemens" }, - { "alcatel", "Alcatel" }, - { "benq", "BenQ" }, - { "ipaq", "HP iPaq" }, - { "mot-", "Motorola" }, - { "playstation portable", "PlayStation Portable" }, - { "playstation 3", "PlayStation 3" }, - { "playstation vita", "PlayStation Vita" }, - { "hiptop", "Danger Hiptop" }, - { "nec-", "NEC" }, - { "panasonic", "Panasonic" }, - { "philips", "Philips" }, - { "sagem", "Sagem" }, - { "sanyo", "Sanyo" }, - { "spv", "SPV" }, - { "zte", "ZTE" }, - { "sendo", "Sendo" }, - { "nintendo dsi", "Nintendo DSi" }, - { "nintendo ds", "Nintendo DS" }, - { "nintendo 3ds", "Nintendo 3DS" }, - { "wii", "Nintendo Wii" }, - { "open web", "Open Web" }, - { "openweb", "OpenWeb" }, - // Operating Systems - { "android", "Android" }, - { "symbian", "Symbian" }, - { "SymbianOS", "SymbianOS" }, - { "elaine", "Palm" }, - { "series60", "Symbian S60" }, - { "windows ce", "Windows CE" }, - // Browsers - { "obigo", "Obigo" }, - { "netfront", "Netfront Browser" }, - { "openwave", "Openwave Browser" }, - { "mobilexplorer", "Mobile Explorer" }, - { "operamini", "Opera Mini" }, - { "opera mini", "Opera Mini" }, - { "opera mobi", "Opera Mobile" }, - { "fennec", "Firefox Mobile" }, - // Other - { "digital paths", "Digital Paths" }, - { "avantgo", "AvantGo" }, - { "xiino", "Xiino" }, - { "novarra", "Novarra Transcoder" }, - { "vodafone", "Vodafone" }, - { "docomo", "NTT DoCoMo" }, - { "o2", "O2" }, - // Fallback - { "mobile", "Generic Mobile" }, - { "wireless", "Generic Mobile" }, - { "j2me", "Generic Mobile" }, - { "midp", "Generic Mobile" }, - { "cldc", "Generic Mobile" }, - { "up.link", "Generic Mobile" }, - { "up.browser", "Generic Mobile" }, - { "smartphone", "Generic Mobile" }, - { "cellphone", "Generic Mobile" }, - }.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase); + public static readonly FrozenDictionary Mobiles = HttpUserAgentRules.CreateMobileDictionary(); /// /// Robots /// - public static readonly (string Key, string Value)[] Robots = - [ - ( "googlebot", "Googlebot" ), - ( "meta-externalagent", "meta-externalagent" ), - ( "openai.com/searchbot", "OAI-SearchBot" ), - ( "CCBot", "CCBot" ), - ( "archive.org/details/archive.org_bot", "archive.org" ), - ( "opensiteexplorer.org/dotbot", "DotBot" ), - ( "awario.com/bots.html", "AwarioBot" ), - ( "Turnitin", "Turnitin" ), - ( "openai.com/gptbot", "GPTBot" ), - ( "perplexity.ai/perplexitybot", "PerplexityBot" ), - ( "developer.amazon.com/support/amazonbot", "Amazonbot" ), - ( "trendictionbot", "trendictionbot" ), - ( "openai.com/searchbot", "OAI-SearchBot" ), - ( "Bytespider", "Bytespider" ), - ( "MojeekBot", "MojeekBot" ), - ( "SeekportBot", "SeekportBot" ), - ( "googleweblight", "Google Web Light" ), - ( "PetalBot", "PetalBot"), - ( "DuplexWeb-Google", "DuplexWeb-Google"), - ( "Storebot-Google", "Storebot-Google"), - ( "msnbot", "MSNBot"), - ( "baiduspider", "Baiduspider"), - ( "Google Favicon", "Google Favicon"), - ( "Jobboerse", "Jobboerse"), - ( "bingbot", "BingBot"), - ( "BingPreview", "Bing Preview"), - ( "slurp", "Slurp"), - ( "yahoo", "Yahoo"), - ( "ask jeeves", "Ask Jeeves"), - ( "fastcrawler", "FastCrawler"), - ( "infoseek", "InfoSeek Robot 1.0"), - ( "lycos", "Lycos"), - ( "YandexBot", "YandexBot"), - ( "YandexImages", "YandexImages"), - ( "mediapartners-google", "Mediapartners Google"), - ( "apis-google", "APIs Google"), - ( "CRAZYWEBCRAWLER", "Crazy Webcrawler"), - ( "AdsBot-Google-Mobile", "AdsBot Google Mobile"), - ( "adsbot-google", "AdsBot Google"), - ( "feedfetcher-google", "FeedFetcher-Google"), - ( "google-read-aloud", "Google-Read-Aloud"), - ( "curious george", "Curious George"), - ( "ia_archiver", "Alexa Crawler"), - ( "MJ12bot", "Majestic"), - ( "Uptimebot", "Uptimebot"), - ( "CheckMarkNetwork", "CheckMark"), - ( "facebookexternalhit", "Facebook"), - ( "adscanner", "AdScanner"), - ( "AhrefsBot", "Ahrefs"), - ( "BLEXBot", "BLEXBot"), - ( "DotBot", "OpenSite"), - ( "Mail.RU_Bot", "Mail.ru"), - ( "MegaIndex", "MegaIndex"), - ( "SemrushBot", "SEMRush"), - ( "SEOkicks", "SEOkicks"), - ( "seoscanners.net", "SEO Scanners"), - ( "Sistrix", "Sistrix" ), - ( "WhatsApp", "WhatsApp" ), - ( "CensysInspect", "CensysInspect" ), - ( "InternetMeasurement", "InternetMeasurement" ), - ( "Barkrowler", "Barkrowler" ), - ( "BrightEdge", "BrightEdge" ), - ( "ImagesiftBot", "ImagesiftBot" ), - ( "Cotoyogi", "Cotoyogi" ), - ( "Applebot", "Applebot" ), - ( "360Spider", "360Spider" ), - ( "GeedoProductSearch", "GeedoProductSearch" ) - ]; - -#if NET9_0_OR_GREATER - // Small groups let the runtime vectorize the substring checks and preserve rule priority. - internal const int TokenGroupSize = 8; - - internal static readonly string[] s_defaultRobotKeys = Array.ConvertAll(Robots, static robot => robot.Key); - internal static readonly SearchValues[] s_robotTokenGroups = CreateTokenGroups(s_defaultRobotKeys.AsSpan(1)); - internal static readonly SearchValues[] s_mobileTokenGroups = CreateTokenGroups(Mobiles.Keys.AsSpan()); - - private static SearchValues[] CreateTokenGroups(ReadOnlySpan tokens) - { - SearchValues[] groups = new SearchValues[(tokens.Length + TokenGroupSize - 1) / TokenGroupSize]; - for (int i = 0; i < groups.Length; i++) - { - ReadOnlySpan remaining = tokens[(i * TokenGroupSize)..]; - groups[i] = SearchValues.Create(remaining[..Math.Min(TokenGroupSize, remaining.Length)], StringComparison.OrdinalIgnoreCase); - } - - return groups; - } -#endif + /// + /// The parser uses this array directly: the first matching entry wins and replaced entries are honored. + /// + public static readonly (string Key, string Value)[] Robots = HttpUserAgentRules.Robots; /// /// Tools diff --git a/src/HttpUserAgentParser/PriorityTokenMatcher.cs b/src/HttpUserAgentParser/PriorityTokenMatcher.cs new file mode 100644 index 0000000..17a1d22 --- /dev/null +++ b/src/HttpUserAgentParser/PriorityTokenMatcher.cs @@ -0,0 +1,280 @@ +// Copyright © https://myCSharp.de - all rights reserved + +#if NET9_0_OR_GREATER +using System.Buffers; +#endif + +namespace MyCSharp.HttpUserAgentParser; + +/// +/// Finds the first token of a priority-ordered token list that occurs in an input +/// (ordinal, case-insensitive substring match). +/// +/// +/// A marker struct per detector (robot, mobile). Value type arguments give every detector its own +/// JIT-compiled code, so Dynamic PGO optimizes each call site for the +/// implementations of that detector instead of mixing the profiles of all detectors. +/// +/// +/// +/// On .NET 9 and later, consecutive tokens are grouped into small sets. +/// A single vectorized pass rejects a whole group, so only groups that may contain a match are checked +/// token by token. Groups never reorder tokens, which preserves the priority semantics of a sequential scan. +/// +/// +/// See PriorityTokenGroup for the group layout. +/// +/// +internal sealed class PriorityTokenMatcher + where TDetector : struct +{ + private readonly string[] _tokens; + +#if NET9_0_OR_GREATER + private readonly PriorityTokenGroup[] _groups; +#endif + + /// + /// Creates a matcher for in priority order. + /// + /// Tokens, highest priority first. + /// Token indices that must start a new group, e.g. to give a very frequent token its own group. + public PriorityTokenMatcher(string[] tokens, params ReadOnlySpan groupStarts) + { + _tokens = tokens; +#if NET9_0_OR_GREATER + _groups = PriorityTokenGroup.Create(tokens, groupStarts); +#else + _ = groupStarts; +#endif + } + + /// + /// Number of tokens. + /// + public int Count => _tokens.Length; + +#if NET9_0_OR_GREATER + /// + /// The token groups. + /// + internal ReadOnlySpan Groups => _groups; + + /// + /// Returns if any token occurs in ; only checks the group filters. + /// + public bool ContainsAny(ReadOnlySpan input) + { + foreach (ref readonly PriorityTokenGroup group in _groups.AsSpan()) + { + if (group.MayMatch(input)) + { + return true; + } + } + + return false; + } +#endif + + /// + /// Returns the index of the first token at or after that occurs in , + /// or -1 if none occurs. + /// + /// The text to search. + /// The first token index to consider. + /// The position of the first occurrence of the returned token in , otherwise -1. + public int Find(ReadOnlySpan input, int startIndex, out int position) + { + string[] tokens = _tokens; +#if NET9_0_OR_GREATER + foreach (ref readonly PriorityTokenGroup group in _groups.AsSpan()) + { + if (group.End <= startIndex || !group.MayMatch(input)) + { + continue; + } + + for (int i = Math.Max(group.Start, startIndex); i < group.End; i++) + { + position = input.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase); + if (position >= 0) + { + return i; + } + } + } +#else + for (int i = startIndex; i < tokens.Length; i++) + { + position = input.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase); + if (position >= 0) + { + return i; + } + } +#endif + + position = -1; + return -1; + } +} + +#if NET9_0_OR_GREATER +/// +/// A run of consecutive tokens of a that is rejected with one vectorized search. +/// +/// +/// The layout is tuned for the Teddy algorithm used by : at most eight values per group +/// (larger, bucketized groups verify many more false-positive candidates and are measurably slower), +/// tokens shorter than three characters are checked separately (they would force the slower two-character fingerprint +/// for the whole group), and tokens containing another token of the same group are dropped from the group filter +/// because whenever they occur, the shorter token occurs, too. +/// +internal readonly struct PriorityTokenGroup +{ + internal const int MaxValuesPerGroup = 8; + internal const int MinVectorizedTokenLength = 3; + + private PriorityTokenGroup(int start, int end, List values, List shortTokens) + { + Start = start; + End = end; + FilterValues = [.. values]; + Values = values.Count > 0 ? SearchValues.Create(FilterValues, StringComparison.OrdinalIgnoreCase) : null; + ShortTokens = [.. shortTokens]; + } + + /// + /// Index of the first token of the group. + /// + public int Start { get; } + + /// + /// Index after the last token of the group. + /// + public int End { get; } + + /// + /// The tokens used for the vectorized group filter (after removing redundant tokens). + /// + public string[] FilterValues { get; } + + /// + /// The vectorized group filter, if the group only has short tokens. + /// + public SearchValues? Values { get; } + + /// + /// Tokens shorter than , checked one by one. + /// + public string[] ShortTokens { get; } + + /// + /// Returns if no token of the group occurs in . + /// + public bool MayMatch(ReadOnlySpan input) + { + if (Values is not null && input.ContainsAny(Values)) + { + return true; + } + + foreach (string token in ShortTokens) + { + if (input.Contains(token, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + + return false; + } + + /// + /// Splits into groups. + /// + public static PriorityTokenGroup[] Create(string[] tokens, ReadOnlySpan groupStarts) + { + List groups = []; + List values = []; + List shortTokens = []; + int start = 0; + + for (int i = 0; i < tokens.Length; i++) + { + string token = tokens[i]; + if (i > start && (groupStarts.Contains(i) || !CanAdd(values, token))) + { + groups.Add(new PriorityTokenGroup(start, i, values, shortTokens)); + values.Clear(); + shortTokens.Clear(); + start = i; + } + + Add(values, shortTokens, token); + } + + if (tokens.Length > 0) + { + groups.Add(new PriorityTokenGroup(start, tokens.Length, values, shortTokens)); + } + + return [.. groups]; + } + + private static bool CanAdd(List values, string token) + { + if (token.Length < MinVectorizedTokenLength || IsCoveredBy(values, token)) + { + return true; + } + + int remaining = values.Count; + foreach (string value in values) + { + if (value.Contains(token, StringComparison.OrdinalIgnoreCase)) + { + remaining--; + } + } + + return remaining < MaxValuesPerGroup; + } + + private static void Add(List values, List shortTokens, string token) + { + if (token.Length < MinVectorizedTokenLength) + { + shortTokens.Add(token); + return; + } + + if (IsCoveredBy(values, token)) + { + return; + } + + // A value containing the new token is redundant: whenever it matches, the new token matches, too. + values.RemoveAll(value => value.Contains(token, StringComparison.OrdinalIgnoreCase)); + values.Add(token); + } + + /// + /// Returns if contains one of : + /// an occurrence of the token then always implies a match of the group filter. + /// + private static bool IsCoveredBy(List values, string token) + { + foreach (string value in values) + { + if (token.Contains(value, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + + return false; + } +} +#endif diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs index 0934b26..858ca4e 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; namespace MyCSharp.HttpUserAgentParser.Telemetry; @@ -14,7 +13,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// suitable for hot paths. /// [EventSource(Name = EventSourceName)] -[ExcludeFromCodeCoverage] public sealed class HttpUserAgentParserEventSource : EventSource { /// @@ -28,7 +26,7 @@ public sealed class HttpUserAgentParserEventSource : EventSource internal static HttpUserAgentParserEventSource Log { get; } = new(); private readonly IncrementingEventCounter _parseRequests; - private readonly EventCounter? _parseDurationSeconds; + private readonly EventCounter _parseDurationSeconds; private readonly IncrementingEventCounter _cacheHit; private readonly IncrementingEventCounter _cacheMiss; @@ -37,7 +35,10 @@ public sealed class HttpUserAgentParserEventSource : EventSource /// /// Initializes all EventCounters and polling counters used by this EventSource. /// - private HttpUserAgentParserEventSource() + /// + /// Use ; the constructor is only accessible for tests. + /// + internal HttpUserAgentParserEventSource() { // Parser _parseRequests = new IncrementingEventCounter("parse-requests", this) @@ -81,12 +82,10 @@ private HttpUserAgentParserEventSource() [NonEvent] internal void ParseRequest() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _parseRequests.Increment(); } - - _parseRequests?.Increment(); } /// @@ -96,12 +95,10 @@ internal void ParseRequest() [NonEvent] internal void ParseDuration(double seconds) { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _parseDurationSeconds.WriteMetric(seconds); } - - _parseDurationSeconds?.WriteMetric(seconds); } /// @@ -110,12 +107,10 @@ internal void ParseDuration(double seconds) [NonEvent] internal void CacheHit() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _cacheHit.Increment(); } - - _cacheHit?.Increment(); } /// @@ -124,43 +119,29 @@ internal void CacheHit() [NonEvent] internal void CacheMiss() { - if (!IsEnabled()) + if (IsEnabled()) { - return; + _cacheMiss.Increment(); } - - _cacheMiss?.Increment(); } - /// - /// Updates the size used by the polling counter. - /// - /// Current number of entries in the cache. - /// - /// The size is updated even when telemetry is disabled so that the polling - /// counter reports a correct value once a listener attaches. - /// - [NonEvent] - internal static void CacheSizeSet(int size) => HttpUserAgentParserTelemetryState.SetConcurrentCacheSize(size); - /// /// Releases all EventCounter and PollingCounter resources used by this EventSource. /// /// - /// when called from ; + /// when called from ; /// when called from a finalizer. /// + /// + /// Follows the pattern of the EventCounters documentation: the counters are released in both cases. + /// protected override void Dispose(bool disposing) { - if (disposing) - { - _parseRequests?.Dispose(); - _parseDurationSeconds?.Dispose(); - - _cacheHit?.Dispose(); - _cacheMiss?.Dispose(); - _cacheSize?.Dispose(); - } + _parseRequests.Dispose(); + _parseDurationSeconds.Dispose(); + _cacheHit.Dispose(); + _cacheMiss.Dispose(); + _cacheSize.Dispose(); base.Dispose(disposing); } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index cb06c26..389acc9 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; @@ -14,7 +13,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// Instruments are created once on first enablement and emit no data unless observed /// by an active listener. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserMeters { /// @@ -68,6 +66,11 @@ public static string GetMeterName(string? meterPrefix) /// public static void Enable(Meter? meter = null) { + if (Interlocked.Exchange(ref s_initialized, 1) == 1) + { + return; + } + s_meter = meter ?? new Meter(MeterName); s_parseRequests = s_meter.CreateCounter( diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs index defb596..1b00aac 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.Runtime.CompilerServices; @@ -10,7 +9,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// Opt-in switch for core telemetry. /// Telemetry is disabled by default to ensure zero overhead unless explicitly enabled. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserTelemetry { // Bit flags to track which telemetry systems are enabled. diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs index 7bd68b9..31189f3 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs @@ -1,7 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics.CodeAnalysis; - namespace MyCSharp.HttpUserAgentParser.Telemetry; /// @@ -12,7 +10,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// so that polling-based instruments can report correct values once a listener /// attaches. /// -[ExcludeFromCodeCoverage] internal static class HttpUserAgentParserTelemetryState { private static long s_concurrentCacheSize; diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index 1d3c653..34631df 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -2,6 +2,10 @@ Fast HTTP User-Agent parsing for .NET. +- Allocation-free detection with vectorized `SearchValues`, no regular expressions in the parser +- Trimming and Native AOT compatible +- Detects the most used browsers and current search engine, SEO and AI crawlers + Repository: https://github.com/mycsharp/HttpUserAgentParser @@ -19,6 +23,17 @@ HttpUserAgentInformation info = HttpUserAgentParser.Parse(userAgent); // or: HttpUserAgentInformation.Parse(userAgent) ``` +## Regular expressions + +The parser itself does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` +and `HttpUserAgentPlatformInformation.Regex` provide source-generated regular expressions (`[GeneratedRegex]`) for your own +matching; they are created on first access. + +## Native AOT + +The package is trimming and Native AOT compatible. EventCounters (`WithTelemetry()`) need +`true` in Native AOT apps; native meters work without it. + ## Dependency injection If you want to inject a parser (e.g., in ASP.NET Core), use `IHttpUserAgentParserProvider`. @@ -57,11 +72,11 @@ services EventSource: `MyCSharp.HttpUserAgentParser` (constant: `HttpUserAgentParserEventSource.EventSourceName`) -- `parse.requests` (incrementing) -- `parse.duration` (ms, event counter) -- `cache.hit` (incrementing) -- `cache.miss` (incrementing) -- `cache.size` (polling) +- `parse-requests` (incrementing) +- `parse-duration` (s, event counter) +- `cache-hit` (incrementing, `HttpUserAgentParserCachedProvider`) +- `cache-miss` (incrementing, `HttpUserAgentParserCachedProvider`) +- `cache-size` (polling, `HttpUserAgentParserCachedProvider`) ### Monitor with dotnet-counters @@ -88,10 +103,10 @@ services ### Meter + instruments -Meter: `MyCSharp.HttpUserAgentParser` (constant: `HttpUserAgentParserMeters.MeterName`) +Meter: `mycsharp.http_user_agent_parser` (the prefix `mycsharp.` can be changed with `WithMeterTelemetryPrefix(...)`) - `parse.requests` (counter) -- `parse.duration` (histogram, ms) +- `parse.duration` (histogram, s) - `cache.hit` (counter) - `cache.miss` (counter) - `cache.size` (observable gauge) @@ -132,13 +147,12 @@ If you enabled **native meters** (see above), collect them via `AddMeter(...)`: ```csharp using OpenTelemetry.Metrics; -using MyCSharp.HttpUserAgentParser.Telemetry; builder.Services.AddOpenTelemetry() .WithMetrics(metrics => { metrics - .AddMeter(HttpUserAgentParserMeters.MeterName) + .AddMeter("mycsharp.http_user_agent_parser") .AddOtlpExporter(); }); ``` diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs index 28e46dd..1bbdb1b 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs @@ -9,8 +9,13 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; -public class HttpUserAgentParserAspNetCoreMetersTelemetryTests +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserAspNetCoreMetersTelemetryTests : IDisposable { + public HttpUserAgentParserAspNetCoreMetersTelemetryTests() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + [Fact] public void Meters_Emit_WhenEnabled() { diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs new file mode 100644 index 0000000..e7fe3a0 --- /dev/null +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs @@ -0,0 +1,67 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Diagnostics.Metrics; +using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; + +/// +/// Covers the telemetry building blocks of the AspNetCore package directly. +/// +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserAspNetCoreTelemetryInternalsTests : IDisposable +{ + public HttpUserAgentParserAspNetCoreTelemetryInternalsTests() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + + [Fact] + public void Meters_Ignore_Measurements_Before_Enable() + { + using MeterTestListener listener = new(HttpUserAgentParserAspNetCoreMeters.MeterName); + + HttpUserAgentParserAspNetCoreMeters.UserAgentPresent(); + HttpUserAgentParserAspNetCoreMeters.UserAgentMissing(); + + Assert.Empty(listener.InstrumentNames); + } + + [Fact] + public void Meters_Are_Enabled_Only_Once() + { + using Meter first = new("test.aspnetcore.first"); + using Meter second = new("test.aspnetcore.second"); + using MeterTestListener listener = new("test.aspnetcore.first"); + + HttpUserAgentParserAspNetCoreMeters.Enable(first); + HttpUserAgentParserAspNetCoreMeters.Enable(second); + HttpUserAgentParserAspNetCoreMeters.UserAgentPresent(); + HttpUserAgentParserAspNetCoreMeters.UserAgentMissing(); + + Assert.Equal(new[] { "user_agent.missing", "user_agent.present" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); + } + + [Fact] + public void EventSource_Ignores_Calls_Without_Listener() + { + HttpUserAgentParserAspNetCoreEventSource source = HttpUserAgentParserAspNetCoreEventSource.Log; + Assert.False(source.IsEnabled()); + + source.UserAgentPresent(); + source.UserAgentMissing(); + + Assert.False(source.IsEnabled()); + } + + [Fact] + public void EventSource_Can_Be_Disposed() + { + HttpUserAgentParserAspNetCoreEventSource source = new(); + Assert.Equal(HttpUserAgentParserAspNetCoreEventSource.EventSourceName, source.Name); + + source.Dispose(); + + Assert.False(source.IsEnabled()); + } +} diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryPathTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryPathTests.cs new file mode 100644 index 0000000..253190b --- /dev/null +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryPathTests.cs @@ -0,0 +1,51 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; +using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; +using MyCSharp.HttpUserAgentParser.DependencyInjection; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; + +/// +/// Covers header present / missing with telemetry disabled and enabled explicitly. +/// +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserAspNetCoreTelemetryPathTests : IDisposable +{ + public HttpUserAgentParserAspNetCoreTelemetryPathTests() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + + [Fact] + public void Disabled_Telemetry_Reads_Header() + { + Assert.False(HttpUserAgentParserAspNetCoreTelemetry.IsEnabled); + + AssertReadsHeader(); + } + + [Fact] + public void Enabled_Telemetry_Reads_Header() + { + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithAspNetCoreMeterTelemetry(); + + Assert.True(HttpUserAgentParserAspNetCoreTelemetry.IsEnabled); + + AssertReadsHeader(); + } + + private static void AssertReadsHeader() + { + DefaultHttpContext context = new(); + Assert.Null(context.GetUserAgentString()); + + context.Request.Headers.UserAgent = "UA"; + Assert.Equal("UA", context.GetUserAgentString()); + + context.Request.Headers.UserAgent = string.Empty; + Assert.Equal(string.Empty, context.GetUserAgentString()); + } +} diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs index bb6d3a0..646840c 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs @@ -9,8 +9,13 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; -public class HttpUserAgentParserAspNetCoreTelemetryTests +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserAspNetCoreTelemetryTests : IDisposable { + public HttpUserAgentParserAspNetCoreTelemetryTests() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); + [Fact] public void EventCounters_DoNotThrow_WhenEnabled() { diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/TelemetryCollection.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/TelemetryCollection.cs new file mode 100644 index 0000000..bd0388c --- /dev/null +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/TelemetryCollection.cs @@ -0,0 +1,15 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; + +/// +/// Telemetry switches are process-wide static state. Tests that change or depend on it run in this collection, +/// which is not parallelized and runs after all parallel tests, so no other test observes a foreign telemetry state. +/// +[CollectionDefinition(Name, DisableParallelization = true)] +public sealed class TelemetryCollection +{ + public const string Name = "Telemetry"; +} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs index 01e13fe..8183e95 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs @@ -25,4 +25,20 @@ public void AddHttpUserAgentMemoryCachedParser() Assert.Equal(typeof(HttpUserAgentParserMemoryCachedProvider), services[1].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[1].Lifetime); } + + [Fact] + public void AddHttpUserAgentMemoryCachedParser_Applies_Options() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentMemoryCachedParser(options => + { + options.CacheOptions.SizeLimit = 1024; + options.CacheEntryOptions.SlidingExpiration = TimeSpan.FromMinutes(60); + }); + + HttpUserAgentParserMemoryCachedProviderOptions options = Assert.IsType(services[0].ImplementationInstance); + Assert.Equal(1024, options.CacheOptions.SizeLimit); + Assert.Equal(TimeSpan.FromMinutes(60), options.CacheEntryOptions.SlidingExpiration); + } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs new file mode 100644 index 0000000..899b4fc --- /dev/null +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs @@ -0,0 +1,36 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; + +public class HttpUserAgentParserMemoryCachedProviderCacheKeyTests +{ + private static HttpUserAgentParserMemoryCachedProvider.CacheKey Key(string userAgent) + => new() { UserAgent = userAgent, Options = new HttpUserAgentParserMemoryCachedProviderOptions() }; + + [Fact] + public void Equals_Ignores_Case() + { + Assert.True(Key("Mozilla/5.0 Chrome").Equals(Key("mozilla/5.0 chrome"))); + Assert.True(Key("Mozilla/5.0 Chrome").Equals((object)Key("Mozilla/5.0 Chrome"))); + } + + [Fact] + public void Not_Equals_Other_User_Agent_Null_Or_Other_Type() + { + HttpUserAgentParserMemoryCachedProvider.CacheKey key = Key("Mozilla/5.0 Chrome"); + + Assert.False(key.Equals(Key("Mozilla/5.0 Firefox"))); + Assert.False(key.Equals(null)); + Assert.False(key.Equals((object?)null)); + Assert.False(key.Equals("Mozilla/5.0 Chrome")); + } + + [Fact] + public void GetHashCode_Is_Ordinal() + { + Assert.Equal(Key("Mozilla/5.0 Chrome").GetHashCode(), Key("Mozilla/5.0 Chrome").GetHashCode()); + Assert.Equal("Mozilla/5.0 Chrome".GetHashCode(StringComparison.Ordinal), Key("Mozilla/5.0 Chrome").GetHashCode()); + } +} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index 38296cd..7dde5ce 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -8,8 +8,13 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; -public class HttpUserAgentParserMemoryCacheMetersTelemetryTests +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserMemoryCacheMetersTelemetryTests : IDisposable { + public HttpUserAgentParserMemoryCacheMetersTelemetryTests() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + [Fact] public void Meters_Emit_WhenEnabled() { diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs new file mode 100644 index 0000000..d63a9ac --- /dev/null +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs @@ -0,0 +1,82 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Diagnostics.Metrics; +using Microsoft.Extensions.Caching.Memory; +using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; + +/// +/// Covers the telemetry building blocks of the MemoryCache package directly. +/// +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserMemoryCacheTelemetryInternalsTests : IDisposable +{ + public HttpUserAgentParserMemoryCacheTelemetryInternalsTests() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + + [Fact] + public void Meters_Ignore_Measurements_Before_Enable() + { + HttpUserAgentParserMemoryCacheMeters.CacheHit(); + HttpUserAgentParserMemoryCacheMeters.CacheMiss(); + + Assert.False(HttpUserAgentParserMemoryCacheMeters.IsEnabled); + } + + [Fact] + public void Meters_Are_Enabled_Only_Once() + { + using Meter first = new("test.memorycache.first"); + using Meter second = new("test.memorycache.second"); + using MeterTestListener listener = new("test.memorycache.first"); + + HttpUserAgentParserMemoryCacheMeters.Enable(first); + HttpUserAgentParserMemoryCacheMeters.Enable(second); + HttpUserAgentParserMemoryCacheMeters.CacheHit(); + HttpUserAgentParserMemoryCacheMeters.CacheMiss(); + + Assert.True(HttpUserAgentParserMemoryCacheMeters.IsEnabled); + Assert.Equal(new[] { "cache.hit", "cache.miss" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); + } + + [Fact] + public void EventSource_Ignores_Calls_Without_Listener() + { + HttpUserAgentParserMemoryCacheEventSource source = HttpUserAgentParserMemoryCacheEventSource.Log; + Assert.False(source.IsEnabled()); + + source.CacheHit(); + source.CacheMiss(); + + Assert.False(source.IsEnabled()); + } + + [Fact] + public void EventSource_Can_Be_Disposed() + { + HttpUserAgentParserMemoryCacheEventSource source = new(); + Assert.Equal(HttpUserAgentParserMemoryCacheEventSource.EventSourceName, source.Name); + + source.Dispose(); + + Assert.False(source.IsEnabled()); + } + + [Fact] + public void Evicted_Entries_Decrement_The_Cache_Size() + { + using Meter meter = new("test.memorycache.eviction"); + HttpUserAgentParserMemoryCacheTelemetry.EnableMeters(meter); + + // A size limit of one entry: the second user agent exceeds the capacity and gets evicted. + HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions(new MemoryCacheOptions { SizeLimit = 1 })); + _ = provider.Parse("Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/158.0.0.0"); + _ = provider.Parse("Mozilla/5.0 (X11; Linux x86_64; rv:160.0) Gecko/20100101 Firefox/160.0"); + + // Eviction callbacks run asynchronously. + Assert.True(SpinWait.SpinUntil(static () => HttpUserAgentParserMemoryCacheTelemetryState.CacheSize < 2, TimeSpan.FromSeconds(10))); + } +} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs new file mode 100644 index 0000000..8bf1140 --- /dev/null +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs @@ -0,0 +1,65 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Microsoft.Extensions.DependencyInjection; +using MyCSharp.HttpUserAgentParser.DependencyInjection; +using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; +using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; + +/// +/// Covers every telemetry state of the memory cached provider explicitly. +/// +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserMemoryCacheTelemetryPathTests : IDisposable +{ + private const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"; + + public HttpUserAgentParserMemoryCacheTelemetryPathTests() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + + [Fact] + public void Disabled_Telemetry_Parses_And_Caches() + { + Assert.False(HttpUserAgentParserMemoryCacheTelemetry.IsEnabled); + + AssertParsesAndCaches(); + Assert.Equal(0, HttpUserAgentParserMemoryCacheTelemetryState.CacheSize); + } + + [Fact] + public void Counters_Without_Listener_Do_Not_Track_Cache_Size() + { + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMemoryCacheTelemetry(); + + Assert.True(HttpUserAgentParserMemoryCacheTelemetry.IsEnabled); + Assert.False(HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled); + + AssertParsesAndCaches(); + Assert.Equal(0, HttpUserAgentParserMemoryCacheTelemetryState.CacheSize); + } + + [Fact] + public void Meters_Track_Cache_Size() + { + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMemoryCacheMeterTelemetry(); + + Assert.True(HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled); + + AssertParsesAndCaches(); + Assert.Equal(1, HttpUserAgentParserMemoryCacheTelemetryState.CacheSize); + } + + private static void AssertParsesAndCaches() + { + HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + + HttpUserAgentInformation miss = provider.Parse(UserAgent); + HttpUserAgentInformation hit = provider.Parse(UserAgent); + + Assert.Equal("Chrome", miss.Name); + Assert.Equal(miss, hit); + } +} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs index 1b8950b..3b93e3f 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs @@ -8,8 +8,13 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; -public class HttpUserAgentParserMemoryCacheTelemetryTests +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserMemoryCacheTelemetryTests : IDisposable { + public HttpUserAgentParserMemoryCacheTelemetryTests() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + [Fact] public void EventCounters_DoNotThrow_WhenEnabled() { diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/TelemetryCollection.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/TelemetryCollection.cs new file mode 100644 index 0000000..afb8b6f --- /dev/null +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/TelemetryCollection.cs @@ -0,0 +1,15 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; + +/// +/// Telemetry switches are process-wide static state. Tests that change or depend on it run in this collection, +/// which is not parallelized and runs after all parallel tests, so no other test observes a foreign telemetry state. +/// +[CollectionDefinition(Name, DisableParallelization = true)] +public sealed class TelemetryCollection +{ + public const string Name = "Telemetry"; +} diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj b/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj new file mode 100644 index 0000000..f638a39 --- /dev/null +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj @@ -0,0 +1,35 @@ + + + + + + Exe + false + true + true + false + false + + + + + + + + + + + + + + + + + + + diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs new file mode 100644 index 0000000..0b9462e --- /dev/null +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs @@ -0,0 +1,77 @@ +// Copyright © https://myCSharp.de - all rights reserved + +// Native AOT smoke test: exercises the public API of all packages in a trimmed, natively compiled app. +// Exit code 0 means success; every failed check is printed and makes the exit code non-zero. + +using System.Diagnostics.Metrics; +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using MyCSharp.HttpUserAgentParser; +using MyCSharp.HttpUserAgentParser.AspNetCore; +using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; +using MyCSharp.HttpUserAgentParser.DependencyInjection; +using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; +using MyCSharp.HttpUserAgentParser.Providers; + +const string Chrome = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"; +const string Safari = "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Mobile/15E148 Safari/604.1"; +const string ClaudeBot = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"; + +int failures = 0; + +void Check(bool condition, string description) +{ + Console.WriteLine($"{(condition ? "PASS" : "FAIL")} {description}"); + if (!condition) + { + failures++; + } +} + +// Parser +HttpUserAgentInformation chrome = HttpUserAgentParser.Parse(Chrome); +Check(chrome is { Type: HttpUserAgentType.Browser, Name: "Chrome", Version: "158.0.0.0" }, "parse Chrome"); +Check(chrome.Platform is { Name: "Windows 10", PlatformType: HttpUserAgentPlatformType.Windows }, "parse Windows platform"); + +HttpUserAgentInformation safari = HttpUserAgentParser.Parse(Safari); +Check(safari is { Name: "Safari", Version: "27.2", MobileDeviceType: "Apple iPhone" }, "parse Safari on iPhone"); + +HttpUserAgentInformation robot = HttpUserAgentParser.Parse(ClaudeBot); +Check(robot is { Type: HttpUserAgentType.Robot, Name: "ClaudeBot" }, "parse ClaudeBot"); +Check(chrome.Equals(HttpUserAgentParser.Parse(Chrome)), "struct equality"); + +// Source-generated regular expressions +Regex? windows10 = chrome.Platform?.Regex; +Check(windows10 is not null && windows10.IsMatch(Chrome), "platform regex"); +Check(HttpUserAgentStatics.Platforms.Count == 43 && HttpUserAgentStatics.Platforms.All(static p => p.Regex is not null), "platform regexes"); +Regex chromeRegex = HttpUserAgentStatics.Browsers.First(static b => b.Key.ToString().StartsWith("Chrome", StringComparison.Ordinal)).Key; +Check(string.Equals(chromeRegex.Match(Chrome).Groups[1].Value, "158.0.0.0", StringComparison.Ordinal), "browser regex version group"); + +// Dependency injection, caching providers and ASP.NET Core accessor +using Meter meter = new("smoke.http_user_agent_parser"); +ServiceCollection services = new(); +services.AddHttpUserAgentMemoryCachedParser(static options => options.CacheOptions.SizeLimit = 16) + .AddHttpUserAgentParserAccessor() + .WithMeterTelemetry(meter) + .WithTelemetry(); + +using (ServiceProvider provider = services.BuildServiceProvider()) +{ + IHttpUserAgentParserProvider parser = provider.GetRequiredService(); + Check(parser.Parse(Chrome) is { Name: "Chrome" } && parser.Parse(Chrome) is { Name: "Chrome" }, "memory cached provider"); + + DefaultHttpContext context = new(); + context.Request.Headers.UserAgent = Safari; + Check(provider.GetRequiredService().Get(context) is { Name: "Safari" }, "ASP.NET Core accessor"); +} + +ServiceCollection genericServices = new(); +genericServices.AddHttpUserAgentParser(); +using (ServiceProvider provider = genericServices.BuildServiceProvider()) +{ + Check(provider.GetRequiredService() is HttpUserAgentParserCachedProvider, "generic provider registration"); +} + +Console.WriteLine(failures == 0 ? "Native AOT smoke test passed." : $"Native AOT smoke test failed: {failures} check(s)."); +return failures == 0 ? 0 : 1; diff --git a/tests/HttpUserAgentParser.TestHelpers/HttpUserAgentParser.TestHelpers.csproj b/tests/HttpUserAgentParser.TestHelpers/HttpUserAgentParser.TestHelpers.csproj index 42cceb3..f07f86d 100644 --- a/tests/HttpUserAgentParser.TestHelpers/HttpUserAgentParser.TestHelpers.csproj +++ b/tests/HttpUserAgentParser.TestHelpers/HttpUserAgentParser.TestHelpers.csproj @@ -4,4 +4,8 @@ false + + + + diff --git a/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs b/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs new file mode 100644 index 0000000..d72a1e5 --- /dev/null +++ b/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs @@ -0,0 +1,221 @@ +// Copyright © https://myCSharp.de - all rights reserved + +namespace MyCSharp.HttpUserAgentParser.TestHelpers; + +/// +/// A real-world browser user agent and the expected parse result. +/// +/// Short description, used as test and benchmark display name. +/// The user agent string. +/// Expected browser name. +/// Expected browser version. +/// Expected platform name. +/// Expected platform type. +/// Expected mobile device type, for desktop user agents. +public sealed record BrowserUserAgent( + string Label, + string UserAgent, + string Name, + string Version, + string PlatformName, + HttpUserAgentPlatformType PlatformType, + string? MobileDeviceType) +{ + /// + public override string ToString() => Label; +} + +/// +/// A real-world crawler user agent and the expected robot name. +/// +/// Crawler category, see . +/// Short description, used as test and benchmark display name. +/// The user agent string. +/// Expected robot name. +public sealed record RobotUserAgent(string Category, string Label, string UserAgent, string Name) +{ + /// + public override string ToString() => Label; +} + +/// +/// Real-world user agents of the most used browsers (current and previous major version, as of November 2026) +/// and of search engine, SEO and AI crawlers. +/// +/// +/// Sources: vendor documentation and release notes (Chrome, Edge, Firefox, Safari, Opera, Samsung, crawler operators), +/// useragents.me traffic data and the ua-parser-js test fixtures. Strings were either copied verbatim or built from the +/// documented user agent format with a verified version number. Notes: +/// +/// Chrome, Edge and Opera use the reduced user agent (Windows NT 10.0 also for Windows 11, Android 10; K, Chrome/x.0.0.0). +/// Since iOS 26, Safari freezes the OS version at 18_7 and macOS at 10_15_7; only Version/ carries the Safari version. +/// iPadOS sends the macOS user agent by default, Brave and Vivaldi send the Chrome user agent. +/// W.X.Y.Z is the placeholder Google and Microsoft use in their crawler documentation. +/// +/// +public static class UserAgentCatalog +{ + /// Category of search engine crawlers. + public const string SearchCrawler = "Search"; + + /// Category of SEO crawlers. + public const string SeoCrawler = "SEO"; + + /// Category of AI crawlers and AI user agents. + public const string AiCrawler = "AI"; + + private const HttpUserAgentPlatformType Windows = HttpUserAgentPlatformType.Windows; + private const HttpUserAgentPlatformType MacOS = HttpUserAgentPlatformType.MacOS; + private const HttpUserAgentPlatformType Linux = HttpUserAgentPlatformType.Linux; + private const HttpUserAgentPlatformType Android = HttpUserAgentPlatformType.Android; + private const HttpUserAgentPlatformType IOS = HttpUserAgentPlatformType.IOS; + + /// + /// Browser user agents: current and previous major version of the most used browsers. + /// + public static IReadOnlyList Browsers { get; } = + [ + // Chrome 158 (current) and 157 (previous) + new("Chrome 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Windows 10", Windows, null), + new("Chrome 157 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Windows 10", Windows, null), + new("Chrome 158 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Mac OS X", MacOS, null), + new("Chrome 157 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Mac OS X", MacOS, null), + new("Chrome 158 Linux", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Linux", Linux, null), + new("Chrome 157 Linux", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Linux", Linux, null), + new("Chrome 158 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Mobile Safari/537.36", "Chrome", "158.0.0.0", "Android", Android, "Android"), + new("Chrome 157 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36", "Chrome", "157.0.0.0", "Android", Android, "Android"), + new("Chrome 158 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/158.0.8127.35 Mobile/15E148 Safari/604.1", "Chrome", "158.0.8127.35", "iOS", IOS, "Apple iPhone"), + new("Chrome 157 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 27_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/157.0.8103.37 Mobile/15E148 Safari/604.1", "Chrome", "157.0.8103.37", "iOS", IOS, "Apple iPhone"), + + // Safari 27.2 (current) and 26.6 (previous) + new("Safari 27 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Safari/605.1.15", "Safari", "27.2", "Mac OS X", MacOS, null), + new("Safari 26 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Safari/605.1.15", "Safari", "26.6", "Mac OS X", MacOS, null), + new("Safari 27 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Mobile/15E148 Safari/604.1", "Safari", "27.2", "iOS", IOS, "Apple iPhone"), + new("Safari 26 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Mobile/15E148 Safari/604.1", "Safari", "26.6", "iOS", IOS, "Apple iPhone"), + new("Safari 27 iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Mobile/15E148 Safari/604.1", "Safari", "27.2", "iOS", IOS, "Apple iPad"), + new("Safari 26 iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Mobile/15E148 Safari/604.1", "Safari", "26.6", "iOS", IOS, "Apple iPad"), + + // Edge 158 (current desktop), 156 (previous desktop, 157 was skipped), 157 / 156 (mobile) + new("Edge 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 Edg/158.0.0.0", "Edge", "158.0.0.0", "Windows 10", Windows, null), + new("Edge 156 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36 Edg/156.0.0.0", "Edge", "156.0.0.0", "Windows 10", Windows, null), + new("Edge 158 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 Edg/158.0.0.0", "Edge", "158.0.0.0", "Mac OS X", MacOS, null), + new("Edge 156 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36 Edg/156.0.0.0", "Edge", "156.0.0.0", "Mac OS X", MacOS, null), + new("Edge 157 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36 EdgA/157.0.0.0", "Edge", "157.0.0.0", "Android", Android, "Android"), + new("Edge 156 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Mobile Safari/537.36 EdgA/156.0.0.0", "Edge", "156.0.0.0", "Android", Android, "Android"), + new("Edge 157 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 27_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/157.0.4341.57 Version/27.0 Mobile/15E148 Safari/604.1", "Edge", "157.0.4341.57", "iOS", IOS, "Apple iPhone"), + new("Edge 156 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 27_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/156.0.4314.56 Version/27.0 Mobile/15E148 Safari/604.1", "Edge", "156.0.4314.56", "iOS", IOS, "Apple iPhone"), + + // Firefox 160 (current) and 159 (previous) + new("Firefox 160 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Windows 10", Windows, null), + new("Firefox 159 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Windows 10", Windows, null), + new("Firefox 160 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Mac OS X", MacOS, null), + new("Firefox 159 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Mac OS X", MacOS, null), + new("Firefox 160 Linux", "Mozilla/5.0 (X11; Linux x86_64; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Linux", Linux, null), + new("Firefox 159 Linux", "Mozilla/5.0 (X11; Linux x86_64; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Linux", Linux, null), + new("Firefox 160 Android", "Mozilla/5.0 (Android 17; Mobile; rv:160.0) Gecko/160.0 Firefox/160.0", "Firefox", "160.0", "Android", Android, "Android"), + new("Firefox 159 Android", "Mozilla/5.0 (Android 17; Mobile; rv:159.0) Gecko/159.0 Firefox/159.0", "Firefox", "159.0", "Android", Android, "Android"), + new("Firefox 160 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/160.0 Mobile/15E148 Safari/604.1", "Firefox", "160.0", "iOS", IOS, "Apple iPhone"), + new("Firefox 159 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/159.0 Mobile/15E148 Safari/604.1", "Firefox", "159.0", "iOS", IOS, "Apple iPhone"), + + // Opera 140 / 139 (desktop, Opera GX sends the same user agent) and Opera for Android 101 + new("Opera 140 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/140.0.0.0", "Opera", "140.0.0.0", "Windows 10", Windows, null), + new("Opera 139 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36 OPR/139.0.0.0", "Opera", "139.0.0.0", "Windows 10", Windows, null), + new("Opera 101 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Mobile Safari/537.36 OPR/101.0.0.0", "Opera", "101.0.0.0", "Android", Android, "Android"), + + // Samsung Internet 30 (phone and tablet / DeX) + new("Samsung Internet 30 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/30.0 Chrome/143.0.0.0 Mobile Safari/537.36", "Samsung Internet", "30.0", "Android", Android, "Samsung"), + new("Samsung Internet 30 DeX", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/30.0 Chrome/143.0.0.0 Safari/537.36", "Samsung Internet", "30.0", "Linux", Linux, "Samsung"), + + // Yandex Browser 26.11 + new("Yandex Browser 26 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 YaBrowser/26.11.0.2030 Yowser/2.5 Safari/537.36", "Yandex Browser", "26.11.0.2030", "Windows 10", Windows, null), + + // UC Browser 15 (UCMobile token) and the classic UCBrowser token + new("UC Browser 15 Android", "Mozilla/5.0 (Linux; Android 16; en-US; SM-S918B Build/BP2A.250605.031.A3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.80 UCMobile/15.0.7.1383 Mobile Safari/537.36", "UC Browser", "15.0.7.1383", "Android", Android, "Android"), + new("UC Browser 11 Android", "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-CN; F5121 Build/34.0.A.1.247) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.5.1.944 Mobile Safari/537.36", "UC Browser", "11.5.1.944", "Android", Android, "Android"), + + // DuckDuckGo browser (WebKit on iOS, WebView on Android) + new("DuckDuckGo iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 DuckDuckGo/7 Safari/605.1.15", "Safari", "26.0", "iOS", IOS, "Apple iPhone"), + new("DuckDuckGo Android", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/151.0.7922.199 Mobile DuckDuckGo/5 Safari/537.36", "Chrome", "151.0.7922.199", "Android", Android, "Android"), + ]; + + /// + /// Crawler user agents of search engines, SEO tools and AI services. + /// + public static IReadOnlyList Robots { get; } = + [ + // Search engines + new(SearchCrawler, "Googlebot Smartphone", "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot"), + new(SearchCrawler, "Googlebot Desktop", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36", "Googlebot"), + new(SearchCrawler, "Google-InspectionTool", "Mozilla/5.0 (compatible; Google-InspectionTool/1.0)", "Google-InspectionTool"), + new(SearchCrawler, "GoogleOther", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GoogleOther) Chrome/W.X.Y.Z Safari/537.36", "GoogleOther"), + new(SearchCrawler, "Google-CloudVertexBot", "Google-CloudVertexBot", "Google-CloudVertexBot"), + new(SearchCrawler, "Bingbot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/W.X.Y.Z Safari/537.36", "BingBot"), + new(SearchCrawler, "DuckDuckBot", "DuckDuckBot/1.1; (+http://duckduckgo.com/duckduckbot.html)", "DuckDuckBot"), + new(SearchCrawler, "YandexBot", "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", "YandexBot"), + new(SearchCrawler, "Baiduspider", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)", "Baiduspider"), + new(SearchCrawler, "Applebot", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15 (Applebot/0.1; +http://www.apple.com/go/applebot)", "Applebot"), + new(SearchCrawler, "SeznamBot", "Mozilla/5.0 (compatible; SeznamBot/4.0; +https://o-seznam.cz/napoveda/vyhledavani/en/seznambot-crawler/)", "SeznamBot"), + new(SearchCrawler, "Sogou web spider", "Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)", "Sogou"), + new(SearchCrawler, "Naver Yeti", "Mozilla/5.0 (compatible; Yeti/1.1; +https://naver.me/spd)", "Naver Yeti"), + new(SearchCrawler, "PetalBot", "Mozilla/5.0 (compatible;PetalBot;+https://webmaster.petalsearch.com/site/petalbot)", "PetalBot"), + new(SearchCrawler, "Qwantbot", "Mozilla/5.0 (compatible; Qwantbot/1.0_12345; +https://help.qwant.com/bot/)", "Qwantbot"), + new(SearchCrawler, "MojeekBot", "Mozilla/5.0 (compatible; MojeekBot/0.11; +https://www.mojeek.com/bot.html)", "MojeekBot"), + + // SEO tools + new(SeoCrawler, "AhrefsBot", "Mozilla/5.0 (compatible; AhrefsBot/7.0; +http://ahrefs.com/robot/)", "Ahrefs"), + new(SeoCrawler, "AhrefsSiteAudit", "Mozilla/5.0 (compatible; AhrefsSiteAudit/6.1; +http://ahrefs.com/robot/site-audit)", "Ahrefs Site Audit"), + new(SeoCrawler, "SemrushBot", "Mozilla/5.0 (compatible; SemrushBot/7~bl; +http://www.semrush.com/bot.html)", "SEMRush"), + new(SeoCrawler, "SiteAuditBot", "Mozilla/5.0 (compatible; SiteAuditBot/0.97; +http://www.semrush.com/bot.html)", "SiteAuditBot"), + new(SeoCrawler, "MJ12bot", "Mozilla/5.0 (compatible; MJ12bot/v1.4.8; http://mj12bot.com/)", "Majestic"), + new(SeoCrawler, "DotBot", "Mozilla/5.0 (compatible; DotBot/1.2; +https://opensiteexplorer.org/dotbot; help@moz.com)", "DotBot"), + new(SeoCrawler, "rogerbot", "rogerbot/1.2", "rogerbot"), + new(SeoCrawler, "Screaming Frog", "Screaming Frog SEO Spider/25.1", "Screaming Frog SEO Spider"), + new(SeoCrawler, "DataForSeoBot", "Mozilla/5.0 (compatible; DataForSeoBot/1.0; +https://dataforseo.com/dataforseo-bot)", "DataForSeoBot"), + new(SeoCrawler, "serpstatbot", "serpstatbot/2.1 (advanced backlink tracking bot; https://serpstatbot.com/; abuse@serpstatbot.com)", "serpstatbot"), + new(SeoCrawler, "BLEXBot", "Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)", "BLEXBot"), + new(SeoCrawler, "Barkrowler", "Mozilla/5.0 (compatible; Barkrowler/0.9; +https://babbar.tech/crawler)", "Barkrowler"), + new(SeoCrawler, "SISTRIX", "Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)", "Sistrix"), + + // AI crawlers and AI user agents + new(AiCrawler, "GPTBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; GPTBot/1.4; +https://openai.com/gptbot", "GPTBot"), + new(AiCrawler, "ChatGPT-User", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot", "ChatGPT-User"), + new(AiCrawler, "OAI-SearchBot", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36; compatible; OAI-SearchBot/1.4; +https://openai.com/searchbot", "OAI-SearchBot"), + new(AiCrawler, "ClaudeBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)", "ClaudeBot"), + new(AiCrawler, "Claude-User", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Claude-User/1.0; +claude-user@anthropic.com)", "Claude-User"), + new(AiCrawler, "Claude-SearchBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Claude-SearchBot/1.0; +claudebot@anthropic.com)", "Claude-SearchBot"), + new(AiCrawler, "PerplexityBot", "Mozilla/5.0 (compatible; PerplexityBot/1.0; +https://perplexity.ai/perplexitybot)", "PerplexityBot"), + new(AiCrawler, "Perplexity-User", "Mozilla/5.0 (compatible; Perplexity-User/1.0; +https://perplexity.ai/perplexity-user)", "Perplexity-User"), + new(AiCrawler, "Amazonbot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1) Chrome/W.X.Y.Z Safari/537.36", "Amazonbot"), + new(AiCrawler, "meta-externalagent", "meta-externalagent/1.1 (+https://developers.facebook.com/docs/sharing/webmasters/crawler)", "meta-externalagent"), + new(AiCrawler, "meta-externalfetcher", "meta-externalfetcher/1.1 (+https://developers.facebook.com/docs/sharing/webmasters/crawler)", "meta-externalfetcher"), + new(AiCrawler, "Bytespider", "Mozilla/5.0 (Linux; Android 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; Bytespider; spider-feedback@bytedance.com)", "Bytespider"), + new(AiCrawler, "CCBot", "CCBot/2.0 (https://commoncrawl.org/faq/)", "CCBot"), + new(AiCrawler, "cohere-ai", "Mozilla/5.0 (compatible; cohere-ai; +https://cohere.com/crawler)", "cohere-ai"), + new(AiCrawler, "Diffbot", "Mozilla/5.0 (compatible; Diffbot/1.0; +https://diffbot.com)", "Diffbot"), + new(AiCrawler, "MistralAI-User", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; MistralAI-User/1.0; +https://docs.mistral.ai/robots)", "MistralAI-User"), + new(AiCrawler, "DuckAssistBot", "DuckAssistBot/1.2; (+http://duckduckgo.com/duckassistbot.html)", "DuckAssistBot"), + new(AiCrawler, "AI2Bot", "Mozilla/5.0 (compatible) AI2Bot (+https://www.allenai.org/crawler)", "AI2Bot"), + new(AiCrawler, "YouBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; YouBot/1.0; +https://docs.you.com/youbot; env:prod) Chrome/X.X.X.X Safari/537.36", "YouBot"), + ]; + + /// + /// User agents without a known browser or robot token. + /// + public static IReadOnlyList Unknown { get; } = + [ + "custom-client/1.0 (+https://example.org/client)", + "okhttp/4.12.0", + "python-requests/2.32.3", + "Go-http-client/2.0", + ]; + + /// + /// All user agents of the catalog (browsers, robots, unknown), e.g. for mixed workload benchmarks. + /// + public static IReadOnlyList All { get; } = + [ + .. Browsers.Select(static ua => ua.UserAgent), + .. Robots.Select(static ua => ua.UserAgent), + .. Unknown, + ]; +} diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs index 1200a7f..16437bc 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs @@ -65,6 +65,52 @@ public void CreateForUnknown(string userAgent) Assert.Null(ua.MobileDeviceType); } + [Fact] + public void Equals_Same_Values() + { + const string UserAgent = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Mobile Safari/537.36"; + + HttpUserAgentInformation first = HttpUserAgentParser.Parse(UserAgent); + HttpUserAgentInformation second = HttpUserAgentParser.Parse(new string(UserAgent.AsSpan())); + + Assert.True(first.Equals(second)); + Assert.True(first.Equals((object)second)); + Assert.Equal(first.GetHashCode(), second.GetHashCode()); + } + + public static TheoryData DifferingProperties => [0, 1, 2, 3, 4, 5, 6]; + + [Theory] + [MemberData(nameof(DifferingProperties))] + public void Not_Equals_When_Any_Property_Differs(int property) + { + HttpUserAgentPlatformInformation platform = new(TextRegex(), "Android", HttpUserAgentPlatformType.Android); + HttpUserAgentInformation info = HttpUserAgentInformation.CreateForBrowser("ua", platform, "Chrome", "1.0", "Android"); + + HttpUserAgentInformation other = property switch + { + 0 => HttpUserAgentInformation.CreateForBrowser("other", platform, "Chrome", "1.0", "Android"), + 1 => HttpUserAgentInformation.CreateForUnknown("ua", platform, "Android"), + 2 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Edge", "1.0", "Android"), + 3 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Chrome", "2.0", "Android"), + 4 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Chrome", "1.0", null), + 5 => HttpUserAgentInformation.CreateForBrowser("ua", null, "Chrome", "1.0", "Android"), + _ => HttpUserAgentInformation.CreateForBrowser("ua", new HttpUserAgentPlatformInformation(TextRegex(), "Linux", HttpUserAgentPlatformType.Linux), "Chrome", "1.0", "Android"), + }; + + Assert.False(info.Equals(other)); + Assert.False(info.Equals((object)other)); + } + + [Fact] + public void Not_Equals_Other_Types() + { + HttpUserAgentInformation info = HttpUserAgentInformation.CreateForRobot("ua", "Googlebot"); + + Assert.False(info.Equals((object?)null)); + Assert.False(info.Equals("ua")); + } + [GeneratedRegex("", RegexOptions.None, matchTimeoutMilliseconds: 1000)] private static partial Regex TextRegex(); } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj index 7366e0c..e03e095 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index bdf3fa3..344c34e 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -260,26 +260,6 @@ public void TryGetRobot_True_And_False() Assert.Null(robot); } - [Fact] - public void GetRobot_UsesReplacementRuleInOriginalOrder() - { - int last = HttpUserAgentStatics.Robots.Length - 1; - (string Key, string Value) original = HttpUserAgentStatics.Robots[last]; - - try - { - HttpUserAgentStatics.Robots[last] = ("CustomTestCrawler", "Custom crawler"); - - Assert.Equal("Custom crawler", HttpUserAgentParser.GetRobot("customtestcrawler/1.0")); - Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("customtestcrawler/1.0 googlebot/2.1")); - Assert.Null(HttpUserAgentParser.GetRobot(original.Key)); - } - finally - { - HttpUserAgentStatics.Robots[last] = original; - } - } - [Fact] public void TryGetMobileDevice_True_And_False() { diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs index 0099677..9c497e9 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs @@ -21,6 +21,59 @@ public void Ctor(string name, HttpUserAgentPlatformType platform) Assert.Equal(platform, info.PlatformType); } + [Fact] + public void Default_Has_No_Regex() + { + HttpUserAgentPlatformInformation info = default; + + Assert.Null(info.Regex); + Assert.Null(info.Name); + Assert.Equal(HttpUserAgentPlatformType.Unknown, info.PlatformType); + } + + [Fact] + public void Lazy_Regex_Is_Resolved_On_Access() + { + HttpUserAgentPlatformInformation info = new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android); + + Assert.Same(HttpUserAgentRegexes.GetPlatformRegex(HttpUserAgentPlatformRegexId.Android), info.Regex); + } + + [Fact] + public void Equals_Same_Regex_Name_And_Type() + { + HttpUserAgentPlatformInformation lazy = new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android); + HttpUserAgentPlatformInformation eager = new(lazy.Regex, "Android", HttpUserAgentPlatformType.Android); + + Assert.True(lazy.Equals(eager)); + Assert.True(lazy.Equals((object)eager)); + Assert.Equal(lazy.GetHashCode(), eager.GetHashCode()); + } + + [Fact] + public void Not_Equals_When_Any_Property_Differs() + { + Regex regex = EmptyRegex(); + HttpUserAgentPlatformInformation info = new(regex, "Android", HttpUserAgentPlatformType.Android); + + Assert.False(info.Equals(new HttpUserAgentPlatformInformation(regex, "Android", HttpUserAgentPlatformType.Linux))); + Assert.False(info.Equals(new HttpUserAgentPlatformInformation(regex, "android", HttpUserAgentPlatformType.Android))); + Assert.False(info.Equals(new HttpUserAgentPlatformInformation(OtherRegex(), "Android", HttpUserAgentPlatformType.Android))); + Assert.False(info.Equals((object?)null)); + Assert.False(info.Equals("Android")); + } + + [Fact] + public void Parse_Results_Are_Equal_To_Published_Platforms() + { + HttpUserAgentPlatformInformation platform = Assert.NotNull(HttpUserAgentParser.GetPlatform("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")); + + Assert.Contains(platform, HttpUserAgentStatics.Platforms); + } + [GeneratedRegex("", RegexOptions.None, matchTimeoutMilliseconds: 1000)] private static partial Regex EmptyRegex(); + + [GeneratedRegex("other", RegexOptions.None, matchTimeoutMilliseconds: 1000)] + private static partial Regex OtherRegex(); } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs new file mode 100644 index 0000000..078a426 --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -0,0 +1,73 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +/// +/// is a public, mutable array that the parser reads directly. +/// Replacing an entry changes process-wide state, so these tests run in the non-parallel collection. +/// +[Collection(TelemetryCollection.Name)] +public class HttpUserAgentStaticsRobotsReplacementTests +{ + [Fact] + public void Robots_Are_Unchanged_By_Default() + { +#if NET9_0_OR_GREATER + Assert.True(HttpUserAgentRules.AreRobotsUnchanged()); +#endif + Assert.Equal("YouBot", HttpUserAgentParser.GetRobot(HttpUserAgentStatics.Robots[^1].Key)); + } + + [Fact] + public void GetRobot_UsesReplacementRuleInOriginalOrder() + { + int last = HttpUserAgentStatics.Robots.Length - 1; + (string Key, string Value) original = HttpUserAgentStatics.Robots[last]; + + try + { + HttpUserAgentStatics.Robots[last] = ("CustomTestCrawler", "Custom crawler"); +#if NET9_0_OR_GREATER + Assert.False(HttpUserAgentRules.AreRobotsUnchanged()); +#endif + + Assert.Equal("Custom crawler", HttpUserAgentParser.GetRobot("customtestcrawler/1.0")); + Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("customtestcrawler/1.0 googlebot/2.1")); + Assert.Equal("BingBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); + Assert.Null(HttpUserAgentParser.GetRobot(original.Key)); + Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/158.0.0.0")); + } + finally + { + HttpUserAgentStatics.Robots[last] = original; + } + +#if NET9_0_OR_GREATER + Assert.True(HttpUserAgentRules.AreRobotsUnchanged()); +#endif + } + + [Fact] + public void GetRobot_Honors_Replaced_First_Entry() + { + (string Key, string Value) original = HttpUserAgentStatics.Robots[0]; + + try + { + HttpUserAgentStatics.Robots[0] = ("ExampleBot", "Example"); + + Assert.Equal("Example", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; ExampleBot/1.0)")); + Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")); + Assert.Equal("BingBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); + } + finally + { + HttpUserAgentStatics.Robots[0] = original; + } + + Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")); + } +} diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs new file mode 100644 index 0000000..e28ef8f --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -0,0 +1,201 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Text.RegularExpressions; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +/// +/// Ensures the public collections keep their contents and regex semantics (patterns, options, timeouts, groups) +/// now that the regular expressions are source-generated instead of being compiled at runtime. +/// +public class HttpUserAgentStaticsTests +{ + private static readonly TimeSpan s_matchTimeout = TimeSpan.FromSeconds(1); + + /// + /// The published platform definitions: token (escaped to the regex pattern), name and type, in declaration order. + /// + private static readonly (string Token, string Name, HttpUserAgentPlatformType Type)[] s_expectedPlatforms = + [ + ("windows nt 10.0", "Windows 10", HttpUserAgentPlatformType.Windows), + ("windows nt 6.3", "Windows 8.1", HttpUserAgentPlatformType.Windows), + ("windows nt 6.2", "Windows 8", HttpUserAgentPlatformType.Windows), + ("windows nt 6.1", "Windows 7", HttpUserAgentPlatformType.Windows), + ("windows nt 6.0", "Windows Vista", HttpUserAgentPlatformType.Windows), + ("windows nt 5.2", "Windows 2003", HttpUserAgentPlatformType.Windows), + ("windows nt 5.1", "Windows XP", HttpUserAgentPlatformType.Windows), + ("windows nt 5.0", "Windows 2000", HttpUserAgentPlatformType.Windows), + ("windows nt 4.0", "Windows NT 4.0", HttpUserAgentPlatformType.Windows), + ("winnt4.0", "Windows NT 4.0", HttpUserAgentPlatformType.Windows), + ("winnt 4.0", "Windows NT", HttpUserAgentPlatformType.Windows), + ("winnt", "Windows NT", HttpUserAgentPlatformType.Windows), + ("windows 98", "Windows 98", HttpUserAgentPlatformType.Windows), + ("win98", "Windows 98", HttpUserAgentPlatformType.Windows), + ("windows 95", "Windows 95", HttpUserAgentPlatformType.Windows), + ("win95", "Windows 95", HttpUserAgentPlatformType.Windows), + ("windows phone", "Windows Phone", HttpUserAgentPlatformType.Windows), + ("windows", "Unknown Windows OS", HttpUserAgentPlatformType.Windows), + ("android", "Android", HttpUserAgentPlatformType.Android), + ("blackberry", "BlackBerry", HttpUserAgentPlatformType.BlackBerry), + ("iphone", "iOS", HttpUserAgentPlatformType.IOS), + ("ipad", "iOS", HttpUserAgentPlatformType.IOS), + ("ipod", "iOS", HttpUserAgentPlatformType.IOS), + ("cros", "ChromeOS", HttpUserAgentPlatformType.ChromeOS), + ("os x", "Mac OS X", HttpUserAgentPlatformType.MacOS), + ("ppc mac", "Power PC Mac", HttpUserAgentPlatformType.MacOS), + ("freebsd", "FreeBSD", HttpUserAgentPlatformType.Linux), + ("ppc", "Macintosh", HttpUserAgentPlatformType.Linux), + ("linux", "Linux", HttpUserAgentPlatformType.Linux), + ("debian", "Debian", HttpUserAgentPlatformType.Linux), + ("sunos", "Sun Solaris", HttpUserAgentPlatformType.Generic), + ("beos", "BeOS", HttpUserAgentPlatformType.Generic), + ("apachebench", "ApacheBench", HttpUserAgentPlatformType.Generic), + ("aix", "AIX", HttpUserAgentPlatformType.Generic), + ("irix", "Irix", HttpUserAgentPlatformType.Generic), + ("osf", "DEC OSF", HttpUserAgentPlatformType.Generic), + ("hp-ux", "HP-UX", HttpUserAgentPlatformType.Windows), + ("netbsd", "NetBSD", HttpUserAgentPlatformType.Generic), + ("bsdi", "BSDi", HttpUserAgentPlatformType.Generic), + ("openbsd", "OpenBSD", HttpUserAgentPlatformType.Unix), + ("gnu", "GNU/Linux", HttpUserAgentPlatformType.Linux), + ("unix", "Unknown Unix OS", HttpUserAgentPlatformType.Unix), + ("symbian", "Symbian OS", HttpUserAgentPlatformType.Symbian), + ]; + + /// + /// The published browser definitions: token (pattern = "{token}.*?([0-9\.]+)") and name. + /// + private static readonly (string Token, string Name)[] s_expectedBrowsers = + [ + ("OPR", "Opera"), ("Flock", "Flock"), ("Edge", "Edge"), ("EdgA", "Edge"), ("Edg", "Edge"), ("Vivaldi", "Vivaldi"), + ("Brave Chrome", "Brave"), ("Chrome", "Chrome"), ("CriOS", "Chrome"), ("Opera.*?Version", "Opera"), ("Opera", "Opera"), + ("MSIE", "Internet Explorer"), ("Internet Explorer", "Internet Explorer"), ("Trident.* rv", "Internet Explorer"), + ("Shiira", "Shiira"), ("Firefox", "Firefox"), ("FxiOS", "Firefox"), ("Chimera", "Chimera"), ("Phoenix", "Phoenix"), + ("Firebird", "Firebird"), ("Camino", "Camino"), ("Netscape", "Netscape"), ("OmniWeb", "OmniWeb"), ("Version", "Safari"), + ("Mozilla", "Mozilla"), ("Konqueror", "Konqueror"), ("icab", "iCab"), ("Lynx", "Lynx"), ("Links", "Links"), + ("hotjava", "HotJava"), ("amaya", "Amaya"), ("IBrowse", "IBrowse"), ("Maxthon", "Maxthon"), ("ipod touch", "Apple iPod"), + ("Ubuntu", "Ubuntu Web Browser"), + ]; + + [Fact] + public void Platforms_Keep_Definitions_And_Order() + { + (string Pattern, string Name, HttpUserAgentPlatformType Type)[] actual = + [.. HttpUserAgentStatics.Platforms.Select(static p => (p.Regex.ToString(), p.Name, p.PlatformType))]; + + Assert.Equal(s_expectedPlatforms.Select(static p => (Regex.Escape(p.Token), p.Name, p.Type)), actual); + } + + [Fact] + public void Platforms_Use_Source_Generated_Regex_With_Previous_Options() + { + foreach (HttpUserAgentPlatformInformation platform in HttpUserAgentStatics.Platforms) + { + AssertSourceGenerated(platform.Regex); + Assert.Same(platform.Regex, platform.Regex); + } + } + + [Fact] + public void Platforms_Regex_Matches_Case_Insensitive() + { + HttpUserAgentPlatformInformation windows10 = HttpUserAgentStatics.Platforms.First(static p => string.Equals(p.Name, "Windows 10", StringComparison.Ordinal)); + + Assert.Matches(windows10.Regex, "Mozilla/5.0 (WINDOWS NT 10.0; Win64; x64)"); + Assert.DoesNotMatch(windows10.Regex, "Mozilla/5.0 (Windows NT 10x0; Win64; x64)"); + } + + [Fact] + public void Browsers_Keep_Definitions() + { + Dictionary actual = HttpUserAgentStatics.Browsers.ToDictionary(static b => b.Key.ToString(), static b => b.Value, StringComparer.Ordinal); + Dictionary expected = s_expectedBrowsers.ToDictionary(static b => $@"{b.Token}.*?([0-9\.]+)", static b => b.Name, StringComparer.Ordinal); + + Assert.Equal(expected, actual); + } + + [Fact] + public void Browsers_Use_Source_Generated_Regex_With_Previous_Options() + { + foreach (Regex regex in HttpUserAgentStatics.Browsers.Keys) + { + AssertSourceGenerated(regex); + } + } + + [Fact] + public void Browsers_Regex_Captures_Version_In_Group_1() + { + Regex chrome = HttpUserAgentStatics.Browsers.Single(static b => b.Key.ToString().StartsWith("Chrome", StringComparison.Ordinal)).Key; + + Match match = chrome.Match("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) chrome/158.0.0.0 Safari/537.36"); + + Assert.True(match.Success); + Assert.Equal("158.0.0.0", match.Groups[1].Value); + } + + [Fact] + public void Mobiles_Contain_All_Rules() + { + Assert.Equal(HttpUserAgentRules.Mobiles.Length, HttpUserAgentStatics.Mobiles.Count); + foreach ((string key, string value) in HttpUserAgentRules.Mobiles) + { + Assert.Equal(value, HttpUserAgentStatics.Mobiles[key]); + Assert.Equal(value, HttpUserAgentStatics.Mobiles[key.ToUpperInvariant()]); + } + } + + [Fact] + public void Robots_Is_The_Array_Used_By_The_Parser() + { + Assert.Same(HttpUserAgentRules.Robots, HttpUserAgentStatics.Robots); + Assert.Contains(("googlebot", "Googlebot"), HttpUserAgentStatics.Robots); + } + + [Fact] + public void Tools_Contains_Curl() + { + Assert.Equal("curl", HttpUserAgentStatics.Tools["CURL"]); + } + + [Fact] + public void Parser_Platform_Rules_Resolve_The_Regex_Of_Their_Token() + { + foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) + { + Assert.Equal(Regex.Escape(token), platform.Regex.ToString()); + Assert.Contains(platform, HttpUserAgentStatics.Platforms); + } + } + + [Fact] + public void Platform_Regex_Ids_Resolve_To_Distinct_Regexes() + { + HttpUserAgentPlatformRegexId[] ids = [.. Enum.GetValues().Where(static id => id != HttpUserAgentPlatformRegexId.None)]; + + Regex[] regexes = [.. ids.Select(static id => HttpUserAgentRegexes.GetPlatformRegex(id)!)]; + + Assert.All(regexes, static regex => Assert.NotNull(regex)); + Assert.Equal(ids.Length, regexes.Distinct().Count()); + Assert.Equal(HttpUserAgentStatics.Platforms.Count, ids.Length); + } + + [Theory] + [InlineData((byte)HttpUserAgentPlatformRegexId.None)] + [InlineData(byte.MaxValue)] + public void Platform_Regex_Id_Without_Regex_Returns_Null(byte id) + { + Assert.Null(HttpUserAgentRegexes.GetPlatformRegex((HttpUserAgentPlatformRegexId)id)); + } + + private static void AssertSourceGenerated(Regex regex) + { + Assert.Equal(RegexOptions.IgnoreCase, regex.Options); + Assert.Equal(s_matchTimeout, regex.MatchTimeout); + + // Source-generated regexes are Regex subclasses emitted into the declaring assembly. + Assert.NotEqual(typeof(Regex), regex.GetType()); + Assert.Same(typeof(HttpUserAgentRegexes).Assembly, regex.GetType().Assembly); + } +} diff --git a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs new file mode 100644 index 0000000..1b9ef3f --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs @@ -0,0 +1,276 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using MyCSharp.HttpUserAgentParser.TestHelpers; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class PriorityTokenMatcherTests +{ + private readonly struct TestDetector; + + private static PriorityTokenMatcher Create(string[] tokens, params ReadOnlySpan groupStarts) => new(tokens, groupStarts); + + [Fact] + public void Find_Returns_First_Token_In_Priority_Order_Not_Leftmost_Occurrence() + { + PriorityTokenMatcher matcher = Create(["beta", "alpha"]); + + Assert.Equal(0, matcher.Find("alpha beta", 0, out int position)); + Assert.Equal(6, position); + Assert.Equal(2, matcher.Count); + } + + [Fact] + public void Find_Starts_At_StartIndex() + { + PriorityTokenMatcher matcher = Create(["beta", "alpha"]); + + Assert.Equal(1, matcher.Find("alpha beta", 1, out int position)); + Assert.Equal(0, position); + } + + [Fact] + public void Find_Is_Case_Insensitive() + { + PriorityTokenMatcher matcher = Create(["iphone"]); + + Assert.Equal(0, matcher.Find("(IPHONE; CPU)", 0, out int position)); + Assert.Equal(1, position); + } + + [Fact] + public void Find_Returns_Minus_One_Without_Match() + { + PriorityTokenMatcher matcher = Create(["alpha", "beta", "lg"]); + + Assert.Equal(-1, matcher.Find("gamma", 0, out int position)); + Assert.Equal(-1, position); + } + + [Fact] + public void Find_Without_Tokens_Returns_Minus_One() + { + PriorityTokenMatcher matcher = Create([]); + + Assert.Equal(-1, matcher.Find("anything", 0, out _)); + } + + [Fact] + public void Find_Skips_Token_After_Covered_Token_When_StartIndex_Is_Inside_Group() + { + // "edg" is the group filter for "edge"; starting at "edge" with only "edg" present must not match. + PriorityTokenMatcher matcher = Create(["edg", "edge", "other"]); + + Assert.Equal(-1, matcher.Find("edgx", 1, out _)); + Assert.Equal(0, matcher.Find("edgx", 0, out _)); + } + + [Fact] + public void Find_Matches_Short_Tokens() + { + PriorityTokenMatcher matcher = Create(["lg", "o2", "longer"]); + + Assert.Equal(1, matcher.Find("Model O2 phone", 0, out int position)); + Assert.Equal(6, position); + Assert.Equal(0, matcher.Find("LG-L160L longer", 0, out _)); + Assert.Equal(2, matcher.Find("a longer text", 0, out _)); + } + + [Fact] + public void Find_Honors_Forced_Single_Token_Group() + { + PriorityTokenMatcher matcher = Create(["windows nt 10.0", "windows nt 6.1", "android"], 1); + + Assert.Equal(0, matcher.Find("(Windows NT 10.0; Win64)", 0, out int position)); + Assert.Equal(1, position); + Assert.Equal(2, matcher.Find("(Linux; Android 15)", 0, out _)); + Assert.Equal(-1, matcher.Find("(Linux; Android 15)", 3, out _)); + } + +#if NET9_0_OR_GREATER + [Fact] + public void Groups_Extract_Short_Tokens() + { + PriorityTokenMatcher matcher = Create(["lg", "longer", "o2"]); + + PriorityTokenGroup group = Assert.Single(matcher.Groups.ToArray()); + Assert.Equal(new[] { "longer" }, group.FilterValues); + Assert.Equal(new[] { "lg", "o2" }, group.ShortTokens); + } + + [Fact] + public void Groups_With_Short_Tokens_Only_Have_No_Vectorized_Filter() + { + PriorityTokenMatcher matcher = Create(["lg"]); + + PriorityTokenGroup group = Assert.Single(matcher.Groups.ToArray()); + Assert.Null(group.Values); + Assert.Equal(0, matcher.Find("LG-L160L", 0, out _)); + Assert.Equal(-1, matcher.Find("Pixel", 0, out _)); + } + + [Fact] + public void Groups_Drop_Tokens_Covered_By_Shorter_Tokens() + { + PriorityTokenMatcher covered = Create(["Edg", "Edge", "EdgA", "EdgiOS"]); + PriorityTokenMatcher replaced = Create(["Edge", "EdgA", "Edg"]); + + Assert.Equal(new[] { "Edg" }, Assert.Single(covered.Groups.ToArray()).FilterValues); + Assert.Equal(new[] { "Edg" }, Assert.Single(replaced.Groups.ToArray()).FilterValues); + } + + [Fact] + public void Groups_Hold_At_Most_Eight_Values() + { + PriorityTokenMatcher matcher = Create(["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii"]); + + PriorityTokenGroup[] groups = matcher.Groups.ToArray(); + Assert.Equal(2, groups.Length); + Assert.Equal(PriorityTokenGroup.MaxValuesPerGroup, groups[0].FilterValues.Length); + Assert.Equal((8, 9), (groups[1].Start, groups[1].End)); + Assert.Equal(8, matcher.Find("iii", 0, out _)); + } + + [Fact] + public void Groups_Accept_A_Token_That_Replaces_Existing_Values() + { + // The ninth token replaces "aaa1" and "aaa2", so the group does not overflow. + PriorityTokenMatcher matcher = Create(["aaa1", "aaa2", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "aaa"]); + + PriorityTokenGroup group = Assert.Single(matcher.Groups.ToArray()); + Assert.Equal(new[] { "bbb", "ccc", "ddd", "eee", "fff", "ggg", "aaa" }, group.FilterValues); + } + + [Fact] + public void Groups_Start_At_Requested_Indices() + { + PriorityTokenMatcher matcher = Create(["aaa", "bbb", "ccc", "ddd"], 1, 3); + + PriorityTokenGroup[] groups = matcher.Groups.ToArray(); + Assert.Equal(new[] { (0, 1), (1, 3), (3, 4) }, groups.Select(static g => (g.Start, g.End))); + } + + [Fact] + public void Built_In_Matchers_Use_Small_Vectorized_Groups() + { + Assert.All(HttpUserAgentRules.RobotMatcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); + Assert.All(HttpUserAgentRules.MobileMatcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); + + // Googlebot, by far the most common robot, is checked on its own. + Assert.Equal((0, 1), (HttpUserAgentRules.RobotMatcher.Groups[0].Start, HttpUserAgentRules.RobotMatcher.Groups[0].End)); + } + + [Fact] + public void ContainsAny_Checks_All_Groups() + { + PriorityTokenMatcher matcher = Create(["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "lg"]); + + Assert.True(matcher.ContainsAny("xx iii xx")); + Assert.True(matcher.ContainsAny("LG-L160L")); + Assert.False(matcher.ContainsAny("nothing")); + } + + [Fact] + public void Robot_Anchors_Add_Uncovered_Keys() + { + string[] anchors = HttpUserAgentRules.CreateRobotAnchors(["Examplebot", "Turnitin", "Bytespider"], ["bot", "spider"]); + + Assert.Equal(new[] { "bot", "spider", "Turnitin" }, anchors); + } + + [Fact] + public void Curated_Robot_Anchors_Cover_All_Default_Robot_Keys() + { + // When a new robot key is not covered, it becomes an anchor on its own (correct, but an extra vectorized pass). + // Extend the curated anchors instead. + Assert.Equal(HttpUserAgentRules.CuratedRobotAnchors.Length, HttpUserAgentRules.RobotAnchorMatcher.Count); + } + + public static TheoryData CatalogBrowserUserAgents => [.. UserAgentCatalog.Browsers.Select(static ua => ua.UserAgent)]; + + [Theory] + [MemberData(nameof(CatalogBrowserUserAgents))] + public void Robot_Anchors_Do_Not_Occur_In_Browser_User_Agents(string userAgent) + { + Assert.False(HttpUserAgentRules.RobotAnchorMatcher.ContainsAny(userAgent)); + } +#endif + + [Theory] + [MemberData(nameof(CatalogUserAgents))] + public void GetRobot_Equals_Sequential_Scan(string userAgent) + { + string? expected = null; + foreach ((string key, string value) in HttpUserAgentStatics.Robots) + { + if (userAgent.Contains(key, StringComparison.OrdinalIgnoreCase)) + { + expected = value; + break; + } + } + + Assert.Equal(expected, HttpUserAgentParser.GetRobot(userAgent)); + } + + public static TheoryData CatalogUserAgents => [.. UserAgentCatalog.All]; + + [Theory] + [MemberData(nameof(CatalogUserAgents))] + public void Built_In_Matchers_Equal_Sequential_Scan(string userAgent) + { + AssertEqualsSequentialScan(HttpUserAgentRules.MobileMatcher, [.. HttpUserAgentRules.Mobiles.Select(static rule => rule.Key)], userAgent); +#if NET9_0_OR_GREATER + AssertEqualsSequentialScan(HttpUserAgentRules.RobotMatcher, HttpUserAgentRules.DefaultRobotKeys, userAgent); +#endif + } + + private static void AssertEqualsSequentialScan(PriorityTokenMatcher matcher, string[] tokens, string input) + where T : struct + { + for (int start = 0; start <= tokens.Length; start++) + { + int expected = -1; + int expectedPosition = -1; + for (int i = start; i < tokens.Length; i++) + { + expectedPosition = input.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase); + if (expectedPosition >= 0) + { + expected = i; + break; + } + } + + Assert.Equal(expected, matcher.Find(input, start, out int position)); + Assert.Equal(expected >= 0 ? expectedPosition : -1, position); + } + } + + /// + /// User agents that contain several mobile tokens: the most specific token wins + /// (device or manufacturer before operating system before browser before generic fallback). + /// + [Theory] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1", "Apple iPhone")] + [InlineData("Mozilla/5.0 (iPod touch; CPU iPhone 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1", "Apple iPod")] + [InlineData("Mozilla/5.0 (Linux; Android 14; SAMSUNG SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/23.0 Chrome/115.0.0.0 Mobile Safari/537.36", "Samsung")] + [InlineData("Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15063", "Android")] + [InlineData("Mozilla/5.0 (Series40; Nokia501/14.0.4/java_runtime_version=Nokia_Asha_1_2; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/3.8.1.0.5", "Nokia")] + [InlineData("Opera/9.80 (Android; Opera Mini/36.2.2254/119.132; U; id) Presto/2.12.423 Version/12.16", "Android")] + [InlineData("Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54", "Opera Mini")] + [InlineData("Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7412.EU", "Nintendo 3DS")] + [InlineData("Opera/9.50 (Nintendo DSi; Opera/507; U; en-US)", "Nintendo DSi")] + [InlineData("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", "LG")] + [InlineData("Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124", "Nokia")] + [InlineData("Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1) AppleWebKit/413 (KHTML, like Gecko) Safari/413", "SymbianOS")] + [InlineData("BlackBerry9700/5.0.0.351 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/123", "BlackBerry")] + [InlineData("Mozilla/5.0 (PlayStation Vita 3.74) AppleWebKit/537.73 (KHTML, like Gecko) Silk/3.2", "PlayStation Vita")] + [InlineData("Mozilla/5.0 (Linux; Android 9; SHARP AQUOS sense3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Mobile Safari/537.36", "Sharp")] + [InlineData("Mozilla/5.0 (Mobile; rv:48.0; A405DL) Gecko/48.0 Firefox/48.0 KAIOS/2.5", "Generic Mobile")] + public void Mobile_Priority_Prefers_Specific_Matches(string userAgent, string expected) + { + Assert.Equal(expected, HttpUserAgentParser.GetMobileDevice(userAgent)); + } +} diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index 5a30cad..d5408d7 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -8,8 +8,13 @@ namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; -public class HttpUserAgentParserMetersTelemetryTests +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserMetersTelemetryTests : IDisposable { + public HttpUserAgentParserMetersTelemetryTests() => HttpUserAgentParserTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserTelemetry.ResetForTests(); + [Fact] public void Meters_DoNotEmit_WhenDisabled() { diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs new file mode 100644 index 0000000..ef3e5f3 --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs @@ -0,0 +1,113 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Diagnostics.Metrics; +using MyCSharp.HttpUserAgentParser.Telemetry; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; + +/// +/// Covers the telemetry building blocks directly: meters before and after enabling, EventSource methods without +/// listener, and the lifetime of an EventSource instance. +/// +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserTelemetryInternalsTests : IDisposable +{ + public HttpUserAgentParserTelemetryInternalsTests() => HttpUserAgentParserTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserTelemetry.ResetForTests(); + + [Fact] + public void Meters_Ignore_Measurements_Before_Enable() + { + Assert.False(HttpUserAgentParserMeters.IsEnabled); + Assert.False(HttpUserAgentParserMeters.IsParseDurationEnabled); + + HttpUserAgentParserMeters.ParseRequest(); + HttpUserAgentParserMeters.ParseDuration(0.1); + HttpUserAgentParserMeters.CacheHit(); + HttpUserAgentParserMeters.CacheMiss(); + + Assert.False(HttpUserAgentParserMeters.IsEnabled); + } + + [Fact] + public void Meters_Record_Measurements_After_Enable() + { + using Meter meter = new("test.core.meters"); + using MeterTestListener listener = new("test.core.meters"); + + HttpUserAgentParserMeters.Enable(meter); + HttpUserAgentParserMeters.ParseRequest(); + HttpUserAgentParserMeters.ParseDuration(0.1); + HttpUserAgentParserMeters.CacheHit(); + HttpUserAgentParserMeters.CacheMiss(); + + Assert.True(HttpUserAgentParserMeters.IsEnabled); + Assert.Equal(new[] { "cache.hit", "cache.miss", "parse.duration", "parse.requests" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); + } + + [Fact] + public void Parse_Duration_Is_Only_Measured_With_A_Listener() + { + using Meter meter = new("test.core.duration"); + HttpUserAgentParserMeters.Enable(meter); + + Assert.False(HttpUserAgentParserMeters.IsParseDurationEnabled); + + using MeterTestListener listener = new("test.core.duration"); + Assert.True(HttpUserAgentParserMeters.IsParseDurationEnabled); + } + + [Fact] + public void Parse_Duration_Is_Measured_For_Meters_While_Counters_Have_No_Listener() + { + using Meter meter = new("test.core.both"); + using MeterTestListener listener = new("test.core.both"); + + HttpUserAgentParserTelemetry.Enable(); + HttpUserAgentParserTelemetry.EnableMeters(meter); + + Assert.False(HttpUserAgentParserTelemetry.AreCountersEnabled); + Assert.True(HttpUserAgentParserTelemetry.ShouldMeasureParseDuration); + + _ = HttpUserAgentParser.Parse("Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/158.0.0.0"); + + Assert.Contains("parse.duration", listener.InstrumentNames, StringComparer.Ordinal); + } + + [Fact] + public void EventSource_Ignores_Calls_Without_Listener() + { + HttpUserAgentParserEventSource source = HttpUserAgentParserEventSource.Log; + Assert.False(source.IsEnabled()); + + source.ParseRequest(); + source.ParseDuration(0.1); + source.CacheHit(); + source.CacheMiss(); + + Assert.False(source.IsEnabled()); + } + + [Fact] + public void EventSource_Can_Be_Disposed() + { + HttpUserAgentParserEventSource source = new(); + Assert.Equal(HttpUserAgentParserEventSource.EventSourceName, source.Name); + + source.Dispose(); + + Assert.False(source.IsEnabled()); + } + + [Fact] + public void Telemetry_State_Tracks_Concurrent_Cache_Size() + { + HttpUserAgentParserTelemetry.ConcurrentCacheSizeSet(42); + Assert.Equal(42, HttpUserAgentParserTelemetryState.ConcurrentCacheSize); + + HttpUserAgentParserTelemetry.ResetForTests(); + Assert.Equal(0, HttpUserAgentParserTelemetryState.ConcurrentCacheSize); + } +} diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs new file mode 100644 index 0000000..b6e07bf --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -0,0 +1,81 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Microsoft.Extensions.DependencyInjection; +using MyCSharp.HttpUserAgentParser.DependencyInjection; +using MyCSharp.HttpUserAgentParser.Providers; +using MyCSharp.HttpUserAgentParser.Telemetry; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; + +/// +/// Covers every telemetry state of the parser and the cached provider explicitly, +/// instead of relying on the order in which other tests switch telemetry on or off. +/// +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserTelemetryPathTests : IDisposable +{ + private const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"; + + public HttpUserAgentParserTelemetryPathTests() => HttpUserAgentParserTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserTelemetry.ResetForTests(); + + [Fact] + public void Disabled_Telemetry_Parses_Without_Instrumentation() + { + Assert.False(HttpUserAgentParserTelemetry.IsEnabled); + + AssertParsesAndCaches(); + } + + [Fact] + public void Counters_Without_Listener_Neither_Measure_Duration_Nor_Track_Cache_Size() + { + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithTelemetry(); + + Assert.True(HttpUserAgentParserTelemetry.IsEnabled); + Assert.False(HttpUserAgentParserTelemetry.ShouldMeasureParseDuration); + Assert.False(HttpUserAgentParserTelemetry.IsCacheSizeEnabled); + + AssertParsesAndCaches(); + } + + [Fact] + public void Meters_Without_Duration_Listener_Track_Cache_Size_But_Do_Not_Measure_Duration() + { + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMeterTelemetry(); + + Assert.True(HttpUserAgentParserTelemetry.IsEnabled); + Assert.False(HttpUserAgentParserTelemetry.ShouldMeasureParseDuration); + Assert.True(HttpUserAgentParserTelemetry.IsCacheSizeEnabled); + + AssertParsesAndCaches(); + Assert.Equal(1, HttpUserAgentParserTelemetryState.ConcurrentCacheSize); + } + + [Fact] + public void Meters_Enable_Only_Once() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + using System.Diagnostics.Metrics.Meter first = new("test.first"); + using System.Diagnostics.Metrics.Meter second = new("test.second"); + using MeterTestListener listener = new("test.first"); + + options.WithMeterTelemetry(first).WithMeterTelemetry(second); + _ = HttpUserAgentParser.Parse(UserAgent); + + Assert.Contains("parse.requests", listener.InstrumentNames, StringComparer.Ordinal); + } + + private static void AssertParsesAndCaches() + { + Assert.Equal("Chrome", HttpUserAgentParser.Parse(UserAgent).Name); + + HttpUserAgentParserCachedProvider provider = new(); + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); // miss + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); // hit + Assert.Equal(1, provider.CacheEntryCount); + } +} diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs index a5e2682..209bc30 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs @@ -8,8 +8,13 @@ namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; -public class HttpUserAgentParserTelemetryTests +[Collection(TelemetryCollection.Name)] +public sealed class HttpUserAgentParserTelemetryTests : IDisposable { + public HttpUserAgentParserTelemetryTests() => HttpUserAgentParserTelemetry.ResetForTests(); + + public void Dispose() => HttpUserAgentParserTelemetry.ResetForTests(); + [Fact] public void EventCounters_DoNotThrow_WhenEnabled() { diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs new file mode 100644 index 0000000..628c6f5 --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs @@ -0,0 +1,15 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; + +/// +/// Telemetry switches and are process-wide static state. Tests that change or depend on it run in this collection, +/// which is not parallelized and runs after all parallel tests, so no other test observes a foreign telemetry state. +/// +[CollectionDefinition(Name, DisableParallelization = true)] +public sealed class TelemetryCollection +{ + public const string Name = "Telemetry"; +} diff --git a/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs b/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs new file mode 100644 index 0000000..03759e5 --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs @@ -0,0 +1,86 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using MyCSharp.HttpUserAgentParser.TestHelpers; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +/// +/// Real-world user agents: the most used browsers (current and previous version) and search engine, SEO and AI crawlers. +/// +public class UserAgentCatalogTests +{ + public static TheoryData BrowserLabels => [.. UserAgentCatalog.Browsers.Select(static ua => ua.Label)]; + + public static TheoryData RobotLabels => [.. UserAgentCatalog.Robots.Select(static ua => ua.Label)]; + + public static TheoryData UnknownUserAgents => [.. UserAgentCatalog.Unknown]; + + [Theory] + [MemberData(nameof(BrowserLabels))] + public void Browser(string label) + { + BrowserUserAgent expected = UserAgentCatalog.Browsers.Single(ua => string.Equals(ua.Label, label, StringComparison.Ordinal)); + + HttpUserAgentInformation info = HttpUserAgentParser.Parse(expected.UserAgent); + + Assert.Equal(HttpUserAgentType.Browser, info.Type); + Assert.Equal(expected.Name, info.Name); + Assert.Equal(expected.Version, info.Version); + HttpUserAgentPlatformInformation platform = Assert.NotNull(info.Platform); + Assert.Equal(expected.PlatformName, platform.Name); + Assert.Equal(expected.PlatformType, platform.PlatformType); + Assert.Equal(expected.MobileDeviceType, info.MobileDeviceType); + Assert.Equal(expected.MobileDeviceType is not null, info.IsMobile()); + } + + [Theory] + [MemberData(nameof(RobotLabels))] + public void Robot(string label) + { + RobotUserAgent expected = UserAgentCatalog.Robots.Single(ua => string.Equals(ua.Label, label, StringComparison.Ordinal)); + + HttpUserAgentInformation info = HttpUserAgentParser.Parse(expected.UserAgent); + + Assert.Equal(HttpUserAgentType.Robot, info.Type); + Assert.Equal(expected.Name, info.Name); + Assert.Null(info.Version); + Assert.Null(info.Platform); + Assert.Null(info.MobileDeviceType); + Assert.True(info.IsRobot()); + } + + [Theory] + [MemberData(nameof(UnknownUserAgents))] + public void Unknown(string userAgent) + { + HttpUserAgentInformation info = HttpUserAgentParser.Parse(userAgent); + + Assert.Equal(HttpUserAgentType.Unknown, info.Type); + Assert.Null(info.Name); + Assert.Null(info.Version); + } + + [Fact] + public void Catalog_Covers_All_Crawler_Categories() + { + Assert.Contains(UserAgentCatalog.Robots, ua => string.Equals(ua.Category, UserAgentCatalog.SearchCrawler, StringComparison.Ordinal)); + Assert.Contains(UserAgentCatalog.Robots, ua => string.Equals(ua.Category, UserAgentCatalog.SeoCrawler, StringComparison.Ordinal)); + Assert.Contains(UserAgentCatalog.Robots, ua => string.Equals(ua.Category, UserAgentCatalog.AiCrawler, StringComparison.Ordinal)); + } + + [Fact] + public void Catalog_Labels_Are_Unique() + { + Assert.Equal(UserAgentCatalog.Browsers.Count, UserAgentCatalog.Browsers.Select(ua => ua.Label).Distinct(StringComparer.Ordinal).Count()); + Assert.Equal(UserAgentCatalog.Robots.Count, UserAgentCatalog.Robots.Select(ua => ua.Label).Distinct(StringComparer.Ordinal).Count()); + Assert.Equal(UserAgentCatalog.Browsers.Count + UserAgentCatalog.Robots.Count + UserAgentCatalog.Unknown.Count, UserAgentCatalog.All.Count); + } + + [Fact] + public void Catalog_Entries_Display_Their_Label() + { + Assert.Equal("Chrome 158 Windows", UserAgentCatalog.Browsers[0].ToString()); + Assert.Equal("Googlebot Smartphone", UserAgentCatalog.Robots[0].ToString()); + } +} From a66cd2c1a6220445d5e69c42e0e8e022a87a5dca Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 16:03:26 +0100 Subject: [PATCH 02/41] ci: skip PR validation for draft pull requests Run the validation when a draft is marked as ready for review. --- .github/workflows/pr-validation.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index e8572c1..5659662 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -4,6 +4,8 @@ on: pull_request: branches: - main + # ready_for_review: validate a draft as soon as it is marked as ready + types: [opened, synchronize, reopened, ready_for_review] permissions: contents: read @@ -12,6 +14,8 @@ permissions: jobs: validate: name: Test on .NET 8 through 11 + # Draft pull requests are not validated + if: ${{ !github.event.pull_request.draft }} uses: ./.github/workflows/build-and-test.yml with: upload-test-results: true From ce8d5ddb6bc4e61eb930a9b728c3f6e32ab368ac Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 16:08:39 +0100 Subject: [PATCH 03/41] feat(aspnetcore): offer an IHttpContextAccessor based accessor next to Get(HttpContext) - Add IHttpUserAgentParserContextAccessor (extends IHttpUserAgentParserAccessor) with Get() and GetHttpContextUserAgent() for the current request - Add HttpUserAgentParserContextAccessor and AddHttpUserAgentParserContextAccessor(), which registers IHttpContextAccessor and, unless already registered, IHttpUserAgentParserAccessor - Cover both accessors in tests and in the Native AOT smoke test, document both options --- README.md | 18 +++++- ...serDependencyInjectionOptionsExtensions.cs | 25 +++++++- .../HttpUserAgentParserAccessor.cs | 1 + .../HttpUserAgentParserContextAccessor.cs | 27 +++++++++ .../IHttpUserAgentParserAccessor.cs | 10 +++- .../IHttpUserAgentParserContextAccessor.cs | 29 ++++++++++ src/HttpUserAgentParser.AspNetCore/readme.md | 18 +++++- ...tParserServiceCollectionExtensionsTests.cs | 29 ++++++++++ ...HttpUserAgentParserContextAccessorTests.cs | 57 +++++++++++++++++++ .../Program.cs | 7 ++- version.json | 2 +- 11 files changed, 212 insertions(+), 11 deletions(-) create mode 100644 src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs create mode 100644 src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs create mode 100644 tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserContextAccessorTests.cs diff --git a/README.md b/README.md index 270ef17..32c4b92 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,16 @@ public void ConfigureServices(IServiceCollection services) ### ASP.NET Core -For ASP.NET Core applications, an accessor (`IHttpUserAgentParserAccessor`) can be registered additionally. It reads the `User-Agent` header of the `HttpContext` you pass in and parses it with the registered `IHttpUserAgentParserProvider`. It does not depend on `IHttpContextAccessor`. This requires the package [MyCSharp.HttpUserAgentParser.AspNetCore](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) +For ASP.NET Core applications, an accessor can be registered additionally. It reads the `User-Agent` header of a request and parses it with the registered `IHttpUserAgentParserProvider`. This requires the package [MyCSharp.HttpUserAgentParser.AspNetCore](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) + +There are two options: + +| Registration | Service | Usage | +| --- | --- | --- | +| `AddHttpUserAgentParserAccessor()` | `IHttpUserAgentParserAccessor` | `Get(httpContext)`: you pass the `HttpContext` | +| `AddHttpUserAgentParserContextAccessor()` | `IHttpUserAgentParserContextAccessor` | `Get()`: the current request via `IHttpContextAccessor`, plus `Get(httpContext)` | + +Passing the `HttpContext` is the recommended option: `IHttpContextAccessor` has a small cost on every request. The context accessor is useful in services that do not have the `HttpContext` at hand. ```csharp public void ConfigureServices(IServiceCollection services) @@ -100,6 +109,7 @@ public void ConfigureServices(IServiceCollection services) .AddHttpUserAgentMemoryCachedParser() // registers Parser, returns HttpUserAgentParserDependencyInjectionOptions // or use any other Parser registration like services.AddHttpUserAgentParser(); above .AddHttpUserAgentParserAccessor(); // registers IHttpUserAgentParserAccessor, uses IHttpUserAgentParserProvider + // or: .AddHttpUserAgentParserContextAccessor(); // additionally registers IHttpUserAgentParserContextAccessor and IHttpContextAccessor } ``` @@ -111,6 +121,12 @@ public void MyMethod(IHttpUserAgentParserAccessor parserAccessor, HttpContext ht { HttpUserAgentInformation? info = parserAccessor.Get(httpContext); // null if the request has no User-Agent header } + +// in any service, with AddHttpUserAgentParserContextAccessor() +public void MyMethod(IHttpUserAgentParserContextAccessor parserAccessor) +{ + HttpUserAgentInformation? info = parserAccessor.Get(); // null outside of a request or without User-Agent header +} ``` If you only need the raw header value, use `httpContext.GetUserAgentString()`. diff --git a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs index b73b694..b3be779 100644 --- a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs +++ b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs @@ -1,6 +1,8 @@ // Copyright © https://myCSharp.de - all rights reserved +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; @@ -12,7 +14,8 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; public static class HttpUserAgentParserDependencyInjectionOptionsExtensions { /// - /// Registers as . + /// Registers as : + /// the is passed explicitly, e.g. accessor.Get(httpContext). /// Requires a registered /// public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserAccessor( @@ -21,4 +24,24 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentPars options.Services.AddSingleton(); return options; } + + /// + /// Registers as and, + /// unless already registered, as , plus : + /// the current request is used with accessor.Get(), an explicit one with accessor.Get(httpContext). + /// Requires a registered + /// + /// + /// has a small cost on every request; prefer + /// when the is at hand. + /// + public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserContextAccessor( + this HttpUserAgentParserDependencyInjectionOptions options) + { + options.Services.AddHttpContextAccessor(); + options.Services.AddSingleton(); + options.Services.TryAddSingleton( + static serviceProvider => serviceProvider.GetRequiredService()); + return options; + } } diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs index a33fc05..855cd04 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs @@ -12,6 +12,7 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore; /// /// The accessor does not depend on : the is passed explicitly, /// e.g. from a controller, a minimal API handler or a middleware. +/// additionally parses the current request via . /// public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAgentParser) : IHttpUserAgentParserAccessor diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs new file mode 100644 index 0000000..25566bf --- /dev/null +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs @@ -0,0 +1,27 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Microsoft.AspNetCore.Http; +using MyCSharp.HttpUserAgentParser.Providers; + +namespace MyCSharp.HttpUserAgentParser.AspNetCore; + +/// +/// User Agent parser accessor for an explicitly passed and for the current request, +/// which is resolved via . +/// +/// +/// Creates a new instance of +/// +public class HttpUserAgentParserContextAccessor(IHttpUserAgentParserProvider httpUserAgentParser, IHttpContextAccessor httpContextAccessor) + : HttpUserAgentParserAccessor(httpUserAgentParser), IHttpUserAgentParserContextAccessor +{ + private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor; + + /// + public string? GetHttpContextUserAgent() + => _httpContextAccessor.HttpContext is { } httpContext ? GetHttpContextUserAgent(httpContext) : null; + + /// + public HttpUserAgentInformation? Get() + => _httpContextAccessor.HttpContext is { } httpContext ? Get(httpContext) : null; +} diff --git a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs index f33d5b4..87cac25 100644 --- a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs @@ -5,17 +5,21 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore; /// -/// User Agent parser accessor +/// User Agent parser accessor for an explicitly passed /// +/// +/// additionally parses the current request via . +/// public interface IHttpUserAgentParserAccessor { /// - /// User agent value + /// Returns the User-Agent header of , or without User-Agent header /// string? GetHttpContextUserAgent(HttpContext httpContext); /// - /// Returns current + /// Returns the parsed of , + /// or without User-Agent header /// HttpUserAgentInformation? Get(HttpContext httpContext); } diff --git a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs new file mode 100644 index 0000000..7fbb7c9 --- /dev/null +++ b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs @@ -0,0 +1,29 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Microsoft.AspNetCore.Http; + +namespace MyCSharp.HttpUserAgentParser.AspNetCore; + +/// +/// User Agent parser accessor that offers both ways to get the user agent of a request: +/// pass the explicitly (inherited from ), +/// or use the current request resolved via . +/// +/// +/// has a small cost on every request. Prefer +/// when the is at hand, e.g. in controllers, minimal APIs and middlewares. +/// +public interface IHttpUserAgentParserContextAccessor : IHttpUserAgentParserAccessor +{ + /// + /// Returns the User-Agent header of the current request, + /// or outside of a request or without User-Agent header + /// + string? GetHttpContextUserAgent(); + + /// + /// Returns the parsed of the current request, + /// or outside of a request or without User-Agent header + /// + HttpUserAgentInformation? Get(); +} diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index a595db0..173552b 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -15,15 +15,18 @@ dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore Register a provider (any of the available ones) and then add the accessor: -The accessor reads the `User-Agent` header from the `HttpContext` you pass in and parses it using the registered provider. It does not depend on `IHttpContextAccessor`. +The accessor reads the `User-Agent` header of a request and parses it using the registered provider. There are two options: + +- `AddHttpUserAgentParserAccessor()` registers `IHttpUserAgentParserAccessor`: you pass the `HttpContext` (`Get(httpContext)`). Recommended. +- `AddHttpUserAgentParserContextAccessor()` registers `IHttpUserAgentParserContextAccessor` and `IHttpContextAccessor`: `Get()` uses the current request, `Get(httpContext)` works as well. Useful in services without access to the `HttpContext`; `IHttpContextAccessor` has a small cost on every request. ```csharp services .AddHttpUserAgentMemoryCachedParser() // or: AddHttpUserAgentParser / AddHttpUserAgentCachedParser - .AddHttpUserAgentParserAccessor(); + .AddHttpUserAgentParserAccessor(); // or: .AddHttpUserAgentParserContextAccessor() ``` -Usage: +Usage with the `HttpContext`: ```csharp public sealed class MyController(IHttpUserAgentParserAccessor accessor) : ControllerBase @@ -36,6 +39,15 @@ public sealed class MyController(IHttpUserAgentParserAccessor accessor) : Contro app.MapGet("/ua", (HttpContext context, IHttpUserAgentParserAccessor accessor) => accessor.Get(context)); ``` +Usage with the current request (`AddHttpUserAgentParserContextAccessor()`): + +```csharp +public sealed class MyService(IHttpUserAgentParserContextAccessor accessor) +{ + public bool IsRobot() => accessor.Get()?.IsRobot() ?? false; // null outside of a request or without User-Agent header +} +``` + The package is trimming and Native AOT compatible. ### Just read the header diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index c5268e6..35fbcd1 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; @@ -23,4 +24,32 @@ public void AddHttpUserAgentParserAccessor() Assert.Equal(typeof(HttpUserAgentParserAccessor), services[0].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime); } + + [Fact] + public void AddHttpUserAgentParserContextAccessor_Offers_Both_Accessors() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentParser().AddHttpUserAgentParserContextAccessor(); + + using ServiceProvider provider = services.BuildServiceProvider(); + IHttpUserAgentParserContextAccessor contextAccessor = provider.GetRequiredService(); + + Assert.IsType(contextAccessor); + Assert.Same(contextAccessor, provider.GetRequiredService()); + Assert.NotNull(provider.GetService()); + } + + [Fact] + public void AddHttpUserAgentParserContextAccessor_Keeps_A_Registered_Accessor() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentParser().AddHttpUserAgentParserAccessor().AddHttpUserAgentParserContextAccessor(); + + using ServiceProvider provider = services.BuildServiceProvider(); + + Assert.IsType(provider.GetRequiredService()); + Assert.IsType(provider.GetRequiredService()); + } } diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserContextAccessorTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserContextAccessorTests.cs new file mode 100644 index 0000000..2817066 --- /dev/null +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserContextAccessorTests.cs @@ -0,0 +1,57 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Microsoft.AspNetCore.Http; +using MyCSharp.HttpUserAgentParser.Providers; +using NSubstitute; +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests; + +public class HttpUserAgentParserContextAccessorTests +{ + private const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"; + + private readonly IHttpUserAgentParserProvider _parserMock = Substitute.For(); + + public HttpUserAgentParserContextAccessorTests() + => _parserMock.Parse(UserAgent).Returns(HttpUserAgentInformation.Parse(UserAgent)); + + [Fact] + public void Get_Parses_The_Current_Request() + { + HttpUserAgentParserContextAccessor accessor = new(_parserMock, new HttpContextAccessor { HttpContext = HttpContextTestHelpers.GetHttpContext(UserAgent) }); + + Assert.Equal(UserAgent, accessor.GetHttpContextUserAgent()); + Assert.Equal("Chrome", accessor.Get()?.Name); + _parserMock.Received(1).Parse(UserAgent); + } + + [Fact] + public void Get_Parses_An_Explicit_Context() + { + HttpUserAgentParserContextAccessor accessor = new(_parserMock, new HttpContextAccessor()); + + Assert.Equal(UserAgent, accessor.GetHttpContextUserAgent(HttpContextTestHelpers.GetHttpContext(UserAgent))); + Assert.Equal("Chrome", accessor.Get(HttpContextTestHelpers.GetHttpContext(UserAgent))?.Name); + } + + [Fact] + public void Get_Returns_Null_Outside_Of_A_Request() + { + HttpUserAgentParserContextAccessor accessor = new(_parserMock, new HttpContextAccessor()); + + Assert.Null(accessor.GetHttpContextUserAgent()); + Assert.Null(accessor.Get()); + _parserMock.DidNotReceiveWithAnyArgs().Parse(default!); + } + + [Fact] + public void Get_Returns_Null_Without_User_Agent_Header() + { + HttpUserAgentParserContextAccessor accessor = new(_parserMock, new HttpContextAccessor { HttpContext = new DefaultHttpContext() }); + + Assert.Null(accessor.GetHttpContextUserAgent()); + Assert.Null(accessor.Get()); + _parserMock.DidNotReceiveWithAnyArgs().Parse(default!); + } +} diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs index 0b9462e..071e767 100644 --- a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs @@ -52,7 +52,7 @@ void Check(bool condition, string description) using Meter meter = new("smoke.http_user_agent_parser"); ServiceCollection services = new(); services.AddHttpUserAgentMemoryCachedParser(static options => options.CacheOptions.SizeLimit = 16) - .AddHttpUserAgentParserAccessor() + .AddHttpUserAgentParserContextAccessor() .WithMeterTelemetry(meter) .WithTelemetry(); @@ -63,7 +63,10 @@ void Check(bool condition, string description) DefaultHttpContext context = new(); context.Request.Headers.UserAgent = Safari; - Check(provider.GetRequiredService().Get(context) is { Name: "Safari" }, "ASP.NET Core accessor"); + Check(provider.GetRequiredService().Get(context) is { Name: "Safari" }, "ASP.NET Core accessor (explicit HttpContext)"); + + provider.GetRequiredService().HttpContext = context; + Check(provider.GetRequiredService().Get() is { Name: "Safari" }, "ASP.NET Core accessor (IHttpContextAccessor)"); } ServiceCollection genericServices = new(); diff --git a/version.json b/version.json index 72f7505..5e0bc01 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "3.1", + "version": "4.0", "nugetPackageVersion": { "semVer": 1 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1. }, From ad85cdb20a1ed25e2d124f7ce28fa9c73c9df56d Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 17:05:38 +0100 Subject: [PATCH 04/41] fix: address review findings for 4.0 - Browser version: read the version from the product token of the browser only (up to the next space, tab, ';', '(', ')' or ','), so an empty version no longer takes the version of the next product ("SamsungBrowser/ Chrome/131.0.0.0" is Chrome 131.0.0.0). - Meters (all packages): create the instruments under a lock and publish them as one object, so no registration returns before its instruments exist. The last registered meter is used, the same meter again is a no-op, calls without a meter share one default meter. - Robots: replace the pinned raw-reference snapshot with a managed key reference comparison; replaced values are honored on the fast path. - .NET 8: use the robot anchor prefilter on all target frameworks. - Native AOT smoke test: verify meter measurements (MeterListener) and EventCounters (EventListener, EventSourceSupport) of all packages. - Docs: catalog counts (48 crawlers, 96 user agents), benchmark results per runtime, allocation note for untrimmed input, regex culture and Compiled semantics, meter registration, unbounded ConcurrentDictionary cache, precise Native AOT statement. --- README.md | 60 +++++---- .../HttpUserAgentParserAspNetCoreMeters.cs | 86 ++++++------ src/HttpUserAgentParser.AspNetCore/readme.md | 3 + .../HttpUserAgentParserMemoryCacheMeters.cs | 80 ++++++++---- src/HttpUserAgentParser.MemoryCache/readme.md | 3 + .../HttpUserAgentParser.cs | 28 ++-- src/HttpUserAgentParser/HttpUserAgentRules.cs | 44 ++----- .../PriorityTokenMatcher.cs | 15 ++- .../Telemetry/HttpUserAgentParserMeters.cs | 122 ++++++++++-------- src/HttpUserAgentParser/readme.md | 12 +- ...ParserAspNetCoreTelemetryInternalsTests.cs | 13 +- ...arserMemoryCacheTelemetryInternalsTests.cs | 13 +- .../EventCounterListener.cs | 46 +++++++ ...HttpUserAgentParser.NativeAot.Smoke.csproj | 2 + .../Program.cs | 40 +++++- .../HttpUserAgentParserTests.cs | 20 +++ ...pUserAgentStaticsRobotsReplacementTests.cs | 32 +++-- .../PriorityTokenMatcherTests.cs | 6 +- .../HttpUserAgentParserTelemetryPathTests.cs | 84 +++++++++++- 19 files changed, 487 insertions(+), 222 deletions(-) create mode 100644 tests/HttpUserAgentParser.NativeAot.Smoke/EventCounterListener.cs diff --git a/README.md b/README.md index 32c4b92..fa00a3d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -Likewise, an In Process Cache mechanism is provided, based on a `ConcurrentDictionary`. +Likewise, an in-process cache based on a `ConcurrentDictionary` is provided. ```csharp public void ConfigureServices(IServiceCollection services) @@ -64,7 +64,7 @@ public void ConfigureServices(IServiceCollection services) } ``` - This is especially recommended for tests. For web applications, the `IMemoryCache` implementation should be used, which offers a timed expiration of the entries. +This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. Clients choose the `User-Agent` header freely, so use it only for a known, limited set of user agents, e.g. in tests. For web applications, use the `IMemoryCache` implementation, which limits the number of entries and expires them. The package [MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache) is required to use the IMemoryCache. This enables the registration of the `IMemoryCache` implementation: @@ -146,17 +146,27 @@ In every list the first matching entry wins. Brave and Vivaldi send the same use The parser does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` and `HttpUserAgentPlatformInformation.Regex` still provide regular expressions for your own matching. They are generated at compile time with `[GeneratedRegex]` (no runtime compilation, trimming and Native AOT compatible) and are only created on first access; the browser patterns capture the version in group 1. +The patterns use `RegexOptions.IgnoreCase` with culture-invariant case mapping, so a match does not depend on the current culture (e.g. `LINUX` matches `linux` under `tr-TR` as well). `RegexOptions.Compiled` is not set, because the source generator already emits the matching code. + `HttpUserAgentStatics.Robots` is the array the parser uses: if you replace an entry, the parser honors it. ## Native AOT and trimming -All packages are annotated with `IsAotCompatible` and are verified by publishing a Native AOT smoke test for every target framework (`tests/HttpUserAgentParser.NativeAot.Smoke`): +All packages are annotated with `IsAotCompatible`. The Native AOT smoke test (`tests/HttpUserAgentParser.NativeAot.Smoke`) is published and run with .NET 8, 9, 10 and 11 in every CI build of `main` and of pull requests: ```shell dotnet publish tests/HttpUserAgentParser.NativeAot.Smoke -c Release -f net11.0 -r linux-x64 ``` -Meters work out of the box. EventCounters rely on `EventSource`, which is disabled by default in Native AOT apps; enable it with `true` in your app's project file if you use `WithTelemetry()`. +The app roots all three library assemblies, so the trimmer and the AOT compiler analyze all of their code, and the publish fails on any trimming or AOT warning. At runtime it checks: + +- parsing of browsers, platforms, mobile devices and crawlers +- the source-generated regular expressions of `HttpUserAgentStatics` +- dependency injection with the cached providers and both ASP.NET Core accessors +- measurements of the meters of all three packages, received by a `MeterListener` +- the EventCounters of all three packages, received by an `EventListener` + +Meters work out of the box. EventCounters rely on `EventSource`, which is disabled by default in Native AOT apps; enable it with `true` in your app's project file if you use `WithTelemetry()`. The smoke test sets this property. ## Telemetry (EventCounters) @@ -274,6 +284,8 @@ public void ConfigureServices(IServiceCollection services) } ``` +Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one; registering the meter in use again has no effect. + ### Meter names and instruments Core meter (default: `mycsharp.http_user_agent_parser`) @@ -423,7 +435,7 @@ Notes: ## Benchmark -Run the parser benchmarks with the .NET 11 runtime. +Run the parser benchmarks with the .NET 11 runtime (use `-f net8.0`, `net9.0` or `net10.0` for the other runtimes). ```shell # 7 typical user agents @@ -436,36 +448,38 @@ dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 - The user agents come from `tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs`, which the unit tests use as well. -### Parser performance on .NET 11 +### Parser performance -BenchmarkDotNet 0.15.8 on .NET 11.0.0 x64, Windows 10 and an AMD Ryzen 9 9950X, without caching. The only allocation is the version string. +BenchmarkDotNet 0.15.8 in-process, x64, Windows 10 and an AMD Ryzen 9 9950X, without caching. For a user agent without leading or trailing white space, the only allocation is the version string; otherwise `Parse` also allocates the trimmed string. Mixed workload: the catalog user agents parsed in a loop, mean time per user agent. -| Workload | Mean | Allocated | -| --- | ---: | ---: | -| 44 browser user agents | 291.6 ns | 38 B | -| 49 crawler user agents | 143.1 ns | 0 B | -| All 97 user agents | 223.5 ns | 18 B | +| Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | .NET 11.0.0 | Allocated | +| --- | ---: | ---: | ---: | ---: | ---: | +| 44 browser user agents | 781.8 ns | 364.1 ns | 362.7 ns | 290.9 ns | 38 B | +| 48 crawler user agents | 384.1 ns | 184.7 ns | 170.8 ns | 171.3 ns | 0 B | +| All 96 user agents | 599.6 ns | 292.1 ns | 280.2 ns | 234.5 ns | 18 B | + +.NET 8 has no `SearchValues`; the parser checks the tokens one by one there. -Single user agents: +Single user agents on .NET 11: | User agent | Mean | Allocated | | --- | ---: | ---: | -| Chrome on Windows | 261.2 ns | 40 B | -| Firefox on Linux | 372.0 ns | 32 B | -| Chrome on Android | 276.6 ns | 40 B | -| Safari on iPhone | 320.3 ns | 32 B | -| Applebot | 170.7 ns | 0 B | -| Googlebot | 9.96 ns | 0 B | -| Unknown client | 422.3 ns | 0 B | +| Chrome on Windows | 244.5 ns | 40 B | +| Firefox on Linux | 345.3 ns | 32 B | +| Chrome on Android | 262.6 ns | 40 B | +| Safari on iPhone | 300.7 ns | 32 B | +| Applebot | 179.2 ns | 0 B | +| Googlebot | 9.44 ns | 0 B | +| Unknown client | 422.1 ns | 0 B | -Startup in a new process (median of 7 runs): +Startup in a new .NET 11 process (median of 7 runs): | | Time | Allocated | | --- | ---: | ---: | -| First `Parse` call | 9.6 ms | 129 KB | -| First use of all `HttpUserAgentStatics` regular expressions (43 platforms, 35 browsers) | 16.6 ms | 114 KB | +| First `Parse` call | 9.1 ms | 122 KB | +| First use of all `HttpUserAgentStatics` regular expressions (43 platforms, 35 browsers) | 15.7 ms | 120 KB | ### Library comparison on .NET 11 diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index b220bfc..c2e80ef 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -10,9 +10,8 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// System.Diagnostics.Metrics instruments emitted by MyCSharp.HttpUserAgentParser.AspNetCore. /// /// -/// Provides meter-based telemetry for User-Agent parsing and presence detection. -/// Instrument creation is performed once and guarded by a lock-free initialization -/// check to minimize overhead on hot paths. +/// All instruments of a meter are created before they become visible, so concurrent registrations never observe +/// a partially initialized state. The last registered meter is used. /// internal static class HttpUserAgentParserAspNetCoreMeters { @@ -38,76 +37,81 @@ internal static class HttpUserAgentParserAspNetCoreMeters public static string GetMeterName(string? meterPrefix) => HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix, MeterNameSuffix); - /// - /// Indicates whether the meter and its instruments have been initialized. - /// - private static int s_initialized; +#if NET9_0_OR_GREATER + private static readonly Lock s_lock = new(); +#else + private static readonly object s_lock = new(); +#endif - private static Meter? s_meter; - private static Counter? s_userAgentPresent; - private static Counter? s_userAgentMissing; + private static Meter? s_defaultMeter; + private static Instruments? s_instruments; /// - /// Enables meter-based telemetry and initializes all metric instruments. + /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// /// /// Optional externally managed instance. If not provided, - /// a new meter is created using . + /// a meter named is used. /// /// - /// Initialization is performed at most once. Subsequent calls are ignored. + /// Registering the meter that is already in use has no effect; another meter replaces it. /// public static void Enable(Meter? meter = null) { - if (Interlocked.Exchange(ref s_initialized, 1) == 1) + lock (s_lock) { - return; - } - - s_meter = meter ?? new Meter(MeterName); - - s_userAgentPresent = s_meter.CreateCounter( - name: "user_agent.present", - unit: "{call}", - description: "User-Agent header present"); + meter ??= s_defaultMeter ??= new Meter(MeterName); + if (ReferenceEquals(s_instruments?.Meter, meter)) + { + return; + } - s_userAgentMissing = s_meter.CreateCounter( - name: "user_agent.missing", - unit: "{call}", - description: "User-Agent header missing"); + // Publish the instruments only after all of them exist. + Volatile.Write(ref s_instruments, new Instruments(meter)); + } } /// /// Records a metric indicating that a User-Agent header was present. /// - /// - /// This method is optimized for hot paths and performs no work - /// if the counter has not been initialized. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UserAgentPresent() - => s_userAgentPresent?.Add(1); + => Volatile.Read(ref s_instruments)?.UserAgentPresent.Add(1); /// /// Records a metric indicating that a User-Agent header was missing. /// - /// - /// This method is optimized for hot paths and performs no work - /// if the counter has not been initialized. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UserAgentMissing() - => s_userAgentMissing?.Add(1); + => Volatile.Read(ref s_instruments)?.UserAgentMissing.Add(1); /// /// Resets static state to support isolated unit tests. /// public static void ResetForTests() { - Volatile.Write(ref s_initialized, 0); + lock (s_lock) + { + Volatile.Write(ref s_instruments, null); + s_defaultMeter = null; + } + } + + /// + /// The instruments of one meter. + /// + private sealed class Instruments(Meter meter) + { + public Meter Meter { get; } = meter; - s_meter = null; - s_userAgentPresent = null; - s_userAgentMissing = null; + public Counter UserAgentPresent { get; } = meter.CreateCounter( + name: "user_agent.present", + unit: "{call}", + description: "User-Agent header present"); + + public Counter UserAgentMissing { get; } = meter.CreateCounter( + name: "user_agent.missing", + unit: "{call}", + description: "User-Agent header missing"); } } diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index 173552b..e74acf6 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -97,6 +97,9 @@ services .WithAspNetCoreMeterTelemetry(); ``` +Pass your own `Meter` to `WithAspNetCoreMeterTelemetry(meter)` to record to it. A later registration with another meter +replaces the previous one; registering the meter in use again has no effect. + ### Meter + instruments Meter: `mycsharp.http_user_agent_parser.aspnetcore` (the prefix `mycsharp.` can be changed with `WithAspNetCoreMeterTelemetryPrefix(...)`) diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 175b81c..66c7fc6 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -9,6 +9,10 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// /// System.Diagnostics.Metrics instruments emitted by MyCSharp.HttpUserAgentParser.MemoryCache. /// +/// +/// All instruments of a meter are created before they become visible to the provider, so concurrent +/// registrations never observe a partially initialized state. The last registered meter is used. +/// internal static class HttpUserAgentParserMemoryCacheMeters { private const string MeterNameSuffix = "http_user_agent_parser.memorycache"; @@ -27,54 +31,74 @@ internal static class HttpUserAgentParserMemoryCacheMeters public static string GetMeterName(string? meterPrefix) => HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix, MeterNameSuffix); - private static int s_initialized; +#if NET9_0_OR_GREATER + private static readonly Lock s_lock = new(); +#else + private static readonly object s_lock = new(); +#endif - private static Meter? s_meter; - private static Counter? s_cacheHit; - private static Counter? s_cacheMiss; - private static ObservableGauge? s_cacheSize; + private static Meter? s_defaultMeter; + private static Instruments? s_instruments; - public static bool IsEnabled => Volatile.Read(ref s_initialized) != 0; + public static bool IsEnabled => Volatile.Read(ref s_instruments) is not null; + /// + /// Creates the metric instruments on (or on a default meter) and uses them from now on. + /// + /// + /// Registering the meter that is already in use has no effect; another meter replaces it. + /// public static void Enable(Meter? meter = null) { - if (Interlocked.Exchange(ref s_initialized, 1) == 1) + lock (s_lock) { - return; + meter ??= s_defaultMeter ??= new Meter(MeterName); + if (ReferenceEquals(s_instruments?.Meter, meter)) + { + return; + } + + // Publish the instruments only after all of them exist. + Volatile.Write(ref s_instruments, new Instruments(meter)); } + } - s_meter = meter ?? new Meter(MeterName); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void CacheHit() => Volatile.Read(ref s_instruments)?.CacheHit.Add(1); - s_cacheHit = s_meter.CreateCounter( + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void CacheMiss() => Volatile.Read(ref s_instruments)?.CacheMiss.Add(1); + + public static void ResetForTests() + { + lock (s_lock) + { + Volatile.Write(ref s_instruments, null); + s_defaultMeter = null; + } + } + + /// + /// The instruments of one meter. + /// + private sealed class Instruments(Meter meter) + { + public Meter Meter { get; } = meter; + + public Counter CacheHit { get; } = meter.CreateCounter( name: "cache.hit", unit: "{call}", description: "Cache hit"); - s_cacheMiss = s_meter.CreateCounter( + public Counter CacheMiss { get; } = meter.CreateCounter( name: "cache.miss", unit: "{call}", description: "Cache miss"); - s_cacheSize = s_meter.CreateObservableGauge( + public ObservableGauge CacheSize { get; } = meter.CreateObservableGauge( name: "cache.size", observeValue: static () => HttpUserAgentParserMemoryCacheTelemetryState.CacheSize, unit: "{entry}", description: "Cache size"); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheHit() => s_cacheHit?.Add(1); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheMiss() => s_cacheMiss?.Add(1); - - public static void ResetForTests() - { - Volatile.Write(ref s_initialized, 0); - - s_meter = null; - s_cacheHit = null; - s_cacheMiss = null; - s_cacheSize = null; - } } diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/readme.md index a015172..57aca91 100644 --- a/src/HttpUserAgentParser.MemoryCache/readme.md +++ b/src/HttpUserAgentParser.MemoryCache/readme.md @@ -99,6 +99,9 @@ services .WithMemoryCacheMeterTelemetry(); ``` +Pass your own `Meter` to `WithMemoryCacheMeterTelemetry(meter)` to record to it. A later registration with another meter +replaces the previous one; registering the meter in use again has no effect. + ### Meter + instruments Meter: `mycsharp.http_user_agent_parser.memorycache` (constant: `HttpUserAgentParserMemoryCachedProvider.MeterName`) diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index e811536..daad19a 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -17,6 +17,11 @@ public static class HttpUserAgentParser { private static readonly SearchValues s_versionCharacters = SearchValues.Create("0123456789."); + /// + /// Characters that end a product token ("product/version") or a comment entry of a user agent. + /// + private static readonly SearchValues s_productTokenDelimiters = SearchValues.Create(" \t;(),"); + /// /// Parses given user agent /// @@ -162,7 +167,6 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri { ReadOnlySpan ua = userAgent.AsSpan(); (string Key, string Value)[] robots = HttpUserAgentRules.Robots; -#if NET9_0_OR_GREATER string[] defaultKeys = HttpUserAgentRules.DefaultRobotKeys; // Googlebot, by far the most common robot, comes first: if the entry is unchanged and matches, it wins. @@ -172,9 +176,9 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri return firstValue; } - if (HttpUserAgentRules.AreRobotsUnchanged()) + if (HttpUserAgentRules.AreRobotKeysUnchanged()) { - // Few vectorized passes over the anchors rule out most user agents (browsers) before the full key search. + // The few anchors rule out most user agents (browsers) before the full key search. if (!HttpUserAgentRules.RobotAnchorMatcher.ContainsAny(ua)) { return null; @@ -184,8 +188,9 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri return index >= 0 ? robots[index].Value : null; } - // The public array is mutable and callers replaced entries: default keys are filtered by group, - // replaced keys are checked one by one, in array order. + // The public array is mutable and callers replaced keys: they are checked one by one, in array order. +#if NET9_0_OR_GREATER + // Default keys are filtered by group. foreach (ref readonly PriorityTokenGroup group in HttpUserAgentRules.RobotMatcher.Groups) { bool mayMatchDefaultKey = group.MayMatch(ua); @@ -250,12 +255,19 @@ private static bool TryIndexOf(ReadOnlySpan haystack, ReadOnlySpan n } /// - /// Finds the first ASCII digit and reads subsequent digits and dots within the search window. + /// Finds the first ASCII digit and reads subsequent digits and dots within the current product token. /// + /// + /// The search ends at the next delimiter, so an empty version never takes the version of the next product + /// (SamsungBrowser/ Chrome/131.0 has no Samsung Internet version). + /// private static bool TryExtractVersion(ReadOnlySpan haystack, out Range range) { - const int SearchWindow = 128; - haystack = haystack[..Math.Min(haystack.Length, SearchWindow)]; + int end = haystack.IndexOfAny(s_productTokenDelimiters); + if (end >= 0) + { + haystack = haystack[..end]; + } int start = haystack.IndexOfAnyInRange('0', '9'); if (start < 0) diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 6b9d59f..7cacc9c 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -1,10 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved using System.Collections.Frozen; -#if NET9_0_OR_GREATER -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -#endif namespace MyCSharp.HttpUserAgentParser; @@ -241,7 +237,6 @@ internal static readonly (string Key, string Value)[] Robots = ( "YouBot", "YouBot" ), ]; -#if NET9_0_OR_GREATER /// /// The default robot keys, used to detect entries replaced by callers. /// @@ -254,8 +249,8 @@ internal static readonly (string Key, string Value)[] Robots = /// /// Short substrings ("anchors") of the default robot keys. Every key contains at least one anchor, - /// so a user agent without any anchor cannot match a default key. The few anchors need far fewer vectorized - /// passes than all keys, which makes the common case (a browser) cheap. + /// so a user agent without any anchor cannot match a default key. The few anchors need far fewer searches + /// than all keys, which makes the common case (a browser) cheap. /// internal static readonly string[] CuratedRobotAnchors = [ @@ -289,38 +284,27 @@ internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAncho } /// - /// Raw contents (string references) of at startup. - /// - private static readonly byte[] s_robotsSnapshot = CreateRobotsSnapshot(); - - /// - /// Returns if no entry of has been replaced. + /// Returns if no key of has been replaced. /// /// - /// Compares the string references of all entries with the startup snapshot in a single vectorized operation, - /// which is much cheaper than checking every entry on each parse. + /// Compares the key references with . Replaced display names (values) do not matter: + /// the parser returns the current value of the matching entry. /// - internal static bool AreRobotsUnchanged() => GetRawContents(Robots).SequenceEqual(s_robotsSnapshot); - - private static byte[] CreateRobotsSnapshot() + internal static bool AreRobotKeysUnchanged() { - // Pin the default strings: their addresses must stay valid identities for the lifetime of the process. - // (String literals are allocated on the frozen heap anyway, so this does not restrict the GC in practice.) - foreach ((string key, string value) in Robots) + ReadOnlySpan defaultKeys = DefaultRobotKeys; + ReadOnlySpan<(string Key, string Value)> robots = Robots.AsSpan(0, defaultKeys.Length); + for (int i = 0; i < defaultKeys.Length; i++) { - _ = GCHandle.Alloc(key, GCHandleType.Pinned); - _ = GCHandle.Alloc(value, GCHandleType.Pinned); + if (!ReferenceEquals(robots[i].Key, defaultKeys[i])) + { + return false; + } } - return GetRawContents(Robots).ToArray(); + return true; } - private static ReadOnlySpan GetRawContents((string Key, string Value)[] robots) - => MemoryMarshal.CreateReadOnlySpan( - ref Unsafe.As<(string Key, string Value), byte>(ref MemoryMarshal.GetArrayDataReference(robots)), - robots.Length * Unsafe.SizeOf<(string Key, string Value)>()); -#endif - /// /// Mobile device rules in priority order: the most specific match wins. /// diff --git a/src/HttpUserAgentParser/PriorityTokenMatcher.cs b/src/HttpUserAgentParser/PriorityTokenMatcher.cs index 17a1d22..061da2f 100644 --- a/src/HttpUserAgentParser/PriorityTokenMatcher.cs +++ b/src/HttpUserAgentParser/PriorityTokenMatcher.cs @@ -59,12 +59,15 @@ public PriorityTokenMatcher(string[] tokens, params ReadOnlySpan groupStart /// The token groups. /// internal ReadOnlySpan Groups => _groups; +#endif /// - /// Returns if any token occurs in ; only checks the group filters. + /// Returns if any token occurs in . /// public bool ContainsAny(ReadOnlySpan input) { +#if NET9_0_OR_GREATER + // The group filters alone answer the question. foreach (ref readonly PriorityTokenGroup group in _groups.AsSpan()) { if (group.MayMatch(input)) @@ -72,10 +75,18 @@ public bool ContainsAny(ReadOnlySpan input) return true; } } +#else + foreach (string token in _tokens) + { + if (input.Contains(token, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } +#endif return false; } -#endif /// /// Returns the index of the first token at or after that occurs in , diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index 389acc9..b71e9f9 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -10,8 +10,8 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// This is opt-in and designed to keep overhead negligible unless a listener is enabled. /// /// -/// Instruments are created once on first enablement and emit no data unless observed -/// by an active listener. +/// All instruments of a meter are created before they become visible to the parser, so concurrent +/// registrations never observe a partially initialized state. The last registered meter is used. /// internal static class HttpUserAgentParserMeters { @@ -37,105 +37,113 @@ internal static class HttpUserAgentParserMeters public static string GetMeterName(string? meterPrefix) => HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix, MeterNameSuffix); - private static int s_initialized; +#if NET9_0_OR_GREATER + private static readonly Lock s_lock = new(); +#else + private static readonly object s_lock = new(); +#endif - private static Meter? s_meter; - - private static Counter? s_parseRequests; - private static Histogram? s_parseDuration; - - private static Counter? s_concurrentCacheHit; - private static Counter? s_concurrentCacheMiss; - private static ObservableGauge? s_concurrentCacheSize; + private static Meter? s_defaultMeter; + private static Instruments? s_instruments; /// /// Gets whether meters have been initialized. /// - public static bool IsEnabled => Volatile.Read(ref s_initialized) != 0; + public static bool IsEnabled => Volatile.Read(ref s_instruments) is not null; /// /// Gets whether the parse duration histogram is currently enabled by a listener. /// - public static bool IsParseDurationEnabled => s_parseDuration?.Enabled ?? false; + public static bool IsParseDurationEnabled => Volatile.Read(ref s_instruments)?.ParseDuration.Enabled ?? false; /// - /// Initializes the meter and creates all metric instruments. + /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// /// - /// Initialization is performed at most once. Subsequent calls are ignored. + /// Registering the meter that is already in use has no effect; another meter replaces it. /// public static void Enable(Meter? meter = null) { - if (Interlocked.Exchange(ref s_initialized, 1) == 1) + lock (s_lock) { - return; + meter ??= s_defaultMeter ??= new Meter(MeterName); + if (ReferenceEquals(s_instruments?.Meter, meter)) + { + return; + } + + // Publish the instruments only after all of them exist. + Volatile.Write(ref s_instruments, new Instruments(meter)); } - - s_meter = meter ?? new Meter(MeterName); - - s_parseRequests = s_meter.CreateCounter( - name: "parse.requests", - unit: "{call}", - description: "User-Agent parse requests"); - - s_parseDuration = s_meter.CreateHistogram( - name: "parse.duration", - unit: "s", - description: "Parse duration"); - - s_concurrentCacheHit = s_meter.CreateCounter( - name: "cache.hit", - unit: "{call}", - description: "Cache hit"); - - s_concurrentCacheMiss = s_meter.CreateCounter( - name: "cache.miss", - unit: "{call}", - description: "Cache miss"); - - s_concurrentCacheSize = s_meter.CreateObservableGauge( - name: "cache.size", - observeValue: static () => HttpUserAgentParserTelemetryState.ConcurrentCacheSize, - unit: "{entry}", - description: "Cache size"); } /// /// Emits a counter increment for a parse request. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ParseRequest() => s_parseRequests?.Add(1); + public static void ParseRequest() => Volatile.Read(ref s_instruments)?.ParseRequests.Add(1); /// /// Records the parse duration in seconds. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ParseDuration(double seconds) => s_parseDuration?.Record(seconds); + public static void ParseDuration(double seconds) => Volatile.Read(ref s_instruments)?.ParseDuration.Record(seconds); /// /// Emits a counter increment for a cache hit. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheHit() => s_concurrentCacheHit?.Add(1); + public static void CacheHit() => Volatile.Read(ref s_instruments)?.CacheHit.Add(1); /// /// Emits a counter increment for a cache miss. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheMiss() => s_concurrentCacheMiss?.Add(1); + public static void CacheMiss() => Volatile.Read(ref s_instruments)?.CacheMiss.Add(1); /// /// Resets static state to support isolated unit tests. /// public static void ResetForTests() { - Volatile.Write(ref s_initialized, 0); - - s_meter = null; - s_parseRequests = null; - s_parseDuration = null; - s_concurrentCacheHit = null; - s_concurrentCacheMiss = null; - s_concurrentCacheSize = null; + lock (s_lock) + { + Volatile.Write(ref s_instruments, null); + s_defaultMeter = null; + } + } + + /// + /// The instruments of one meter. + /// + private sealed class Instruments(Meter meter) + { + public Meter Meter { get; } = meter; + + public Counter ParseRequests { get; } = meter.CreateCounter( + name: "parse.requests", + unit: "{call}", + description: "User-Agent parse requests"); + + public Histogram ParseDuration { get; } = meter.CreateHistogram( + name: "parse.duration", + unit: "s", + description: "Parse duration"); + + public Counter CacheHit { get; } = meter.CreateCounter( + name: "cache.hit", + unit: "{call}", + description: "Cache hit"); + + public Counter CacheMiss { get; } = meter.CreateCounter( + name: "cache.miss", + unit: "{call}", + description: "Cache miss"); + + public ObservableGauge CacheSize { get; } = meter.CreateObservableGauge( + name: "cache.size", + observeValue: static () => HttpUserAgentParserTelemetryState.ConcurrentCacheSize, + unit: "{entry}", + description: "Cache size"); } } diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index 34631df..543e5d8 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -2,7 +2,7 @@ Fast HTTP User-Agent parsing for .NET. -- Allocation-free detection with vectorized `SearchValues`, no regular expressions in the parser +- Allocation-free detection with vectorized `SearchValues` (only the version string is allocated), no regular expressions in the parser - Trimming and Native AOT compatible - Detects the most used browsers and current search engine, SEO and AI crawlers @@ -27,7 +27,8 @@ HttpUserAgentInformation info = HttpUserAgentParser.Parse(userAgent); The parser itself does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` and `HttpUserAgentPlatformInformation.Regex` provide source-generated regular expressions (`[GeneratedRegex]`) for your own -matching; they are created on first access. +matching; they are created on first access. They use `RegexOptions.IgnoreCase` with culture-invariant case mapping and +no `RegexOptions.Compiled`, because the source generator already emits the matching code. ## Native AOT @@ -53,6 +54,10 @@ services // or: .AddHttpUserAgentParser(); ``` +This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. +Use it only for a known, limited set of user agents (e.g. in tests); for web applications use +[MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache). + ## Telemetry (EventCounters) Telemetry is: @@ -101,6 +106,9 @@ services .WithMeterTelemetry(); ``` +Pass your own `Meter` to `WithMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the +previous one; registering the meter in use again has no effect. + ### Meter + instruments Meter: `mycsharp.http_user_agent_parser` (the prefix `mycsharp.` can be changed with `WithMeterTelemetryPrefix(...)`) diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs index e7fe3a0..2f405b4 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs @@ -28,18 +28,23 @@ public void Meters_Ignore_Measurements_Before_Enable() } [Fact] - public void Meters_Are_Enabled_Only_Once() + public void Meters_Use_The_Last_Registered_Meter() { using Meter first = new("test.aspnetcore.first"); using Meter second = new("test.aspnetcore.second"); - using MeterTestListener listener = new("test.aspnetcore.first"); + using MeterTestListener firstListener = new("test.aspnetcore.first"); + using MeterTestListener secondListener = new("test.aspnetcore.second"); HttpUserAgentParserAspNetCoreMeters.Enable(first); - HttpUserAgentParserAspNetCoreMeters.Enable(second); + HttpUserAgentParserAspNetCoreMeters.Enable(first); // the meter in use: no effect HttpUserAgentParserAspNetCoreMeters.UserAgentPresent(); + HttpUserAgentParserAspNetCoreMeters.Enable(second); HttpUserAgentParserAspNetCoreMeters.UserAgentMissing(); + HttpUserAgentParserAspNetCoreMeters.Enable(); // default meter + HttpUserAgentParserAspNetCoreMeters.Enable(); // default meter in use: no effect - Assert.Equal(new[] { "user_agent.missing", "user_agent.present" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); + Assert.Equal(new[] { "user_agent.present" }, firstListener.InstrumentNames, StringComparer.Ordinal); + Assert.Equal(new[] { "user_agent.missing" }, secondListener.InstrumentNames, StringComparer.Ordinal); } [Fact] diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs index d63a9ac..8a9446a 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs @@ -27,19 +27,24 @@ public void Meters_Ignore_Measurements_Before_Enable() } [Fact] - public void Meters_Are_Enabled_Only_Once() + public void Meters_Use_The_Last_Registered_Meter() { using Meter first = new("test.memorycache.first"); using Meter second = new("test.memorycache.second"); - using MeterTestListener listener = new("test.memorycache.first"); + using MeterTestListener firstListener = new("test.memorycache.first"); + using MeterTestListener secondListener = new("test.memorycache.second"); HttpUserAgentParserMemoryCacheMeters.Enable(first); - HttpUserAgentParserMemoryCacheMeters.Enable(second); + HttpUserAgentParserMemoryCacheMeters.Enable(first); // the meter in use: no effect HttpUserAgentParserMemoryCacheMeters.CacheHit(); + HttpUserAgentParserMemoryCacheMeters.Enable(second); HttpUserAgentParserMemoryCacheMeters.CacheMiss(); + HttpUserAgentParserMemoryCacheMeters.Enable(); // default meter + HttpUserAgentParserMemoryCacheMeters.Enable(); // default meter in use: no effect Assert.True(HttpUserAgentParserMemoryCacheMeters.IsEnabled); - Assert.Equal(new[] { "cache.hit", "cache.miss" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); + Assert.Equal(new[] { "cache.hit" }, firstListener.InstrumentNames, StringComparer.Ordinal); + Assert.Equal(new[] { "cache.miss" }, secondListener.InstrumentNames, StringComparer.Ordinal); } [Fact] diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/EventCounterListener.cs b/tests/HttpUserAgentParser.NativeAot.Smoke/EventCounterListener.cs new file mode 100644 index 0000000..cb79c8c --- /dev/null +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/EventCounterListener.cs @@ -0,0 +1,46 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Collections.Concurrent; +using System.Diagnostics.Tracing; +using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; +using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using MyCSharp.HttpUserAgentParser.Telemetry; + +namespace MyCSharp.HttpUserAgentParser.NativeAot.Smoke; + +/// +/// Enables the EventSources of all packages and records which of them published EventCounters. +/// +internal sealed class EventCounterListener : EventListener +{ + private static readonly string[] s_eventSourceNames = + [ + HttpUserAgentParserEventSource.EventSourceName, + HttpUserAgentParserMemoryCacheEventSource.EventSourceName, + HttpUserAgentParserAspNetCoreEventSource.EventSourceName, + ]; + + private readonly ConcurrentDictionary _sourcesWithCounters = new(StringComparer.Ordinal); + + public bool WaitForCounters(TimeSpan timeout) + => SpinWait.SpinUntil(() => _sourcesWithCounters.Count == s_eventSourceNames.Length, timeout); + + protected override void OnEventSourceCreated(EventSource eventSource) + { + if (Array.Exists(s_eventSourceNames, name => string.Equals(name, eventSource.Name, StringComparison.Ordinal))) + { + EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, new Dictionary(StringComparer.Ordinal) + { + ["EventCounterIntervalSec"] = "0.1", + }); + } + } + + protected override void OnEventWritten(EventWrittenEventArgs eventData) + { + if (string.Equals(eventData.EventName, "EventCounters", StringComparison.Ordinal) && eventData.EventSource.Name is { } name) + { + _sourcesWithCounters[name] = true; + } + } +} diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj b/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj index f638a39..99808f0 100644 --- a/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj @@ -12,6 +12,8 @@ false true true + + true false false diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs index 071e767..61576a1 100644 --- a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs @@ -3,6 +3,7 @@ // Native AOT smoke test: exercises the public API of all packages in a trimmed, natively compiled app. // Exit code 0 means success; every failed check is printed and makes the exit code non-zero. +using System.Collections.Concurrent; using System.Diagnostics.Metrics; using System.Text.RegularExpressions; using Microsoft.AspNetCore.Http; @@ -12,6 +13,7 @@ using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; +using MyCSharp.HttpUserAgentParser.NativeAot.Smoke; using MyCSharp.HttpUserAgentParser.Providers; const string Chrome = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"; @@ -48,13 +50,36 @@ void Check(bool condition, string description) Regex chromeRegex = HttpUserAgentStatics.Browsers.First(static b => b.Key.ToString().StartsWith("Chrome", StringComparison.Ordinal)).Key; Check(string.Equals(chromeRegex.Match(Chrome).Groups[1].Value, "158.0.0.0", StringComparison.Ordinal), "browser regex version group"); -// Dependency injection, caching providers and ASP.NET Core accessor -using Meter meter = new("smoke.http_user_agent_parser"); +// Telemetry listeners: meters and EventCounters must emit data in a Native AOT app (EventSourceSupport is enabled) +ConcurrentDictionary measurements = new(StringComparer.Ordinal); +using MeterListener meterListener = new() +{ + InstrumentPublished = static (instrument, listener) => + { + if (instrument.Meter.Name.StartsWith("smoke.", StringComparison.Ordinal)) + { + listener.EnableMeasurementEvents(instrument); + } + }, +}; +meterListener.SetMeasurementEventCallback((instrument, _, _, _) => measurements.AddOrUpdate(instrument.Name, 1, static (_, count) => count + 1)); +meterListener.SetMeasurementEventCallback((instrument, _, _, _) => measurements.AddOrUpdate(instrument.Name, 1, static (_, count) => count + 1)); +meterListener.Start(); +using EventCounterListener counterListener = new(); + +// Dependency injection, caching providers and ASP.NET Core accessors +using Meter coreMeter = new("smoke.core"); +using Meter memoryCacheMeter = new("smoke.memorycache"); +using Meter aspNetCoreMeter = new("smoke.aspnetcore"); ServiceCollection services = new(); services.AddHttpUserAgentMemoryCachedParser(static options => options.CacheOptions.SizeLimit = 16) .AddHttpUserAgentParserContextAccessor() - .WithMeterTelemetry(meter) - .WithTelemetry(); + .WithMeterTelemetry(coreMeter) + .WithMemoryCacheMeterTelemetry(memoryCacheMeter) + .WithAspNetCoreMeterTelemetry(aspNetCoreMeter) + .WithTelemetry() + .WithMemoryCacheTelemetry() + .WithAspNetCoreTelemetry(); using (ServiceProvider provider = services.BuildServiceProvider()) { @@ -69,6 +94,13 @@ void Check(bool condition, string description) Check(provider.GetRequiredService().Get() is { Name: "Safari" }, "ASP.NET Core accessor (IHttpContextAccessor)"); } +foreach (string instrument in (string[])["parse.requests", "parse.duration", "cache.miss", "cache.hit", "user_agent.present"]) +{ + Check(measurements.ContainsKey(instrument), $"meter measurement {instrument}"); +} + +Check(counterListener.WaitForCounters(TimeSpan.FromSeconds(10)), "EventCounters of all packages"); + ServiceCollection genericServices = new(); genericServices.AddHttpUserAgentParser(); using (ServiceProvider provider = genericServices.BuildServiceProvider()) diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 344c34e..605ccd7 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -303,6 +303,26 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() Assert.Null(browser); // Should fail to extract version and continue, ending with no browser match } + [Theory] + [InlineData("SamsungBrowser/ Chrome/131.0.0.0 Safari/537.36", "Chrome", "131.0.0.0")] + [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)", "Internet Explorer", "8.0")] + [InlineData("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0")] + public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAgent, string expectedName, string expectedVersion) + { + (string Name, string? Version)? browser = HttpUserAgentParser.GetBrowser(userAgent); + + Assert.Equal((expectedName, expectedVersion), browser); + } + + [Theory] + [InlineData("Chrome/ Safari/537.36")] + [InlineData("Mozilla/5.0 (iPhone) Version/ Mobile/15E148 Safari/604.1")] + [InlineData("Mozilla/5.0 Firefox/(X11) 120")] + public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userAgent) + { + Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); + } + [Theory] [InlineData("Chrome/ı1.2é3", "1.2")] [InlineData("Chrome/1.2ı3 followed by a long suffix", "1.2")] diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs index 078a426..9c757ea 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -15,9 +15,7 @@ public class HttpUserAgentStaticsRobotsReplacementTests [Fact] public void Robots_Are_Unchanged_By_Default() { -#if NET9_0_OR_GREATER - Assert.True(HttpUserAgentRules.AreRobotsUnchanged()); -#endif + Assert.True(HttpUserAgentRules.AreRobotKeysUnchanged()); Assert.Equal("YouBot", HttpUserAgentParser.GetRobot(HttpUserAgentStatics.Robots[^1].Key)); } @@ -30,9 +28,7 @@ public void GetRobot_UsesReplacementRuleInOriginalOrder() try { HttpUserAgentStatics.Robots[last] = ("CustomTestCrawler", "Custom crawler"); -#if NET9_0_OR_GREATER - Assert.False(HttpUserAgentRules.AreRobotsUnchanged()); -#endif + Assert.False(HttpUserAgentRules.AreRobotKeysUnchanged()); Assert.Equal("Custom crawler", HttpUserAgentParser.GetRobot("customtestcrawler/1.0")); Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("customtestcrawler/1.0 googlebot/2.1")); @@ -45,9 +41,27 @@ public void GetRobot_UsesReplacementRuleInOriginalOrder() HttpUserAgentStatics.Robots[last] = original; } -#if NET9_0_OR_GREATER - Assert.True(HttpUserAgentRules.AreRobotsUnchanged()); -#endif + Assert.True(HttpUserAgentRules.AreRobotKeysUnchanged()); + } + + [Fact] + public void GetRobot_Returns_Replaced_Display_Name() + { + int index = Array.FindIndex(HttpUserAgentStatics.Robots, static robot => string.Equals(robot.Key, "bingbot", StringComparison.Ordinal)); + (string Key, string Value) original = HttpUserAgentStatics.Robots[index]; + + try + { + // Only the display name changes: the keys are unchanged, so the fast path stays active. + HttpUserAgentStatics.Robots[index] = (original.Key, "Bing crawler"); + Assert.True(HttpUserAgentRules.AreRobotKeysUnchanged()); + + Assert.Equal("Bing crawler", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); + } + finally + { + HttpUserAgentStatics.Robots[index] = original; + } } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs index 1b9ef3f..ee45240 100644 --- a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs @@ -160,6 +160,7 @@ public void Built_In_Matchers_Use_Small_Vectorized_Groups() // Googlebot, by far the most common robot, is checked on its own. Assert.Equal((0, 1), (HttpUserAgentRules.RobotMatcher.Groups[0].Start, HttpUserAgentRules.RobotMatcher.Groups[0].End)); } +#endif [Fact] public void ContainsAny_Checks_All_Groups() @@ -182,7 +183,7 @@ public void Robot_Anchors_Add_Uncovered_Keys() [Fact] public void Curated_Robot_Anchors_Cover_All_Default_Robot_Keys() { - // When a new robot key is not covered, it becomes an anchor on its own (correct, but an extra vectorized pass). + // When a new robot key is not covered, it becomes an anchor on its own (correct, but an extra search). // Extend the curated anchors instead. Assert.Equal(HttpUserAgentRules.CuratedRobotAnchors.Length, HttpUserAgentRules.RobotAnchorMatcher.Count); } @@ -195,7 +196,6 @@ public void Robot_Anchors_Do_Not_Occur_In_Browser_User_Agents(string userAgent) { Assert.False(HttpUserAgentRules.RobotAnchorMatcher.ContainsAny(userAgent)); } -#endif [Theory] [MemberData(nameof(CatalogUserAgents))] @@ -221,9 +221,7 @@ public void GetRobot_Equals_Sequential_Scan(string userAgent) public void Built_In_Matchers_Equal_Sequential_Scan(string userAgent) { AssertEqualsSequentialScan(HttpUserAgentRules.MobileMatcher, [.. HttpUserAgentRules.Mobiles.Select(static rule => rule.Key)], userAgent); -#if NET9_0_OR_GREATER AssertEqualsSequentialScan(HttpUserAgentRules.RobotMatcher, HttpUserAgentRules.DefaultRobotKeys, userAgent); -#endif } private static void AssertEqualsSequentialScan(PriorityTokenMatcher matcher, string[] tokens, string input) diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs index b6e07bf..738d7ce 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics.Metrics; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; @@ -55,18 +56,89 @@ public void Meters_Without_Duration_Listener_Track_Cache_Size_But_Do_Not_Measure } [Fact] - public void Meters_Enable_Only_Once() + public void Meters_Use_The_Last_Registered_Meter() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); - using System.Diagnostics.Metrics.Meter first = new("test.first"); - using System.Diagnostics.Metrics.Meter second = new("test.second"); - using MeterTestListener listener = new("test.first"); + using Meter first = new("test.first"); + using Meter second = new("test.second"); + using MeterTestListener firstListener = new("test.first"); + using MeterTestListener secondListener = new("test.second"); - options.WithMeterTelemetry(first).WithMeterTelemetry(second); + options.WithMeterTelemetry(first); _ = HttpUserAgentParser.Parse(UserAgent); + options.WithMeterTelemetry(second); + _ = HttpUserAgentParser.Parse(UserAgent); + + Assert.Single(firstListener.InstrumentNames, static name => string.Equals(name, "parse.requests", StringComparison.Ordinal)); + Assert.Single(secondListener.InstrumentNames, static name => string.Equals(name, "parse.requests", StringComparison.Ordinal)); + } - Assert.Contains("parse.requests", listener.InstrumentNames, StringComparer.Ordinal); + [Fact] + public void Registering_The_Same_Meter_Again_Keeps_The_Instruments() + { + using Meter meter = new("test.same"); + int published = 0; + int publishedOnDefaultMeter = 0; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + published += instrument.Meter == meter ? 1 : 0; + publishedOnDefaultMeter += string.Equals(instrument.Meter.Name, HttpUserAgentParserMeters.MeterName, StringComparison.Ordinal) ? 1 : 0; + }, + }; + listener.Start(); + publishedOnDefaultMeter = 0; // ignore instruments of earlier tests + + HttpUserAgentParserTelemetry.EnableMeters(meter); + HttpUserAgentParserTelemetry.EnableMeters(meter); + Assert.Equal(5, published); + + HttpUserAgentParserTelemetry.EnableMeters(); + HttpUserAgentParserTelemetry.EnableMeters(); + Assert.Equal(5, publishedOnDefaultMeter); + } + + [Fact] + public async Task Concurrent_Registration_Returns_After_All_Instruments_Exist() + { + CancellationToken cancellationToken = TestContext.Current.CancellationToken; + using Meter meter = new("test.race"); + using ManualResetEventSlim creating = new(); + using ManualResetEventSlim release = new(); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter != meter) + { + return; + } + + if (string.Equals(instrument.Name, "parse.requests", StringComparison.Ordinal)) + { + // The first registration stops while it creates its instruments. + creating.Set(); + release.Wait(TimeSpan.FromSeconds(10), cancellationToken); + } + + target.EnableMeasurementEvents(instrument); + }, + }; + listener.Start(); + + Task first = Task.Run(() => HttpUserAgentParserTelemetry.EnableMeters(meter), cancellationToken); + Assert.True(creating.Wait(TimeSpan.FromSeconds(10), cancellationToken)); + Task second = Task.Run(() => HttpUserAgentParserTelemetry.EnableMeters(meter), cancellationToken); + + // The second registration must not return while the instruments of the first one are incomplete. + Assert.NotSame(second, await Task.WhenAny(second, Task.Delay(200, cancellationToken))); + + release.Set(); + await Task.WhenAll(first, second).WaitAsync(TimeSpan.FromSeconds(10), cancellationToken); + + Assert.True(HttpUserAgentParserTelemetry.ShouldMeasureParseDuration); } private static void AssertParsesAndCaches() From b11d004df7b053673d2d960473a0c2c50e1bdf11 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 17:41:58 +0100 Subject: [PATCH 05/41] fix: browser version search, meter switching and MemoryCache keys - Browser version: if a token has no version, check the next occurrence of the same token before the next rule ("Chrome/ Chrome/131.0" is Chrome 131.0). A separate version token (Version/, MSIE, rv:) only counts at the start of a token ("Opera/9.80 VendorVersion/120.0" is Opera 9.80). - Meters: create the instruments once per meter (ConditionalWeakTable), so a meter registered again reuses them. The cache.size gauges report only while their meter is in use; a replaced meter no longer reports the cache size, and switching back no longer reports it twice. - MemoryCache: use the user agent string as cache key. The reused thread-static CacheKey was stored as the key of new entries and changed by the next call on that thread, so entries were lost between threads. Keys are ordinal now (Equals ignored case, the hash did not). --- README.md | 24 ++-- .../HttpUserAgentParserAspNetCoreMeters.cs | 18 +-- src/HttpUserAgentParser.AspNetCore/readme.md | 2 +- ...HttpUserAgentParserMemoryCachedProvider.cs | 135 +++++------------- .../HttpUserAgentParserMemoryCacheMeters.cs | 70 +++++---- src/HttpUserAgentParser.MemoryCache/readme.md | 2 +- .../HttpUserAgentParser.cs | 97 ++++++++++--- .../Telemetry/HttpUserAgentParserMeters.cs | 94 +++++++----- src/HttpUserAgentParser/readme.md | 2 +- ...ParserAspNetCoreTelemetryInternalsTests.cs | 19 +++ ...rserMemoryCachedProviderAdditionalTests.cs | 36 +++++ ...ParserMemoryCachedProviderCacheKeyTests.cs | 36 ----- ...arserMemoryCacheTelemetryInternalsTests.cs | 24 ++++ .../HttpUserAgentParserTests.cs | 9 ++ .../HttpUserAgentParserTelemetryPathTests.cs | 24 ++++ 15 files changed, 347 insertions(+), 245 deletions(-) delete mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs diff --git a/README.md b/README.md index fa00a3d..82376e6 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ If you only need the raw header value, use `httpContext.GetUserAgentString()`. 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) 4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Yandex Browser, UC Browser and others -In every list the first matching entry wins. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome; iPadOS sends the macOS user agent by default. +In every list the first matching entry wins. A browser version is read from the browser's own product token (`Chrome/131.0.0.0`); a separate version token such as Safari's `Version/` only counts at the start of a token, so `VendorVersion/1.0` is ignored. If a token has no version, the next occurrence of the token and then the next rule is checked. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome; iPadOS sends the macOS user agent by default. ### `HttpUserAgentStatics` and regular expressions @@ -284,7 +284,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one; registering the meter in use again has no effect. +Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. ### Meter names and instruments @@ -456,9 +456,9 @@ Mixed workload: the catalog user agents parsed in a loop, mean time per user age | Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | .NET 11.0.0 | Allocated | | --- | ---: | ---: | ---: | ---: | ---: | -| 44 browser user agents | 781.8 ns | 364.1 ns | 362.7 ns | 290.9 ns | 38 B | -| 48 crawler user agents | 384.1 ns | 184.7 ns | 170.8 ns | 171.3 ns | 0 B | -| All 96 user agents | 599.6 ns | 292.1 ns | 280.2 ns | 234.5 ns | 18 B | +| 44 browser user agents | 751.2 ns | 359.9 ns | 358.0 ns | 291.3 ns | 38 B | +| 48 crawler user agents | 370.5 ns | 187.1 ns | 175.2 ns | 164.4 ns | 0 B | +| All 96 user agents | 586.1 ns | 290.4 ns | 276.2 ns | 243.6 ns | 18 B | .NET 8 has no `SearchValues`; the parser checks the tokens one by one there. @@ -466,13 +466,13 @@ Single user agents on .NET 11: | User agent | Mean | Allocated | | --- | ---: | ---: | -| Chrome on Windows | 244.5 ns | 40 B | -| Firefox on Linux | 345.3 ns | 32 B | -| Chrome on Android | 262.6 ns | 40 B | -| Safari on iPhone | 300.7 ns | 32 B | -| Applebot | 179.2 ns | 0 B | -| Googlebot | 9.44 ns | 0 B | -| Unknown client | 422.1 ns | 0 B | +| Chrome on Windows | 249.4 ns | 40 B | +| Firefox on Linux | 352.4 ns | 32 B | +| Chrome on Android | 267.1 ns | 40 B | +| Safari on iPhone | 295.2 ns | 32 B | +| Applebot | 182.5 ns | 0 B | +| Googlebot | 9.45 ns | 0 B | +| Unknown client | 404.8 ns | 0 B | Startup in a new .NET 11 process (median of 7 runs): diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index c2e80ef..607d52a 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -46,6 +46,11 @@ public static string GetMeterName(string? meterPrefix) private static Meter? s_defaultMeter; private static Instruments? s_instruments; + /// + /// The instruments of every registered meter; a meter registered again reuses its instruments. + /// + private static readonly ConditionalWeakTable s_instrumentsByMeter = new(); + /// /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// @@ -54,20 +59,16 @@ public static string GetMeterName(string? meterPrefix) /// a meter named is used. /// /// - /// Registering the meter that is already in use has no effect; another meter replaces it. + /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. /// public static void Enable(Meter? meter = null) { lock (s_lock) { meter ??= s_defaultMeter ??= new Meter(MeterName); - if (ReferenceEquals(s_instruments?.Meter, meter)) - { - return; - } - // Publish the instruments only after all of them exist. - Volatile.Write(ref s_instruments, new Instruments(meter)); + // Instruments are created once per meter and published only after all of them exist. + Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); } } @@ -94,6 +95,7 @@ public static void ResetForTests() { Volatile.Write(ref s_instruments, null); s_defaultMeter = null; + s_instrumentsByMeter.Clear(); } } @@ -102,8 +104,6 @@ public static void ResetForTests() /// private sealed class Instruments(Meter meter) { - public Meter Meter { get; } = meter; - public Counter UserAgentPresent { get; } = meter.CreateCounter( name: "user_agent.present", unit: "{call}", diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index e74acf6..07b7cf4 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -98,7 +98,7 @@ services ``` Pass your own `Meter` to `WithAspNetCoreMeterTelemetry(meter)` to record to it. A later registration with another meter -replaces the previous one; registering the meter in use again has no effect. +replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. ### Meter + instruments diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index 1cac3ad..5f6dccc 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -22,127 +22,60 @@ public class HttpUserAgentParserMemoryCachedProvider( private readonly Microsoft.Extensions.Caching.Memory.MemoryCache _memoryCache = new(options.CacheOptions); private readonly HttpUserAgentParserMemoryCachedProviderOptions _options = options; + /// + /// Number of cached user agents. + /// + internal int CacheEntryCount => _memoryCache.Count; + /// /// - /// This method includes performance optimizations for telemetry: - /// - /// Telemetry checks use a volatile flag to ensure zero overhead when disabled. - /// Cache size tracking (via and ) is skipped entirely if the size metric is not enabled to avoid allocations. - /// + /// The user agent string itself is the cache key (ordinal comparison), so a cache hit does not allocate. + /// Telemetry checks use a volatile flag to ensure zero overhead when disabled; cache size tracking + /// (via and ) + /// is skipped entirely if the size metric is not enabled. /// public HttpUserAgentInformation Parse(string userAgent) { - CacheKey key = GetKey(userAgent); - - if (!HttpUserAgentParserMemoryCacheTelemetry.IsEnabled) - { - return ParseWithoutTelemetry(key); - } - - if (_memoryCache.TryGetValue(key, out HttpUserAgentInformation cached)) - { - HttpUserAgentParserMemoryCacheTelemetry.CacheHit(); - return cached; - } - - return _memoryCache.GetOrCreate(key, static entry => + if (_memoryCache.TryGetValue(userAgent, out HttpUserAgentInformation cached)) { - CacheKey key = (entry.Key as CacheKey)!; - entry.SlidingExpiration = key.Options.CacheEntryOptions.SlidingExpiration; - entry.SetSize(1); - - // Miss path. Note: Like other cache implementations, races can happen; counters are best-effort. - HttpUserAgentParserMemoryCacheTelemetry.CacheMiss(); - - if (HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled) + if (HttpUserAgentParserMemoryCacheTelemetry.IsEnabled) { - // Optimization: Avoid Interlocked overhead and delegate allocation if telemetry is disabled. - HttpUserAgentParserMemoryCacheTelemetry.CacheSizeIncrement(); - entry.RegisterPostEvictionCallback(static (_, _, _, _) => HttpUserAgentParserMemoryCacheTelemetry.CacheSizeDecrement()); + HttpUserAgentParserMemoryCacheTelemetry.CacheHit(); } - return HttpUserAgentParser.Parse(key.UserAgent); - }); - } - - /// - /// Parses the user agent string using the memory cache without emitting telemetry. - /// - private HttpUserAgentInformation ParseWithoutTelemetry(CacheKey key) - { - return _memoryCache.GetOrCreate(key, static entry => - { - CacheKey key = (entry.Key as CacheKey)!; - - entry.SlidingExpiration = key.Options.CacheEntryOptions.SlidingExpiration; - entry.SetSize(1); - - return HttpUserAgentParser.Parse(key.UserAgent); - }); - } - - /// - /// Thread-local reusable cache key instance to avoid per-call allocations. - /// - /// - /// Marked as to ensure thread safety without locking. - /// - [ThreadStatic] - private static CacheKey? s_tKey; - - /// - /// Gets a cache key instance initialized for the specified user agent. - /// - /// - /// Reuses a thread-local instance to minimize allocations. The returned instance - /// must not be stored or shared across threads. - /// - private CacheKey GetKey(string userAgent) - { - CacheKey key = s_tKey ??= new CacheKey(); - - key.UserAgent = userAgent; - key.Options = _options; + return cached; + } - return key; + return ParseAndCache(userAgent); } /// - /// Cache key used for memory-cached HTTP User-Agent parsing. + /// Parses the user agent and adds the result to the cache (miss path). /// /// - /// Implements as required by IMemoryCache - /// to ensure correct key comparison semantics. + /// Like other cache implementations, concurrent misses of the same user agent may parse it more than once; the last result is kept. /// - internal sealed class CacheKey : IEquatable // required for IMemoryCache + private HttpUserAgentInformation ParseAndCache(string userAgent) { - /// - /// Gets or sets the raw User-Agent string. - /// - public string UserAgent { get; set; } = null!; + HttpUserAgentInformation information = HttpUserAgentParser.Parse(userAgent); - /// - /// Gets or sets the cache configuration options associated with this key. - /// - public HttpUserAgentParserMemoryCachedProviderOptions Options { get; set; } = null!; + using ICacheEntry entry = _memoryCache.CreateEntry(userAgent); + entry.SlidingExpiration = _options.CacheEntryOptions.SlidingExpiration; + entry.Size = 1; + entry.Value = information; - /// - /// Determines equality based on the User-Agent string, ignoring case. - /// - public bool Equals(CacheKey? other) - => string.Equals(UserAgent, other?.UserAgent, StringComparison.OrdinalIgnoreCase); + if (HttpUserAgentParserMemoryCacheTelemetry.IsEnabled) + { + HttpUserAgentParserMemoryCacheTelemetry.CacheMiss(); - /// - public override bool Equals(object? obj) - => Equals(obj as CacheKey); + if (HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled) + { + // The eviction callback also runs if the cache rejects the entry because of its size limit. + HttpUserAgentParserMemoryCacheTelemetry.CacheSizeIncrement(); + entry.RegisterPostEvictionCallback(static (_, _, _, _) => HttpUserAgentParserMemoryCacheTelemetry.CacheSizeDecrement()); + } + } - /// - /// Returns a hash code based on the User-Agent string. - /// - /// - /// Uses ordinal comparison for performance and consistency with the cache. - /// - public override int GetHashCode() - => UserAgent.GetHashCode(StringComparison.Ordinal); + return information; } } diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 66c7fc6..588b307 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -11,7 +11,8 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// /// /// All instruments of a meter are created before they become visible to the provider, so concurrent -/// registrations never observe a partially initialized state. The last registered meter is used. +/// registrations never observe a partially initialized state. The last registered meter is used; a replaced meter +/// no longer reports the cache size. /// internal static class HttpUserAgentParserMemoryCacheMeters { @@ -40,26 +41,27 @@ public static string GetMeterName(string? meterPrefix) private static Meter? s_defaultMeter; private static Instruments? s_instruments; + /// + /// The instruments of every registered meter; a meter registered again reuses its instruments. + /// + private static readonly ConditionalWeakTable s_instrumentsByMeter = new(); + public static bool IsEnabled => Volatile.Read(ref s_instruments) is not null; /// /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// /// - /// Registering the meter that is already in use has no effect; another meter replaces it. + /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. /// public static void Enable(Meter? meter = null) { lock (s_lock) { meter ??= s_defaultMeter ??= new Meter(MeterName); - if (ReferenceEquals(s_instruments?.Meter, meter)) - { - return; - } - // Publish the instruments only after all of them exist. - Volatile.Write(ref s_instruments, new Instruments(meter)); + // Instruments are created once per meter and published only after all of them exist. + Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); } } @@ -75,30 +77,46 @@ public static void ResetForTests() { Volatile.Write(ref s_instruments, null); s_defaultMeter = null; + s_instrumentsByMeter.Clear(); } } /// /// The instruments of one meter. /// - private sealed class Instruments(Meter meter) + private sealed class Instruments { - public Meter Meter { get; } = meter; - - public Counter CacheHit { get; } = meter.CreateCounter( - name: "cache.hit", - unit: "{call}", - description: "Cache hit"); - - public Counter CacheMiss { get; } = meter.CreateCounter( - name: "cache.miss", - unit: "{call}", - description: "Cache miss"); - - public ObservableGauge CacheSize { get; } = meter.CreateObservableGauge( - name: "cache.size", - observeValue: static () => HttpUserAgentParserMemoryCacheTelemetryState.CacheSize, - unit: "{entry}", - description: "Cache size"); + public Instruments(Meter meter) + { + CacheHit = meter.CreateCounter( + name: "cache.hit", + unit: "{call}", + description: "Cache hit"); + + CacheMiss = meter.CreateCounter( + name: "cache.miss", + unit: "{call}", + description: "Cache miss"); + + CacheSize = meter.CreateObservableGauge( + name: "cache.size", + observeValues: ObserveCacheSize, + unit: "{entry}", + description: "Cache size"); + } + + public Counter CacheHit { get; } + + public Counter CacheMiss { get; } + + public ObservableGauge CacheSize { get; } + + /// + /// Reports the cache size only while these instruments are in use, so a replaced meter does not report it as well. + /// + private IEnumerable> ObserveCacheSize() + => ReferenceEquals(Volatile.Read(ref s_instruments), this) + ? [new Measurement(HttpUserAgentParserMemoryCacheTelemetryState.CacheSize)] + : []; } } diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/readme.md index 57aca91..0036c1e 100644 --- a/src/HttpUserAgentParser.MemoryCache/readme.md +++ b/src/HttpUserAgentParser.MemoryCache/readme.md @@ -100,7 +100,7 @@ services ``` Pass your own `Meter` to `WithMemoryCacheMeterTelemetry(meter)` to record to it. A later registration with another meter -replaces the previous one; registering the meter in use again has no effect. +replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. ### Meter + instruments diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index daad19a..38df1b0 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -116,41 +116,94 @@ public static (string Name, string? Version)? GetBrowser(string userAgent) // Rules are evaluated in priority order (specific browsers before the browsers their user agents contain). foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) { - if (!TryIndexOf(ua, detectToken, out int detectIndex)) + if (TryIndexOf(ua, detectToken, out int detectIndex) + && TryReadBrowserVersion(ua, detectToken, detectIndex, versionToken, out Range version)) { - continue; + return (name, ua[version].ToString()); } - int versionSearchStart = detectIndex + detectToken.Length; + // Token not found or without version: try the next rule + } - if (versionToken is null) - { - // For rules without a specific version token, ensure pattern Token/ - if (versionSearchStart >= ua.Length || ua[versionSearchStart] != '/') - { - // Likely a misspelling or partial token (e.g., Edgg, Oprea, Chromee) - continue; - } - } - else if (TryIndexOf(ua, versionToken, out int versionTokenIndex)) + return null; + } + + /// + /// Reads the version of a browser rule whose detect token occurs at (first occurrence). + /// + private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectToken, int detectIndex, string? versionToken, out Range version) + { + if (versionToken is null) + { + // Pattern Token/; every occurrence of the token may carry the version ("Chrome/ Chrome/131.0"). + // Without '/' the token is likely a misspelling or part of another word (e.g. Edgg, Oprea, Chromee). + return TryReadVersionAfter(ua, detectToken, detectIndex, tokenStartOnly: false, slashRequired: true, out version); + } + + // A separate version token (e.g. Safari "Version/") only counts at the start of a token: + // in "VendorVersion/120.0" the version belongs to another product. + bool sameToken = string.Equals(detectToken, versionToken, StringComparison.Ordinal); + int versionIndex = sameToken ? detectIndex : ua.IndexOf(versionToken, StringComparison.OrdinalIgnoreCase); + while (versionIndex >= 0 && !IsTokenStart(ua, versionIndex)) + { + versionIndex = IndexOfNext(ua, versionToken, versionIndex); + } + + if (versionIndex >= 0) + { + return TryReadVersionAfter(ua, versionToken, versionIndex, tokenStartOnly: true, slashRequired: false, out version); + } + + // Without version token the version follows the detect token (e.g. "Opera/9.80"). + if (sameToken) + { + version = default; + return false; + } + + return TryReadVersionAfter(ua, detectToken, detectIndex, tokenStartOnly: false, slashRequired: false, out version); + } + + /// + /// Reads the version of the first occurrence of , starting at , that has one. + /// + private static bool TryReadVersionAfter(ReadOnlySpan ua, string token, int index, bool tokenStartOnly, bool slashRequired, out Range version) + { + for (; index >= 0; index = IndexOfNext(ua, token, index)) + { + int end = index + token.Length; + if ((tokenStartOnly && !IsTokenStart(ua, index)) + || (slashRequired && (end >= ua.Length || ua[end] != '/'))) { - // Version token may differ (e.g., Safari uses "Version/") - versionSearchStart = versionTokenIndex + versionToken.Length; + continue; } - // Otherwise (version token not found) the version is searched after the detect token. - ReadOnlySpan search = ua[versionSearchStart..]; - if (TryExtractVersion(search, out Range range)) + if (TryExtractVersion(ua[end..], out Range range)) { - return (name, search[range].ToString()); + version = new Range(end + range.Start.Value, end + range.End.Value); + return true; } - - // If we didn't find a version for this rule, try next rule } - return null; + version = default; + return false; + } + + /// + /// Returns the index of the next occurrence of after , or -1. + /// + private static int IndexOfNext(ReadOnlySpan ua, string token, int index) + { + int next = ua[(index + 1)..].IndexOf(token, StringComparison.OrdinalIgnoreCase); + return next < 0 ? -1 : index + 1 + next; } + /// + /// Returns whether a token at starts a token of its own, i.e. does not continue a word. + /// + private static bool IsTokenStart(ReadOnlySpan ua, int index) + => index == 0 || !char.IsAsciiLetterOrDigit(ua[index - 1]); + /// /// returns true if browser was found /// diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index b71e9f9..e4b2b98 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -11,7 +11,8 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// /// /// All instruments of a meter are created before they become visible to the parser, so concurrent -/// registrations never observe a partially initialized state. The last registered meter is used. +/// registrations never observe a partially initialized state. The last registered meter is used; a replaced meter +/// no longer reports the cache size. /// internal static class HttpUserAgentParserMeters { @@ -46,6 +47,11 @@ public static string GetMeterName(string? meterPrefix) private static Meter? s_defaultMeter; private static Instruments? s_instruments; + /// + /// The instruments of every registered meter; a meter registered again reuses its instruments. + /// + private static readonly ConditionalWeakTable s_instrumentsByMeter = new(); + /// /// Gets whether meters have been initialized. /// @@ -60,20 +66,16 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// /// - /// Registering the meter that is already in use has no effect; another meter replaces it. + /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. /// public static void Enable(Meter? meter = null) { lock (s_lock) { meter ??= s_defaultMeter ??= new Meter(MeterName); - if (ReferenceEquals(s_instruments?.Meter, meter)) - { - return; - } - // Publish the instruments only after all of them exist. - Volatile.Write(ref s_instruments, new Instruments(meter)); + // Instruments are created once per meter and published only after all of them exist. + Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); } } @@ -110,40 +112,60 @@ public static void ResetForTests() { Volatile.Write(ref s_instruments, null); s_defaultMeter = null; + s_instrumentsByMeter.Clear(); } } /// /// The instruments of one meter. /// - private sealed class Instruments(Meter meter) + private sealed class Instruments { - public Meter Meter { get; } = meter; - - public Counter ParseRequests { get; } = meter.CreateCounter( - name: "parse.requests", - unit: "{call}", - description: "User-Agent parse requests"); - - public Histogram ParseDuration { get; } = meter.CreateHistogram( - name: "parse.duration", - unit: "s", - description: "Parse duration"); - - public Counter CacheHit { get; } = meter.CreateCounter( - name: "cache.hit", - unit: "{call}", - description: "Cache hit"); - - public Counter CacheMiss { get; } = meter.CreateCounter( - name: "cache.miss", - unit: "{call}", - description: "Cache miss"); - - public ObservableGauge CacheSize { get; } = meter.CreateObservableGauge( - name: "cache.size", - observeValue: static () => HttpUserAgentParserTelemetryState.ConcurrentCacheSize, - unit: "{entry}", - description: "Cache size"); + public Instruments(Meter meter) + { + ParseRequests = meter.CreateCounter( + name: "parse.requests", + unit: "{call}", + description: "User-Agent parse requests"); + + ParseDuration = meter.CreateHistogram( + name: "parse.duration", + unit: "s", + description: "Parse duration"); + + CacheHit = meter.CreateCounter( + name: "cache.hit", + unit: "{call}", + description: "Cache hit"); + + CacheMiss = meter.CreateCounter( + name: "cache.miss", + unit: "{call}", + description: "Cache miss"); + + CacheSize = meter.CreateObservableGauge( + name: "cache.size", + observeValues: ObserveCacheSize, + unit: "{entry}", + description: "Cache size"); + } + + public Counter ParseRequests { get; } + + public Histogram ParseDuration { get; } + + public Counter CacheHit { get; } + + public Counter CacheMiss { get; } + + public ObservableGauge CacheSize { get; } + + /// + /// Reports the cache size only while these instruments are in use, so a replaced meter does not report it as well. + /// + private IEnumerable> ObserveCacheSize() + => ReferenceEquals(Volatile.Read(ref s_instruments), this) + ? [new Measurement(HttpUserAgentParserTelemetryState.ConcurrentCacheSize)] + : []; } } diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index 543e5d8..e4e796d 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -107,7 +107,7 @@ services ``` Pass your own `Meter` to `WithMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the -previous one; registering the meter in use again has no effect. +previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. ### Meter + instruments diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs index 2f405b4..d2f3a38 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs @@ -47,6 +47,25 @@ public void Meters_Use_The_Last_Registered_Meter() Assert.Equal(new[] { "user_agent.missing" }, secondListener.InstrumentNames, StringComparer.Ordinal); } + [Fact] + public void A_Meter_Registered_Again_Reuses_Its_Instruments() + { + using Meter first = new("test.aspnetcore.again.first"); + using Meter second = new("test.aspnetcore.again.second"); + int published = 0; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => published += instrument.Meter == first ? 1 : 0, + }; + listener.Start(); + + HttpUserAgentParserAspNetCoreMeters.Enable(first); + HttpUserAgentParserAspNetCoreMeters.Enable(second); + HttpUserAgentParserAspNetCoreMeters.Enable(first); + + Assert.Equal(2, published); // user_agent.present and user_agent.missing, once + } + [Fact] public void EventSource_Ignores_Calls_Without_Listener() { diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs index 45e9753..f26f865 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs @@ -28,4 +28,40 @@ public void Provider_Caches_Entries_And_Resolves_Twice() Assert.Equal(a.Name, b.Name); Assert.Equal(a.Version, b.Version); } + + [Fact] + public void Entries_Of_One_Thread_Are_Hits_On_Another_Thread() + { + HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + + RunOnNewThread(() => + { + provider.Parse("Chrome/17"); + provider.Parse("Firefox/12"); // must not change the key of the cached Chrome entry + }); + + HttpUserAgentInformation chrome = default; + RunOnNewThread(() => chrome = provider.Parse("Chrome/17")); + + Assert.Equal(2, provider.CacheEntryCount); + Assert.Equal(("Chrome", "17"), (chrome.Name, chrome.Version)); + } + + [Fact] + public void Keys_Are_Case_Sensitive() + { + HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + + // The result contains the original user agent, so a differently cased user agent is a different entry. + Assert.Equal("Chrome/17", provider.Parse("Chrome/17").UserAgent); + Assert.Equal("CHROME/17", provider.Parse("CHROME/17").UserAgent); + Assert.Equal(2, provider.CacheEntryCount); + } + + private static void RunOnNewThread(Action action) + { + Thread thread = new(() => action()); + thread.Start(); + thread.Join(); + } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs deleted file mode 100644 index 899b4fc..0000000 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderCacheKeyTests.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright © https://myCSharp.de - all rights reserved - -using Xunit; - -namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; - -public class HttpUserAgentParserMemoryCachedProviderCacheKeyTests -{ - private static HttpUserAgentParserMemoryCachedProvider.CacheKey Key(string userAgent) - => new() { UserAgent = userAgent, Options = new HttpUserAgentParserMemoryCachedProviderOptions() }; - - [Fact] - public void Equals_Ignores_Case() - { - Assert.True(Key("Mozilla/5.0 Chrome").Equals(Key("mozilla/5.0 chrome"))); - Assert.True(Key("Mozilla/5.0 Chrome").Equals((object)Key("Mozilla/5.0 Chrome"))); - } - - [Fact] - public void Not_Equals_Other_User_Agent_Null_Or_Other_Type() - { - HttpUserAgentParserMemoryCachedProvider.CacheKey key = Key("Mozilla/5.0 Chrome"); - - Assert.False(key.Equals(Key("Mozilla/5.0 Firefox"))); - Assert.False(key.Equals(null)); - Assert.False(key.Equals((object?)null)); - Assert.False(key.Equals("Mozilla/5.0 Chrome")); - } - - [Fact] - public void GetHashCode_Is_Ordinal() - { - Assert.Equal(Key("Mozilla/5.0 Chrome").GetHashCode(), Key("Mozilla/5.0 Chrome").GetHashCode()); - Assert.Equal("Mozilla/5.0 Chrome".GetHashCode(StringComparison.Ordinal), Key("Mozilla/5.0 Chrome").GetHashCode()); - } -} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs index 8a9446a..979f9bc 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs @@ -47,6 +47,30 @@ public void Meters_Use_The_Last_Registered_Meter() Assert.Equal(new[] { "cache.miss" }, secondListener.InstrumentNames, StringComparer.Ordinal); } + [Fact] + public void Only_The_Meter_In_Use_Reports_The_Cache_Size() + { + using Meter first = new("test.memorycache.size.first"); + using Meter second = new("test.memorycache.size.second"); + using MeterTestListener firstListener = new("test.memorycache.size.first"); + using MeterTestListener secondListener = new("test.memorycache.size.second"); + + HttpUserAgentParserMemoryCacheMeters.Enable(first); + HttpUserAgentParserMemoryCacheMeters.Enable(second); + firstListener.RecordObservableInstruments(); + secondListener.RecordObservableInstruments(); + + Assert.Empty(firstListener.InstrumentNames); + Assert.Equal(new[] { "cache.size" }, secondListener.InstrumentNames, StringComparer.Ordinal); + + HttpUserAgentParserMemoryCacheMeters.Enable(first); // reuses the instruments of the first meter + firstListener.RecordObservableInstruments(); + secondListener.RecordObservableInstruments(); + + Assert.Equal(new[] { "cache.size" }, firstListener.InstrumentNames, StringComparer.Ordinal); + Assert.Equal(new[] { "cache.size" }, secondListener.InstrumentNames, StringComparer.Ordinal); + } + [Fact] public void EventSource_Ignores_Calls_Without_Listener() { diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 605ccd7..b8e6abf 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -307,6 +307,13 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() [InlineData("SamsungBrowser/ Chrome/131.0.0.0 Safari/537.36", "Chrome", "131.0.0.0")] [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)", "Internet Explorer", "8.0")] [InlineData("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0")] + // A later occurrence of the same token carries the version + [InlineData("Chrome/ Chrome/131.0", "Chrome", "131.0")] + [InlineData("Mozilla/5.0 Version/ Mobile Version/17.0 Safari/604.1", "Safari", "17.0")] + // A version token inside another word belongs to another product + [InlineData("Opera/9.80 VendorVersion/120.0", "Opera", "9.80")] + [InlineData("Mozilla/5.0 Version/ XVersion/1.0 Version/17.0 Safari/604.1", "Safari", "17.0")] + [InlineData("Version/17.0 Safari/604.1", "Safari", "17.0")] public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAgent, string expectedName, string expectedVersion) { (string Name, string? Version)? browser = HttpUserAgentParser.GetBrowser(userAgent); @@ -318,6 +325,8 @@ public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAge [InlineData("Chrome/ Safari/537.36")] [InlineData("Mozilla/5.0 (iPhone) Version/ Mobile/15E148 Safari/604.1")] [InlineData("Mozilla/5.0 Firefox/(X11) 120")] + [InlineData("Mozilla/5.0 VendorVersion/120.0 Safari/604.1")] + [InlineData("Mozilla/5.0 Chrome/ Chrome")] public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userAgent) { Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs index 738d7ce..9d641af 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -74,6 +74,30 @@ public void Meters_Use_The_Last_Registered_Meter() Assert.Single(secondListener.InstrumentNames, static name => string.Equals(name, "parse.requests", StringComparison.Ordinal)); } + [Fact] + public void Only_The_Meter_In_Use_Reports_The_Cache_Size() + { + using Meter first = new("test.size.first"); + using Meter second = new("test.size.second"); + using MeterTestListener firstListener = new("test.size.first"); + using MeterTestListener secondListener = new("test.size.second"); + + HttpUserAgentParserTelemetry.EnableMeters(first); + HttpUserAgentParserTelemetry.EnableMeters(second); + firstListener.RecordObservableInstruments(); + secondListener.RecordObservableInstruments(); + + Assert.Empty(firstListener.InstrumentNames); + Assert.Equal(new[] { "cache.size" }, secondListener.InstrumentNames, StringComparer.Ordinal); + + HttpUserAgentParserTelemetry.EnableMeters(first); // reuses the instruments of the first meter + firstListener.RecordObservableInstruments(); + secondListener.RecordObservableInstruments(); + + Assert.Equal(new[] { "cache.size" }, firstListener.InstrumentNames, StringComparer.Ordinal); + Assert.Equal(new[] { "cache.size" }, secondListener.InstrumentNames, StringComparer.Ordinal); + } + [Fact] public void Registering_The_Same_Meter_Again_Keeps_The_Instruments() { From 9138a2046f09261a2c8678f226d7530eb883fcdb Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 18:14:36 +0100 Subject: [PATCH 06/41] fix: token boundaries, linear version search, cache size and own meters - Browser version: later occurrences of a browser token only count at the start of a token ("ChromeHelper/1 MyChrome/2.0 Firefox/126.0" is Firefox 126.0); the first occurrence may still continue a word (HeadlessChrome). A token starts at the beginning or after a space, tab, ';', '(', ')' or ',' - the delimiters that end a product token - so "Vendor-Version/120.0" is no version token either. - Version search: continue behind the product token examined before, so the time grows linearly with the length of the user agent (1,000,000 characters of "Chrome/a": 1.7 s before, 2 ms now). - Cache size: providers register themselves weakly when created; the cache.size gauges and cache-size counters sum the live caches when observed. Entries cached before telemetry was enabled are counted, several core providers no longer overwrite each other, and nothing is counted on the parse path anymore. - Meters: meters the packages create (default, prefix variants) are created once per name and disposed when replaced; caller meters are never disposed. Repeated prefix registrations keep one meter. - ConcurrentDictionary cache: ordinal keys like the MemoryCache. --- README.md | 34 +++---- ...encyInjectionOptionsTelemetryExtensions.cs | 3 +- .../HttpUserAgentParserAspNetCoreMeters.cs | 44 ++++++++- .../HttpUserAgentParserAspNetCoreTelemetry.cs | 9 ++ src/HttpUserAgentParser.AspNetCore/readme.md | 1 + ...encyInjectionOptionsTelemetryExtensions.cs | 3 +- ...HttpUserAgentParserMemoryCachedProvider.cs | 35 ++++---- .../HttpUserAgentParserMemoryCacheMeters.cs | 44 ++++++++- ...HttpUserAgentParserMemoryCacheTelemetry.cs | 53 ++--------- ...serAgentParserMemoryCacheTelemetryState.cs | 45 +++++----- src/HttpUserAgentParser.MemoryCache/readme.md | 5 +- ...encyInjectionOptionsTelemetryExtensions.cs | 3 +- .../HttpUserAgentParser.cs | 90 ++++++++++--------- .../HttpUserAgentParserCachedProvider.cs | 27 +++--- .../Telemetry/HttpUserAgentParserMeters.cs | 44 ++++++++- .../Telemetry/HttpUserAgentParserTelemetry.cs | 32 ++----- .../HttpUserAgentParserTelemetryState.cs | 42 +++++---- src/HttpUserAgentParser/readme.md | 6 +- ...entParserAspNetCoreMetersTelemetryTests.cs | 53 +++++++++++ ...ntParserMemoryCacheMetersTelemetryTests.cs | 53 +++++++++++ ...arserMemoryCacheTelemetryInternalsTests.cs | 11 +-- ...gentParserMemoryCacheTelemetryPathTests.cs | 40 ++++++--- .../HttpUserAgentParserTests.cs | 22 +++++ .../HttpUserAgentParserCachedProviderTests.cs | 12 +++ ...HttpUserAgentParserMetersTelemetryTests.cs | 53 +++++++++++ ...pUserAgentParserTelemetryInternalsTests.cs | 16 ++-- .../HttpUserAgentParserTelemetryPathTests.cs | 38 ++++++-- 27 files changed, 572 insertions(+), 246 deletions(-) diff --git a/README.md b/README.md index 82376e6..0e2bb3c 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. Clients choose the `User-Agent` header freely, so use it only for a known, limited set of user agents, e.g. in tests. For web applications, use the `IMemoryCache` implementation, which limits the number of entries and expires them. +This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. Both caches use the exact user agent string as key (ordinal), because the result contains the user agent. Clients choose the `User-Agent` header freely, so use it only for a known, limited set of user agents, e.g. in tests. For web applications, use the `IMemoryCache` implementation, which limits the number of entries and expires them. The package [MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache) is required to use the IMemoryCache. This enables the registration of the `IMemoryCache` implementation: @@ -140,7 +140,7 @@ If you only need the raw header value, use `httpContext.GetUserAgentString()`. 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) 4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Yandex Browser, UC Browser and others -In every list the first matching entry wins. A browser version is read from the browser's own product token (`Chrome/131.0.0.0`); a separate version token such as Safari's `Version/` only counts at the start of a token, so `VendorVersion/1.0` is ignored. If a token has no version, the next occurrence of the token and then the next rule is checked. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome; iPadOS sends the macOS user agent by default. +In every list the first matching entry wins. A browser version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next space, tab, `;`, `(`, `)` or `,`. A token starts at the beginning or after one of these characters. A separate version token such as Safari's `Version/` only counts at the start of a token, so `VendorVersion/1.0` and `Vendor-Version/1.0` are ignored. If the browser token has no version, later occurrences that start a token are checked, then the next rule. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome; iPadOS sends the macOS user agent by default. ### `HttpUserAgentStatics` and regular expressions @@ -220,13 +220,13 @@ Core (`MyCSharp.HttpUserAgentParser`) - `parse-duration` (s) - `cache-hit` (`HttpUserAgentParserCachedProvider`) - `cache-miss` (`HttpUserAgentParserCachedProvider`) -- `cache-size` (`HttpUserAgentParserCachedProvider`) +- `cache-size` (`HttpUserAgentParserCachedProvider`): the entries of all live providers of the package, including entries cached before telemetry was enabled MemoryCache (`MyCSharp.HttpUserAgentParser.MemoryCache`) - `cache-hit` - `cache-miss` -- `cache-size` +- `cache-size`: the entries of all live providers of the package, including entries cached before telemetry was enabled ASP.NET Core (`MyCSharp.HttpUserAgentParser.AspNetCore`) @@ -284,7 +284,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. +Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The package creates its own meters (without argument or with a prefix) once per name and disposes them when they are replaced; meters you pass in are never disposed. ### Meter names and instruments @@ -294,13 +294,13 @@ Core meter (default: `mycsharp.http_user_agent_parser`) - `parse.duration` (histogram, `s`) - `cache.hit` (counter, `{call}`) - `cache.miss` (counter, `{call}`) -- `cache.size` (observable gauge, `{entry}`) +- `cache.size` (observable gauge, `{entry}`): the entries of all live providers of the package, including entries cached before telemetry was enabled MemoryCache meter (default: `mycsharp.http_user_agent_parser.memorycache`) - `cache.hit` (counter, `{call}`) - `cache.miss` (counter, `{call}`) -- `cache.size` (observable gauge, `{entry}`) +- `cache.size` (observable gauge, `{entry}`): the entries of all live providers of the package, including entries cached before telemetry was enabled ASP.NET Core meter (default: `mycsharp.http_user_agent_parser.aspnetcore`) @@ -456,9 +456,9 @@ Mixed workload: the catalog user agents parsed in a loop, mean time per user age | Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | .NET 11.0.0 | Allocated | | --- | ---: | ---: | ---: | ---: | ---: | -| 44 browser user agents | 751.2 ns | 359.9 ns | 358.0 ns | 291.3 ns | 38 B | -| 48 crawler user agents | 370.5 ns | 187.1 ns | 175.2 ns | 164.4 ns | 0 B | -| All 96 user agents | 586.1 ns | 290.4 ns | 276.2 ns | 243.6 ns | 18 B | +| 44 browser user agents | 758.5 ns | 372.0 ns | 353.1 ns | 302.1 ns | 38 B | +| 48 crawler user agents | 369.9 ns | 192.6 ns | 167.4 ns | 159.4 ns | 0 B | +| All 96 user agents | 589.0 ns | 291.1 ns | 285.7 ns | 240.7 ns | 18 B | .NET 8 has no `SearchValues`; the parser checks the tokens one by one there. @@ -466,13 +466,13 @@ Single user agents on .NET 11: | User agent | Mean | Allocated | | --- | ---: | ---: | -| Chrome on Windows | 249.4 ns | 40 B | -| Firefox on Linux | 352.4 ns | 32 B | -| Chrome on Android | 267.1 ns | 40 B | -| Safari on iPhone | 295.2 ns | 32 B | -| Applebot | 182.5 ns | 0 B | -| Googlebot | 9.45 ns | 0 B | -| Unknown client | 404.8 ns | 0 B | +| Chrome on Windows | 255.8 ns | 40 B | +| Firefox on Linux | 352.8 ns | 32 B | +| Chrome on Android | 282.1 ns | 40 B | +| Safari on iPhone | 302.5 ns | 32 B | +| Applebot | 192.0 ns | 0 B | +| Googlebot | 9.54 ns | 0 B | +| Unknown client | 421.7 ns | 0 B | Startup in a new .NET 11 process (median of 7 runs): diff --git a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs index 9e8b54a..9fa7ea4 100644 --- a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs +++ b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs @@ -42,8 +42,7 @@ public static HttpUserAgentParserDependencyInjectionOptions WithAspNetCoreMeterT this HttpUserAgentParserDependencyInjectionOptions options, string meterPrefix) { - Meter meter = new(HttpUserAgentParserAspNetCoreMeters.GetMeterName(meterPrefix)); - HttpUserAgentParserAspNetCoreTelemetry.EnableMeters(meter); + HttpUserAgentParserAspNetCoreTelemetry.EnableMetersWithName(HttpUserAgentParserAspNetCoreMeters.GetMeterName(meterPrefix)); return options; } } diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 607d52a..82196c5 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -43,7 +43,11 @@ public static string GetMeterName(string? meterPrefix) private static readonly object s_lock = new(); #endif - private static Meter? s_defaultMeter; + /// + /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. + /// + private static Meter? s_ownedMeter; + private static Instruments? s_instruments; /// @@ -61,14 +65,45 @@ public static string GetMeterName(string? meterPrefix) /// /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. /// - public static void Enable(Meter? meter = null) + public static void Enable(Meter? meter = null) => Use(meter, MeterName); + + /// + /// Creates the metric instruments on a meter named that this class creates and owns. + /// + /// + /// An owned meter is created once per name; it is disposed when another meter replaces it. + /// + public static void EnableOwnedMeter(string meterName) => Use(null, meterName); + + /// + /// Uses or, if null, an owned meter named . + /// + private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - meter ??= s_defaultMeter ??= new Meter(MeterName); + Meter? previousOwnedMeter = s_ownedMeter; + if (meter is null) + { + meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) + ? previousOwnedMeter + : new Meter(ownedMeterName); + s_ownedMeter = meter; + } + else + { + s_ownedMeter = null; + } // Instruments are created once per meter and published only after all of them exist. Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); + + // A replaced owned meter is no longer used: dispose it, so repeated registrations do not keep meters alive. + // Meters passed in by the caller are never disposed. + if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) + { + previousOwnedMeter.Dispose(); + } } } @@ -94,7 +129,8 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - s_defaultMeter = null; + s_ownedMeter?.Dispose(); + s_ownedMeter = null; s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs index b893760..15c437e 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs @@ -64,6 +64,15 @@ public static void EnableMeters(Meter? meter = null) Interlocked.Or(ref s_enabledFlags, MetersFlag); } + /// + /// Enables native System.Diagnostics.Metrics telemetry with a meter named that the package owns. + /// + public static void EnableMetersWithName(string meterName) + { + HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter(meterName); + Interlocked.Or(ref s_enabledFlags, MetersFlag); + } + /// /// Records telemetry indicating that a User-Agent header was present. /// diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index 07b7cf4..c99966a 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -99,6 +99,7 @@ services Pass your own `Meter` to `WithAspNetCoreMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. +Meters the package creates itself (without argument or with a prefix) are created once per name and disposed when they are replaced. ### Meter + instruments diff --git a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs index 6b31060..4b86b6f 100644 --- a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs +++ b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs @@ -42,8 +42,7 @@ public static HttpUserAgentParserDependencyInjectionOptions WithMemoryCacheMeter this HttpUserAgentParserDependencyInjectionOptions options, string meterPrefix) { - Meter meter = new(HttpUserAgentParserMemoryCacheMeters.GetMeterName(meterPrefix)); - HttpUserAgentParserMemoryCacheTelemetry.EnableMeters(meter); + HttpUserAgentParserMemoryCacheTelemetry.EnableMetersWithName(HttpUserAgentParserMemoryCacheMeters.GetMeterName(meterPrefix)); return options; } } diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index 5f6dccc..503a82b 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -8,19 +8,30 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache; /// /// -/// Creates a new instance of . +/// that caches the results in an . /// -/// The options used to set expiration and size limit -public class HttpUserAgentParserMemoryCachedProvider( - HttpUserAgentParserMemoryCachedProviderOptions options) : IHttpUserAgentParserProvider +public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvider { /// /// The name of the Meter used for metrics. /// public const string MeterName = "mycsharp.http_user_agent_parser.memorycache"; - private readonly Microsoft.Extensions.Caching.Memory.MemoryCache _memoryCache = new(options.CacheOptions); - private readonly HttpUserAgentParserMemoryCachedProviderOptions _options = options; + private readonly Microsoft.Extensions.Caching.Memory.MemoryCache _memoryCache; + private readonly HttpUserAgentParserMemoryCachedProviderOptions _options; + + /// + /// Creates a new instance of . + /// + /// The options used to set expiration and size limit + public HttpUserAgentParserMemoryCachedProvider(HttpUserAgentParserMemoryCachedProviderOptions options) + { + _memoryCache = new(options.CacheOptions); + _options = options; + + // Known independent of telemetry, so the cache size also includes entries cached before telemetry was enabled. + HttpUserAgentParserMemoryCacheTelemetryState.Register(this); + } /// /// Number of cached user agents. @@ -30,9 +41,8 @@ public class HttpUserAgentParserMemoryCachedProvider( /// /// /// The user agent string itself is the cache key (ordinal comparison), so a cache hit does not allocate. - /// Telemetry checks use a volatile flag to ensure zero overhead when disabled; cache size tracking - /// (via and ) - /// is skipped entirely if the size metric is not enabled. + /// Telemetry checks use a volatile flag to ensure zero overhead when disabled; the cache size is counted only + /// when a cache size instrument is observed. /// public HttpUserAgentInformation Parse(string userAgent) { @@ -67,13 +77,6 @@ private HttpUserAgentInformation ParseAndCache(string userAgent) if (HttpUserAgentParserMemoryCacheTelemetry.IsEnabled) { HttpUserAgentParserMemoryCacheTelemetry.CacheMiss(); - - if (HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled) - { - // The eviction callback also runs if the cache rejects the entry because of its size limit. - HttpUserAgentParserMemoryCacheTelemetry.CacheSizeIncrement(); - entry.RegisterPostEvictionCallback(static (_, _, _, _) => HttpUserAgentParserMemoryCacheTelemetry.CacheSizeDecrement()); - } } return information; diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 588b307..2b8d083 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -38,7 +38,11 @@ public static string GetMeterName(string? meterPrefix) private static readonly object s_lock = new(); #endif - private static Meter? s_defaultMeter; + /// + /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. + /// + private static Meter? s_ownedMeter; + private static Instruments? s_instruments; /// @@ -54,14 +58,45 @@ public static string GetMeterName(string? meterPrefix) /// /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. /// - public static void Enable(Meter? meter = null) + public static void Enable(Meter? meter = null) => Use(meter, MeterName); + + /// + /// Creates the metric instruments on a meter named that this class creates and owns. + /// + /// + /// An owned meter is created once per name; it is disposed when another meter replaces it. + /// + public static void EnableOwnedMeter(string meterName) => Use(null, meterName); + + /// + /// Uses or, if null, an owned meter named . + /// + private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - meter ??= s_defaultMeter ??= new Meter(MeterName); + Meter? previousOwnedMeter = s_ownedMeter; + if (meter is null) + { + meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) + ? previousOwnedMeter + : new Meter(ownedMeterName); + s_ownedMeter = meter; + } + else + { + s_ownedMeter = null; + } // Instruments are created once per meter and published only after all of them exist. Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); + + // A replaced owned meter is no longer used: dispose it, so repeated registrations do not keep meters alive. + // Meters passed in by the caller are never disposed. + if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) + { + previousOwnedMeter.Dispose(); + } } } @@ -76,7 +111,8 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - s_defaultMeter = null; + s_ownedMeter?.Dispose(); + s_ownedMeter = null; s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs index 4b14f88..ac9a5f2 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs @@ -26,27 +26,6 @@ internal static class HttpUserAgentParserMemoryCacheTelemetry /// public static bool IsEnabled => Volatile.Read(ref s_enabledFlags) != 0; - /// - /// Checks if EventCounters are specifically enabled. - /// - public static bool AreCountersEnabled - => (Volatile.Read(ref s_enabledFlags) & EventCountersFlag) != 0 - && HttpUserAgentParserMemoryCacheEventSource.Log.IsEnabled(); - - /// - /// Checks if Meters are specifically enabled. - /// - public static bool AreMetersEnabled - => (Volatile.Read(ref s_enabledFlags) & MetersFlag) != 0 - && HttpUserAgentParserMemoryCacheMeters.IsEnabled; - - /// - /// Checks if cache size tracking is enabled for either system. - /// This is used to guard expensive operations like .Count or Interlocked updates. - /// - public static bool IsCacheSizeEnabled - => AreCountersEnabled || AreMetersEnabled; - /// /// Enables EventCounter telemetry for the MemoryCache provider. /// @@ -67,6 +46,15 @@ public static void EnableMeters(Meter? meter = null) Interlocked.Or(ref s_enabledFlags, MetersFlag); } + /// + /// Enables native System.Diagnostics.Metrics telemetry with a meter named that the package owns. + /// + public static void EnableMetersWithName(string meterName) + { + HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter(meterName); + Interlocked.Or(ref s_enabledFlags, MetersFlag); + } + /// /// Records a cache hit. /// @@ -103,35 +91,12 @@ public static void CacheMiss() } } - /// - /// Increments the cache size counter. - /// - /// - /// The operation is forwarded to the internal telemetry state and is safe - /// to call concurrently. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheSizeIncrement() - => HttpUserAgentParserMemoryCacheTelemetryState.CacheSizeIncrement(); - - /// - /// Decrements the cache size counter. - /// - /// - /// The operation is forwarded to the internal telemetry state and is safe - /// to call concurrently. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheSizeDecrement() - => HttpUserAgentParserMemoryCacheTelemetryState.CacheSizeDecrement(); - /// /// Resets telemetry state for unit tests. /// public static void ResetForTests() { Volatile.Write(ref s_enabledFlags, 0); - HttpUserAgentParserMemoryCacheTelemetryState.ResetForTests(); HttpUserAgentParserMemoryCacheMeters.ResetForTests(); } } diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs index 689f832..299f67b 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs @@ -1,43 +1,42 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Runtime.CompilerServices; + namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// -/// Holds telemetry state for tracking the size of the HTTP User-Agent parser memory cache. +/// Knows the live instances to report their cache size. /// /// -/// The state is updated with atomic operations, so it is safe in concurrent scenarios. +/// Every provider registers itself when it is created, independent of whether telemetry is enabled, so the +/// reported size includes entries cached before telemetry was enabled. Providers are referenced weakly. /// internal static class HttpUserAgentParserMemoryCacheTelemetryState { - private static long s_cacheSize; - - /// - /// Gets the current number of entries in the memory cache. - /// - /// - /// The value is read atomically to ensure thread safety. - /// - public static long CacheSize => Volatile.Read(ref s_cacheSize); + private static readonly ConditionalWeakTable s_providers = new(); /// - /// Increments the cached entry counter by one. + /// Registers a provider whose entries count towards . /// - /// - /// Uses an atomic operation to remain safe in concurrent scenarios. - /// - public static void CacheSizeIncrement() => Interlocked.Increment(ref s_cacheSize); + public static void Register(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Add(provider, null); /// - /// Decrements the cached entry counter by one. + /// Gets the number of entries of all live memory caches. /// /// - /// Uses an atomic operation to remain safe in concurrent scenarios. + /// Counting only runs when an instrument is observed, never on the parse path. /// - public static void CacheSizeDecrement() => Interlocked.Decrement(ref s_cacheSize); + public static long CacheSize + { + get + { + long size = 0; + foreach (KeyValuePair provider in (IEnumerable>)s_providers) + { + size += provider.Key.CacheEntryCount; + } - /// - /// Resets the cache size for unit tests. - /// - public static void ResetForTests() => Volatile.Write(ref s_cacheSize, 0); + return size; + } + } } diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/readme.md index 0036c1e..0b2b1e2 100644 --- a/src/HttpUserAgentParser.MemoryCache/readme.md +++ b/src/HttpUserAgentParser.MemoryCache/readme.md @@ -70,7 +70,7 @@ EventSource: `MyCSharp.HttpUserAgentParser.MemoryCache` (constant: `HttpUserAgen - `cache-hit` (incrementing) - `cache-miss` (incrementing) -- `cache-size` (polling) +- `cache-size` (polling): the entries of all live providers of the package, including entries cached before telemetry was enabled ### Monitor with dotnet-counters @@ -101,6 +101,7 @@ services Pass your own `Meter` to `WithMemoryCacheMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. +Meters the package creates itself (without argument or with a prefix) are created once per name and disposed when they are replaced. ### Meter + instruments @@ -108,7 +109,7 @@ Meter: `mycsharp.http_user_agent_parser.memorycache` (constant: `HttpUserAgentPa - `cache.hit` (counter) - `cache.miss` (counter) -- `cache.size` (observable gauge) +- `cache.size` (observable gauge): the entries of all live providers of the package, including entries cached before telemetry was enabled ## Export to OpenTelemetry / Application Insights diff --git a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs index a5e6ee8..e1aa007 100644 --- a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs +++ b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs @@ -43,8 +43,7 @@ public static HttpUserAgentParserDependencyInjectionOptions WithMeterTelemetryPr this HttpUserAgentParserDependencyInjectionOptions options, string meterPrefix) { - Meter meter = new(HttpUserAgentParserMeters.GetMeterName(meterPrefix)); - HttpUserAgentParserTelemetry.EnableMeters(meter); + HttpUserAgentParserTelemetry.EnableMetersWithName(HttpUserAgentParserMeters.GetMeterName(meterPrefix)); return options; } } diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 38df1b0..1bdd151 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -129,80 +129,92 @@ public static (string Name, string? Version)? GetBrowser(string userAgent) } /// - /// Reads the version of a browser rule whose detect token occurs at (first occurrence). + /// Reads the version of a browser rule whose detect token occurs first at . /// private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectToken, int detectIndex, string? versionToken, out Range version) { if (versionToken is null) { - // Pattern Token/; every occurrence of the token may carry the version ("Chrome/ Chrome/131.0"). - // Without '/' the token is likely a misspelling or part of another word (e.g. Edgg, Oprea, Chromee). - return TryReadVersionAfter(ua, detectToken, detectIndex, tokenStartOnly: false, slashRequired: true, out version); + // Pattern Token/. Without '/' the token is likely a misspelling or part of another word (e.g. Edgg, Oprea, Chromee). + return TryReadVersionAfter(ua, detectToken, detectIndex, slashRequired: true, out version); } // A separate version token (e.g. Safari "Version/") only counts at the start of a token: - // in "VendorVersion/120.0" the version belongs to another product. + // in "VendorVersion/120.0" or "Vendor-Version/120.0" the version belongs to another product. bool sameToken = string.Equals(detectToken, versionToken, StringComparison.Ordinal); - int versionIndex = sameToken ? detectIndex : ua.IndexOf(versionToken, StringComparison.OrdinalIgnoreCase); - while (versionIndex >= 0 && !IsTokenStart(ua, versionIndex)) - { - versionIndex = IndexOfNext(ua, versionToken, versionIndex); - } - + int versionIndex = IndexOfTokenStart(ua, versionToken, sameToken ? detectIndex : 0); if (versionIndex >= 0) { - return TryReadVersionAfter(ua, versionToken, versionIndex, tokenStartOnly: true, slashRequired: false, out version); + return TryReadVersionAfter(ua, versionToken, versionIndex, slashRequired: false, out version); } - // Without version token the version follows the detect token (e.g. "Opera/9.80"). + // Without version token the version follows the detect token (e.g. "Opera/9.80"), unless both are the same. if (sameToken) { version = default; return false; } - return TryReadVersionAfter(ua, detectToken, detectIndex, tokenStartOnly: false, slashRequired: false, out version); + return TryReadVersionAfter(ua, detectToken, detectIndex, slashRequired: false, out version); } /// - /// Reads the version of the first occurrence of , starting at , that has one. + /// Reads the version after the occurrence of at or, + /// if that one has none, after a later occurrence that starts a token. /// - private static bool TryReadVersionAfter(ReadOnlySpan ua, string token, int index, bool tokenStartOnly, bool slashRequired, out Range version) + /// + /// The given occurrence may continue a word, as before (HeadlessChrome/120 is Chrome); later occurrences must start + /// a token, so MyChrome/2.0 does not count. The search continues behind the product token examined before, because + /// a token cannot start inside it; so every character is examined once, independent of the number of occurrences. + /// + private static bool TryReadVersionAfter(ReadOnlySpan ua, string token, int index, bool slashRequired, out Range version) { - for (; index >= 0; index = IndexOfNext(ua, token, index)) + do { int end = index + token.Length; - if ((tokenStartOnly && !IsTokenStart(ua, index)) - || (slashRequired && (end >= ua.Length || ua[end] != '/'))) + int next = index + 1; + if (!slashRequired || (end < ua.Length && ua[end] == '/')) { - continue; - } + if (TryExtractVersion(ua[end..], out Range range, out int productTokenLength)) + { + version = new Range(end + range.Start.Value, end + range.End.Value); + return true; + } - if (TryExtractVersion(ua[end..], out Range range)) - { - version = new Range(end + range.Start.Value, end + range.End.Value); - return true; + next = end + productTokenLength; } + + index = IndexOfTokenStart(ua, token, next); } + while (index >= 0); version = default; return false; } /// - /// Returns the index of the next occurrence of after , or -1. + /// Returns the index of the first occurrence of at or after + /// that starts a token (at the beginning or after a delimiter), or -1. /// - private static int IndexOfNext(ReadOnlySpan ua, string token, int index) + private static int IndexOfTokenStart(ReadOnlySpan ua, string token, int start) { - int next = ua[(index + 1)..].IndexOf(token, StringComparison.OrdinalIgnoreCase); - return next < 0 ? -1 : index + 1 + next; - } + while (true) + { + int offset = ua[start..].IndexOf(token, StringComparison.OrdinalIgnoreCase); + if (offset < 0) + { + return -1; + } - /// - /// Returns whether a token at starts a token of its own, i.e. does not continue a word. - /// - private static bool IsTokenStart(ReadOnlySpan ua, int index) - => index == 0 || !char.IsAsciiLetterOrDigit(ua[index - 1]); + int index = start + offset; + if (index == 0 || s_productTokenDelimiters.Contains(ua[index - 1])) + { + return index; + } + + start = index + 1; + } + } /// /// returns true if browser was found @@ -314,13 +326,11 @@ private static bool TryIndexOf(ReadOnlySpan haystack, ReadOnlySpan n /// The search ends at the next delimiter, so an empty version never takes the version of the next product /// (SamsungBrowser/ Chrome/131.0 has no Samsung Internet version). /// - private static bool TryExtractVersion(ReadOnlySpan haystack, out Range range) + private static bool TryExtractVersion(ReadOnlySpan haystack, out Range range, out int productTokenLength) { int end = haystack.IndexOfAny(s_productTokenDelimiters); - if (end >= 0) - { - haystack = haystack[..end]; - } + productTokenLength = end < 0 ? haystack.Length : end; + haystack = haystack[..productTokenLength]; int start = haystack.IndexOfAnyInRange('0', '9'); if (start < 0) diff --git a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs index a3f792b..42275f3 100644 --- a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs +++ b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs @@ -13,17 +13,22 @@ public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider /// /// internal cache /// - private readonly ConcurrentDictionary _cache = new(StringComparer.OrdinalIgnoreCase); + /// + /// The key is the exact user agent (ordinal): the result contains the user agent, so a differently cased one is another entry. + /// + private readonly ConcurrentDictionary _cache = new(StringComparer.Ordinal); + + /// + /// Creates a provider with an empty cache. + /// + public HttpUserAgentParserCachedProvider() => HttpUserAgentParserTelemetryState.Register(this); /// /// Parses the user agent or uses the internal cached information /// /// - /// This method includes performance optimizations for telemetry: - /// - /// Telemetry checks use a volatile flag to ensure zero overhead when disabled. - /// Cache size reporting (which requires an expensive lock) is only executed if the specific metric is enabled. - /// + /// Telemetry checks use a volatile flag to ensure zero overhead when disabled. The cache size is counted only + /// when a cache size instrument is observed. /// public HttpUserAgentInformation Parse(string userAgent) { @@ -39,19 +44,11 @@ public HttpUserAgentInformation Parse(string userAgent) } // Note: ConcurrentDictionary can invoke the factory multiple times in races; counters are best-effort. - HttpUserAgentInformation result = _cache.GetOrAdd(userAgent, static ua => + return _cache.GetOrAdd(userAgent, static ua => { HttpUserAgentParserTelemetry.ConcurrentCacheMiss(); return HttpUserAgentParser.Parse(ua); }); - - if (HttpUserAgentParserTelemetry.IsCacheSizeEnabled) - { - // Optimization: Avoid expensive .Count property access (locks all buckets) if telemetry is disabled. - HttpUserAgentParserTelemetry.ConcurrentCacheSizeSet(_cache.Count); - } - - return result; } /// diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index e4b2b98..34a8979 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -44,7 +44,11 @@ public static string GetMeterName(string? meterPrefix) private static readonly object s_lock = new(); #endif - private static Meter? s_defaultMeter; + /// + /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. + /// + private static Meter? s_ownedMeter; + private static Instruments? s_instruments; /// @@ -68,14 +72,45 @@ public static string GetMeterName(string? meterPrefix) /// /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. /// - public static void Enable(Meter? meter = null) + public static void Enable(Meter? meter = null) => Use(meter, MeterName); + + /// + /// Creates the metric instruments on a meter named that this class creates and owns. + /// + /// + /// An owned meter is created once per name; it is disposed when another meter replaces it. + /// + public static void EnableOwnedMeter(string meterName) => Use(null, meterName); + + /// + /// Uses or, if null, an owned meter named . + /// + private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - meter ??= s_defaultMeter ??= new Meter(MeterName); + Meter? previousOwnedMeter = s_ownedMeter; + if (meter is null) + { + meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) + ? previousOwnedMeter + : new Meter(ownedMeterName); + s_ownedMeter = meter; + } + else + { + s_ownedMeter = null; + } // Instruments are created once per meter and published only after all of them exist. Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); + + // A replaced owned meter is no longer used: dispose it, so repeated registrations do not keep meters alive. + // Meters passed in by the caller are never disposed. + if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) + { + previousOwnedMeter.Dispose(); + } } } @@ -111,7 +146,8 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - s_defaultMeter = null; + s_ownedMeter?.Dispose(); + s_ownedMeter = null; s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs index 1b00aac..bcd6069 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs @@ -34,13 +34,6 @@ public static bool AreCountersEnabled => (Volatile.Read(ref s_enabledFlags) & EventCountersFlag) != 0 && HttpUserAgentParserEventSource.Log.IsEnabled(); - /// - /// Checks if Meters are specifically enabled. - /// - public static bool AreMetersEnabled - => (Volatile.Read(ref s_enabledFlags) & MetersFlag) != 0 - && HttpUserAgentParserMeters.IsEnabled; - /// /// Checks if parse duration should be measured. /// This is true if either EventCounters are enabled OR if the specific Meter instrument for duration is enabled. @@ -48,13 +41,6 @@ public static bool AreMetersEnabled public static bool ShouldMeasureParseDuration => AreCountersEnabled || HttpUserAgentParserMeters.IsParseDurationEnabled; - /// - /// Checks if cache size tracking is enabled for either system. - /// This is used to guard expensive operations like .Count or Interlocked updates. - /// - public static bool IsCacheSizeEnabled - => AreCountersEnabled || AreMetersEnabled; - /// /// Enables core EventCounter telemetry for the parser. /// @@ -75,6 +61,15 @@ public static void EnableMeters(Meter? meter = null) Interlocked.Or(ref s_enabledFlags, MetersFlag); } + /// + /// Enables native System.Diagnostics.Metrics telemetry with a meter named that the package owns. + /// + public static void EnableMetersWithName(string meterName) + { + HttpUserAgentParserMeters.EnableOwnedMeter(meterName); + Interlocked.Or(ref s_enabledFlags, MetersFlag); + } + /// /// Records a parse request event. /// @@ -148,21 +143,12 @@ public static void ConcurrentCacheMiss() } } - /// - /// Updates the concurrent cache size. - /// - /// The current size of the cache. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ConcurrentCacheSizeSet(int size) - => HttpUserAgentParserTelemetryState.SetConcurrentCacheSize(size); - /// /// Resets telemetry state for unit testing. /// public static void ResetForTests() { Volatile.Write(ref s_enabledFlags, 0); - HttpUserAgentParserTelemetryState.ResetForTests(); HttpUserAgentParserMeters.ResetForTests(); } } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs index 31189f3..61432e6 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs @@ -1,35 +1,43 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Runtime.CompilerServices; +using MyCSharp.HttpUserAgentParser.Providers; + namespace MyCSharp.HttpUserAgentParser.Telemetry; /// -/// Holds shared telemetry state for the concurrent dictionary cache. +/// Knows the live instances to report their cache size. /// /// -/// The state is updated independently of whether telemetry is currently enabled -/// so that polling-based instruments can report correct values once a listener -/// attaches. +/// Every provider registers itself when it is created, independent of whether telemetry is enabled, so the +/// reported size includes entries cached before telemetry was enabled. Providers are referenced weakly. /// internal static class HttpUserAgentParserTelemetryState { - private static long s_concurrentCacheSize; + private static readonly ConditionalWeakTable s_providers = new(); /// - /// Gets the current size of the concurrent dictionary cache. + /// Registers a provider whose entries count towards . /// - public static long ConcurrentCacheSize - => Volatile.Read(ref s_concurrentCacheSize); + public static void Register(HttpUserAgentParserCachedProvider provider) => s_providers.Add(provider, null); /// - /// Updates the current size of the concurrent dictionary cache. + /// Gets the number of entries of all live concurrent dictionary caches. /// - /// Current number of entries in the cache. - public static void SetConcurrentCacheSize(int size) - => Volatile.Write(ref s_concurrentCacheSize, size); + /// + /// Counting locks each dictionary briefly; it only runs when an instrument is observed, never on the parse path. + /// + public static long ConcurrentCacheSize + { + get + { + long size = 0; + foreach (KeyValuePair provider in (IEnumerable>)s_providers) + { + size += provider.Key.CacheEntryCount; + } - /// - /// Resets the telemetry state for unit tests. - /// - public static void ResetForTests() - => Volatile.Write(ref s_concurrentCacheSize, 0); + return size; + } + } } diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index e4e796d..6b24e48 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -55,6 +55,7 @@ services ``` This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. +The key is the exact user agent string (ordinal). Use it only for a known, limited set of user agents (e.g. in tests); for web applications use [MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache). @@ -81,7 +82,7 @@ EventSource: `MyCSharp.HttpUserAgentParser` (constant: `HttpUserAgentParserEvent - `parse-duration` (s, event counter) - `cache-hit` (incrementing, `HttpUserAgentParserCachedProvider`) - `cache-miss` (incrementing, `HttpUserAgentParserCachedProvider`) -- `cache-size` (polling, `HttpUserAgentParserCachedProvider`) +- `cache-size` (polling, `HttpUserAgentParserCachedProvider`): the entries of all live providers of the package, including entries cached before telemetry was enabled ### Monitor with dotnet-counters @@ -108,6 +109,7 @@ services Pass your own `Meter` to `WithMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. +Meters the package creates itself (without argument or with a prefix) are created once per name and disposed when they are replaced. ### Meter + instruments @@ -117,7 +119,7 @@ Meter: `mycsharp.http_user_agent_parser` (the prefix `mycsharp.` can be changed - `parse.duration` (histogram, s) - `cache.hit` (counter) - `cache.miss` (counter) -- `cache.size` (observable gauge) +- `cache.size` (observable gauge): the entries of all live providers of the package, including entries cached before telemetry was enabled ## Export to OpenTelemetry diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs index 1bbdb1b..9e43707 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics.Metrics; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; @@ -95,4 +96,56 @@ public void WithAspNetCoreMeterTelemetryPrefix_Throws_WhenInvalid() Assert.Throws(() => options.WithAspNetCoreMeterTelemetryPrefix("acme-")); Assert.Throws(() => options.WithAspNetCoreMeterTelemetryPrefix("acme..")); } + + [Fact] + public void Repeated_Prefix_Registrations_Keep_One_Meter() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + for (int i = 0; i < 32; i++) + { + options.WithAspNetCoreMeterTelemetryPrefix("repeated."); + } + + Assert.Equal(1, CountLiveMeters("repeated.http_user_agent_parser.aspnetcore")); + } + + [Fact] + public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + using Meter callerMeter = new("caller.http_user_agent_parser.aspnetcore"); + + options.WithAspNetCoreMeterTelemetryPrefix("first."); + options.WithAspNetCoreMeterTelemetryPrefix("second."); + Assert.Equal(0, CountLiveMeters("first.http_user_agent_parser.aspnetcore")); + Assert.Equal(1, CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + + options.WithAspNetCoreMeterTelemetry(callerMeter); + Assert.Equal(0, CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + + options.WithAspNetCoreMeterTelemetry(); // the default meter replaces the meter of the caller + Assert.Equal(1, CountLiveMeters("caller.http_user_agent_parser.aspnetcore")); + Assert.Equal(1, CountLiveMeters("mycsharp.http_user_agent_parser.aspnetcore")); + } + + /// + /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. + /// + private static int CountLiveMeters(string meterName) + { + HashSet meters = []; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) + { + meters.Add(instrument.Meter); + } + }, + }; + listener.Start(); + return meters.Count; + } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index 7dde5ce..d601932 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics.Metrics; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; @@ -101,4 +102,56 @@ public void WithMemoryCacheMeterTelemetryPrefix_Throws_WhenInvalid() Assert.Throws(() => options.WithMemoryCacheMeterTelemetryPrefix("acme-")); Assert.Throws(() => options.WithMemoryCacheMeterTelemetryPrefix("acme..")); } + + [Fact] + public void Repeated_Prefix_Registrations_Keep_One_Meter() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + for (int i = 0; i < 32; i++) + { + options.WithMemoryCacheMeterTelemetryPrefix("repeated."); + } + + Assert.Equal(1, CountLiveMeters("repeated.http_user_agent_parser.memorycache")); + } + + [Fact] + public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + using Meter callerMeter = new("caller.http_user_agent_parser.memorycache"); + + options.WithMemoryCacheMeterTelemetryPrefix("first."); + options.WithMemoryCacheMeterTelemetryPrefix("second."); + Assert.Equal(0, CountLiveMeters("first.http_user_agent_parser.memorycache")); + Assert.Equal(1, CountLiveMeters("second.http_user_agent_parser.memorycache")); + + options.WithMemoryCacheMeterTelemetry(callerMeter); + Assert.Equal(0, CountLiveMeters("second.http_user_agent_parser.memorycache")); + + options.WithMemoryCacheMeterTelemetry(); // the default meter replaces the meter of the caller + Assert.Equal(1, CountLiveMeters("caller.http_user_agent_parser.memorycache")); + Assert.Equal(1, CountLiveMeters("mycsharp.http_user_agent_parser.memorycache")); + } + + /// + /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. + /// + private static int CountLiveMeters(string meterName) + { + HashSet meters = []; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) + { + meters.Add(instrument.Meter); + } + }, + }; + listener.Start(); + return meters.Count; + } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs index 979f9bc..5223f25 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs @@ -95,17 +95,14 @@ public void EventSource_Can_Be_Disposed() } [Fact] - public void Evicted_Entries_Decrement_The_Cache_Size() + public void Size_Limit_Bounds_The_Counted_Entries() { - using Meter meter = new("test.memorycache.eviction"); - HttpUserAgentParserMemoryCacheTelemetry.EnableMeters(meter); - - // A size limit of one entry: the second user agent exceeds the capacity and gets evicted. + // A size limit of one entry: the second user agent exceeds the capacity and is not cached. HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions(new MemoryCacheOptions { SizeLimit = 1 })); _ = provider.Parse("Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/158.0.0.0"); _ = provider.Parse("Mozilla/5.0 (X11; Linux x86_64; rv:160.0) Gecko/20100101 Firefox/160.0"); - // Eviction callbacks run asynchronously. - Assert.True(SpinWait.SpinUntil(static () => HttpUserAgentParserMemoryCacheTelemetryState.CacheSize < 2, TimeSpan.FromSeconds(10))); + Assert.InRange(provider.CacheEntryCount, 0, 1); + Assert.True(HttpUserAgentParserMemoryCacheTelemetryState.CacheSize >= provider.CacheEntryCount); } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs index 8bf1140..f38dfa3 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics.Metrics; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; @@ -26,30 +27,47 @@ public void Disabled_Telemetry_Parses_And_Caches() Assert.False(HttpUserAgentParserMemoryCacheTelemetry.IsEnabled); AssertParsesAndCaches(); - Assert.Equal(0, HttpUserAgentParserMemoryCacheTelemetryState.CacheSize); } [Fact] - public void Counters_Without_Listener_Do_Not_Track_Cache_Size() + public void Counters_Without_Listener_Parse_And_Cache() { new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMemoryCacheTelemetry(); Assert.True(HttpUserAgentParserMemoryCacheTelemetry.IsEnabled); - Assert.False(HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled); AssertParsesAndCaches(); - Assert.Equal(0, HttpUserAgentParserMemoryCacheTelemetryState.CacheSize); } [Fact] - public void Meters_Track_Cache_Size() + public void Cache_Size_Includes_Entries_Cached_Before_Telemetry_Was_Enabled() { - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMemoryCacheMeterTelemetry(); - - Assert.True(HttpUserAgentParserMemoryCacheTelemetry.IsCacheSizeEnabled); - - AssertParsesAndCaches(); - Assert.Equal(1, HttpUserAgentParserMemoryCacheTelemetryState.CacheSize); + HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Firefox/12"); + + using Meter meter = new("test.memorycache.size.late"); + long? size = null; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter == meter && string.Equals(instrument.Name, "cache.size", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + listener.SetMeasurementEventCallback((_, value, _, _) => size = value); + listener.Start(); + + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMemoryCacheMeterTelemetry(meter); + _ = provider.Parse("Chrome/17"); // hit + listener.RecordObservableInstruments(); + + // Providers of tests running in parallel may add to the size. + Assert.True(size >= 2, $"cache.size: {size}"); + GC.KeepAlive(provider); } private static void AssertParsesAndCaches() diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index b8e6abf..a9d861c 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests; @@ -314,6 +315,10 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() [InlineData("Opera/9.80 VendorVersion/120.0", "Opera", "9.80")] [InlineData("Mozilla/5.0 Version/ XVersion/1.0 Version/17.0 Safari/604.1", "Safari", "17.0")] [InlineData("Version/17.0 Safari/604.1", "Safari", "17.0")] + [InlineData("Opera/9.80 Vendor-Version/120.0", "Opera", "9.80")] + // Later occurrences only count at the start of a token; the first one may continue a word, as before + [InlineData("ChromeHelper/1 MyChrome/2.0 Firefox/126.0", "Firefox", "126.0")] + [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/120.0.6099.109 Safari/537.36", "Chrome", "120.0.6099.109")] public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAgent, string expectedName, string expectedVersion) { (string Name, string? Version)? browser = HttpUserAgentParser.GetBrowser(userAgent); @@ -332,6 +337,23 @@ public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userA Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); } + [Theory] + [InlineData("Chrome/a")] // one product token without delimiter + [InlineData("Chrome/a ")] // many product tokens + [InlineData("Version/a")] + [InlineData("Version/a ")] + public void GetBrowser_Time_Grows_Linearly_With_Repeated_Tokens(string repeated) + { + // A search that rescans the rest of the user agent for every occurrence needs seconds for 1,000,000 characters. + string userAgent = string.Concat(Enumerable.Repeat(repeated, 1_000_000 / repeated.Length)); + + long start = Stopwatch.GetTimestamp(); + Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); + TimeSpan elapsed = Stopwatch.GetElapsedTime(start); + + Assert.True(elapsed < TimeSpan.FromSeconds(1), $"GetBrowser took {elapsed.TotalMilliseconds:F0} ms"); + } + [Theory] [InlineData("Chrome/ı1.2é3", "1.2")] [InlineData("Chrome/1.2ı3 followed by a long suffix", "1.2")] diff --git a/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs b/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs index fb79528..dc2f87d 100644 --- a/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs @@ -48,4 +48,16 @@ public void Parse() Assert.Equal(2, provider.CacheEntryCount); Assert.True(provider.HasCacheEntry(userAgentTwo)); } + + [Fact] + public void Keys_Are_Case_Sensitive() + { + HttpUserAgentParserCachedProvider provider = new(); + + // The result contains the original user agent, so a differently cased user agent is a different entry. + Assert.Equal("Chrome/17", provider.Parse("Chrome/17").UserAgent); + Assert.Equal("CHROME/17", provider.Parse("CHROME/17").UserAgent); + Assert.Equal(2, provider.CacheEntryCount); + Assert.False(provider.HasCacheEntry("chrome/17")); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index d5408d7..843fc74 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -1,5 +1,6 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Diagnostics.Metrics; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; @@ -116,4 +117,56 @@ public void WithMeterTelemetryPrefix_Throws_WhenInvalid() Assert.Throws(() => options.WithMeterTelemetryPrefix("acme-")); Assert.Throws(() => options.WithMeterTelemetryPrefix("acme..")); } + + [Fact] + public void Repeated_Prefix_Registrations_Keep_One_Meter() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + for (int i = 0; i < 32; i++) + { + options.WithMeterTelemetryPrefix("repeated."); + } + + Assert.Equal(1, CountLiveMeters("repeated.http_user_agent_parser")); + } + + [Fact] + public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + using Meter callerMeter = new("caller.http_user_agent_parser"); + + options.WithMeterTelemetryPrefix("first."); + options.WithMeterTelemetryPrefix("second."); + Assert.Equal(0, CountLiveMeters("first.http_user_agent_parser")); + Assert.Equal(1, CountLiveMeters("second.http_user_agent_parser")); + + options.WithMeterTelemetry(callerMeter); + Assert.Equal(0, CountLiveMeters("second.http_user_agent_parser")); + + options.WithMeterTelemetry(); // the default meter replaces the meter of the caller + Assert.Equal(1, CountLiveMeters("caller.http_user_agent_parser")); + Assert.Equal(1, CountLiveMeters("mycsharp.http_user_agent_parser")); + } + + /// + /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. + /// + private static int CountLiveMeters(string meterName) + { + HashSet meters = []; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) + { + meters.Add(instrument.Meter); + } + }, + }; + listener.Start(); + return meters.Count; + } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs index ef3e5f3..85e179a 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs @@ -1,6 +1,7 @@ // Copyright © https://myCSharp.de - all rights reserved using System.Diagnostics.Metrics; +using MyCSharp.HttpUserAgentParser.Providers; using MyCSharp.HttpUserAgentParser.Telemetry; using Xunit; @@ -102,12 +103,15 @@ public void EventSource_Can_Be_Disposed() } [Fact] - public void Telemetry_State_Tracks_Concurrent_Cache_Size() + public void Telemetry_State_Counts_The_Entries_Of_Live_Providers() { - HttpUserAgentParserTelemetry.ConcurrentCacheSizeSet(42); - Assert.Equal(42, HttpUserAgentParserTelemetryState.ConcurrentCacheSize); - - HttpUserAgentParserTelemetry.ResetForTests(); - Assert.Equal(0, HttpUserAgentParserTelemetryState.ConcurrentCacheSize); + HttpUserAgentParserCachedProvider provider = new(); + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Firefox/12"); + _ = provider.Parse("Chrome/17"); + + // Providers of tests running in parallel may add to the size. + Assert.True(HttpUserAgentParserTelemetryState.ConcurrentCacheSize >= 2); + GC.KeepAlive(provider); } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs index 9d641af..e578add 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -31,28 +31,56 @@ public void Disabled_Telemetry_Parses_Without_Instrumentation() } [Fact] - public void Counters_Without_Listener_Neither_Measure_Duration_Nor_Track_Cache_Size() + public void Counters_Without_Listener_Do_Not_Measure_Duration() { new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithTelemetry(); Assert.True(HttpUserAgentParserTelemetry.IsEnabled); Assert.False(HttpUserAgentParserTelemetry.ShouldMeasureParseDuration); - Assert.False(HttpUserAgentParserTelemetry.IsCacheSizeEnabled); AssertParsesAndCaches(); } [Fact] - public void Meters_Without_Duration_Listener_Track_Cache_Size_But_Do_Not_Measure_Duration() + public void Meters_Without_Duration_Listener_Do_Not_Measure_Duration() { new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMeterTelemetry(); Assert.True(HttpUserAgentParserTelemetry.IsEnabled); Assert.False(HttpUserAgentParserTelemetry.ShouldMeasureParseDuration); - Assert.True(HttpUserAgentParserTelemetry.IsCacheSizeEnabled); AssertParsesAndCaches(); - Assert.Equal(1, HttpUserAgentParserTelemetryState.ConcurrentCacheSize); + } + + [Fact] + public void Cache_Size_Includes_Entries_Cached_Before_Telemetry_Was_Enabled() + { + HttpUserAgentParserCachedProvider provider = new(); + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Firefox/12"); + + using Meter meter = new("test.size.late"); + long? size = null; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter == meter && string.Equals(instrument.Name, "cache.size", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + listener.SetMeasurementEventCallback((_, value, _, _) => size = value); + listener.Start(); + + new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()).WithMeterTelemetry(meter); + _ = provider.Parse("Chrome/17"); // hit + listener.RecordObservableInstruments(); + + // Providers of tests running in parallel may add to the size. + Assert.True(size >= 2, $"cache.size: {size}"); + GC.KeepAlive(provider); } [Fact] From bce7be38a67182ad19eaa5149ee707b646d4d6d7 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 20:03:36 +0100 Subject: [PATCH 07/41] fix: findings of independent parser, telemetry and provider reviews Parser - Browser and version tokens only count at the start of a token (at the beginning or after a space, tab, '+', ';', '(', ')' or ','), for every occurrence: "Knowledge/1.0" is no Edge, "MyChrome/2.0" no Chrome. Headless Chrome and ELinks get rules of their own. - '+' separates tokens like a space (URL-encoded logs such as IIS): Safari, Opera and Internet Explorer versions are read again. - Rules with a version token accept "Token 1.2" (Opera 9.50, MSIE 6.0, several spaces, '+'); "MSIE MSIE 7.0" and "MSIE 6.0" work again. - Platforms: "cros " instead of "cros" (Microsoft is no ChromeOS), "windows phone" before "android". Robot key "YouBot/" (ShowyouBot). - Fast path: the inlined IndexOf stays in front of the token-start check, so rules that do not match cost what they did. Telemetry - Own meters are created once per name and reused, not disposed when replaced: no measurement is lost during a switch. - The core and the MemoryCache package reject a shared meter (same instrument names, the values mixed silently). - Meter prefixes: ASCII letters or digits followed by '.'. Providers, DI, ASP.NET Core - MemoryCache entries get all CacheEntryOptions (absolute expiration, priority, tokens, eviction callbacks, size). - HttpUserAgentParserMemoryCachedProvider implements IDisposable and disposes its MemoryCache. - Accessor registrations use TryAdd (idempotent in any order); an empty or white-space User-Agent header returns null. - Docs: readme snippets that did not compile, regex creation, token rules, allocation statement, URL-encoded user agents. --- README.md | 34 +++--- ...serDependencyInjectionOptionsExtensions.cs | 10 +- .../HttpUserAgentParserAccessor.cs | 4 +- .../IHttpUserAgentParserAccessor.cs | 2 +- .../IHttpUserAgentParserContextAccessor.cs | 2 +- .../HttpUserAgentParserAspNetCoreMeters.cs | 38 +++---- src/HttpUserAgentParser.AspNetCore/readme.md | 6 +- ...encyInjectionOptionsTelemetryExtensions.cs | 4 + ...rMemoryCacheServiceCollectionExtensions.cs | 3 +- ...HttpUserAgentParserMemoryCachedProvider.cs | 24 +++- .../HttpUserAgentParserMemoryCacheMeters.cs | 42 ++++--- ...serAgentParserMemoryCacheTelemetryState.cs | 10 ++ src/HttpUserAgentParser.MemoryCache/readme.md | 12 +- ...encyInjectionOptionsTelemetryExtensions.cs | 4 + .../HttpUserAgentParser.cs | 106 +++++++++++++----- src/HttpUserAgentParser/HttpUserAgentRules.cs | 14 ++- .../HttpUserAgentParserCacheMeterGuard.cs | 87 ++++++++++++++ .../HttpUserAgentParserMeterNameHelper.cs | 13 +-- .../Telemetry/HttpUserAgentParserMeters.cs | 42 ++++--- src/HttpUserAgentParser/readme.md | 9 +- ...tParserServiceCollectionExtensionsTests.cs | 24 ++++ .../HttpUserAgentParserAccessorTests.cs | 11 ++ ...entParserAspNetCoreMetersTelemetryTests.cs | 65 +++++++++-- ...rserMemoryCachedProviderAdditionalTests.cs | 69 ++++++++++++ ...ntParserMemoryCacheMetersTelemetryTests.cs | 80 +++++++++++-- .../HttpUserAgentParserTests.cs | 40 ++++++- .../HttpUserAgentStaticsTests.cs | 4 +- ...HttpUserAgentParserMetersTelemetryTests.cs | 101 +++++++++++++++-- 28 files changed, 680 insertions(+), 180 deletions(-) create mode 100644 src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs diff --git a/README.md b/README.md index 0e2bb3c..dd77d95 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -> `AddHttpUserAgentMemoryCachedParser` registers `HttpUserAgentParserMemoryCachedProvider` as singleton which contains an isolated `MemoryCache` object. +> `AddHttpUserAgentMemoryCachedParser` registers `HttpUserAgentParserMemoryCachedProvider` as singleton which contains an isolated `MemoryCache` object; the container disposes the provider and its cache. Every entry gets all `CacheEntryOptions` (e.g. `AbsoluteExpirationRelativeToNow`, `Priority`, expiration tokens, eviction callbacks) and the size 1, unless `CacheEntryOptions.Size` is set. ### ASP.NET Core @@ -119,7 +119,7 @@ Now you can use // e.g. in a controller, a minimal API handler or a middleware public void MyMethod(IHttpUserAgentParserAccessor parserAccessor, HttpContext httpContext) { - HttpUserAgentInformation? info = parserAccessor.Get(httpContext); // null if the request has no User-Agent header + HttpUserAgentInformation? info = parserAccessor.Get(httpContext); // null if the request has no (or an empty) User-Agent header } // in any service, with AddHttpUserAgentParserContextAccessor() @@ -140,11 +140,13 @@ If you only need the raw header value, use `httpContext.GetUserAgentString()`. 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) 4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Yandex Browser, UC Browser and others -In every list the first matching entry wins. A browser version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next space, tab, `;`, `(`, `)` or `,`. A token starts at the beginning or after one of these characters. A separate version token such as Safari's `Version/` only counts at the start of a token, so `VendorVersion/1.0` and `Vendor-Version/1.0` are ignored. If the browser token has no version, later occurrences that start a token are checked, then the next rule. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome; iPadOS sends the macOS user agent by default. +In every list the first matching entry wins. Browser and version tokens only count at the start of a token: at the beginning of the user agent or after a space, tab, `+`, `;`, `(`, `)` or `,`, so `Knowledge/1.0` is no Edge and `VendorVersion/1.0` no version token. The version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next of these characters; Opera and Internet Explorer also accept `Opera 9.50` and `MSIE 6.0`. If a token has no version, later occurrences of the token are checked, then the next rule. `+` stands for a space as in URL-encoded logs (IIS); decode other encodings such as `%20` before parsing, e.g. with `WebUtility.UrlDecode`. + +Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome, as is Headless Chrome; iPadOS sends the macOS user agent by default. ### `HttpUserAgentStatics` and regular expressions -The parser does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` and `HttpUserAgentPlatformInformation.Regex` still provide regular expressions for your own matching. They are generated at compile time with `[GeneratedRegex]` (no runtime compilation, trimming and Native AOT compatible) and are only created on first access; the browser patterns capture the version in group 1. +The parser does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` and `HttpUserAgentPlatformInformation.Regex` still provide regular expressions for your own matching. They are generated at compile time with `[GeneratedRegex]` (no runtime compilation, trimming and Native AOT compatible) and are created on first use: the browser regexes when `HttpUserAgentStatics` is first used (including `HttpUserAgentStatics.Robots`), a platform regex on first access of `HttpUserAgentPlatformInformation.Regex`. The browser patterns capture the version in group 1. The patterns use `RegexOptions.IgnoreCase` with culture-invariant case mapping, so a match does not depend on the current culture (e.g. `LINUX` matches `linux` under `tr-TR` as well). `RegexOptions.Compiled` is not set, because the source generator already emits the matching code. @@ -284,7 +286,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The package creates its own meters (without argument or with a prefix) once per name and disposes them when they are replaced; meters you pass in are never disposed. +Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The package creates its own meters (without argument or with a prefix) once per name and reuses them; meters you pass in are never disposed. The core and the MemoryCache package need separate meters, because both create the instruments `cache.hit`, `cache.miss` and `cache.size`; passing the meter that one of them uses to the other throws an `ArgumentException`. The ASP.NET Core package may share a meter with either. ### Meter names and instruments @@ -323,7 +325,7 @@ public void ConfigureServices(IServiceCollection services) Rules: - `""` (empty) is allowed and removes the prefix. -- Otherwise the prefix must be **alphanumeric** and **end with `.`**. +- Otherwise the prefix must be **ASCII letters or digits** followed by **`.`** (e.g. `acme.`). Example results: @@ -456,9 +458,9 @@ Mixed workload: the catalog user agents parsed in a loop, mean time per user age | Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | .NET 11.0.0 | Allocated | | --- | ---: | ---: | ---: | ---: | ---: | -| 44 browser user agents | 758.5 ns | 372.0 ns | 353.1 ns | 302.1 ns | 38 B | -| 48 crawler user agents | 369.9 ns | 192.6 ns | 167.4 ns | 159.4 ns | 0 B | -| All 96 user agents | 589.0 ns | 291.1 ns | 285.7 ns | 240.7 ns | 18 B | +| 44 browser user agents | 764.5 ns | 367.4 ns | 365.5 ns | 298.4 ns | 38 B | +| 48 crawler user agents | 385.4 ns | 186.2 ns | 177.3 ns | 160.5 ns | 0 B | +| All 96 user agents | 597.6 ns | 295.1 ns | 282.0 ns | 247.5 ns | 18 B | .NET 8 has no `SearchValues`; the parser checks the tokens one by one there. @@ -466,13 +468,13 @@ Single user agents on .NET 11: | User agent | Mean | Allocated | | --- | ---: | ---: | -| Chrome on Windows | 255.8 ns | 40 B | -| Firefox on Linux | 352.8 ns | 32 B | -| Chrome on Android | 282.1 ns | 40 B | -| Safari on iPhone | 302.5 ns | 32 B | -| Applebot | 192.0 ns | 0 B | -| Googlebot | 9.54 ns | 0 B | -| Unknown client | 421.7 ns | 0 B | +| Chrome on Windows | 254.7 ns | 40 B | +| Firefox on Linux | 356.4 ns | 32 B | +| Chrome on Android | 289.8 ns | 40 B | +| Safari on iPhone | 306.0 ns | 32 B | +| Applebot | 178.5 ns | 0 B | +| Googlebot | 9.58 ns | 0 B | +| Unknown client | 411.4 ns | 0 B | Startup in a new .NET 11 process (median of 7 runs): diff --git a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs index b3be779..4c99c83 100644 --- a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs +++ b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs @@ -18,10 +18,14 @@ public static class HttpUserAgentParserDependencyInjectionOptionsExtensions /// the is passed explicitly, e.g. accessor.Get(httpContext). /// Requires a registered /// + /// + /// Does nothing if an is already registered, e.g. by + /// , whose accessor supports Get(httpContext) as well. + /// public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserAccessor( this HttpUserAgentParserDependencyInjectionOptions options) { - options.Services.AddSingleton(); + options.Services.TryAddSingleton(); return options; } @@ -33,13 +37,13 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentPars /// /// /// has a small cost on every request; prefer - /// when the is at hand. + /// when the is at hand. Calling this method again has no effect. /// public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserContextAccessor( this HttpUserAgentParserDependencyInjectionOptions options) { options.Services.AddHttpContextAccessor(); - options.Services.AddSingleton(); + options.Services.TryAddSingleton(); options.Services.TryAddSingleton( static serviceProvider => serviceProvider.GetRequiredService()); return options; diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs index 855cd04..a5a2a70 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs @@ -27,12 +27,12 @@ public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAg /// /// Returns the parsed of , - /// or if the request has no User-Agent header + /// or if the request has no User-Agent header or only white space /// public HttpUserAgentInformation? Get(HttpContext httpContext) { string? httpUserAgent = GetHttpContextUserAgent(httpContext); - if (string.IsNullOrEmpty(httpUserAgent)) + if (string.IsNullOrWhiteSpace(httpUserAgent)) { return null; } diff --git a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs index 87cac25..4896753 100644 --- a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs @@ -19,7 +19,7 @@ public interface IHttpUserAgentParserAccessor /// /// Returns the parsed of , - /// or without User-Agent header + /// or without User-Agent header (or with only white space) /// HttpUserAgentInformation? Get(HttpContext httpContext); } diff --git a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs index 7fbb7c9..a05c282 100644 --- a/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/IHttpUserAgentParserContextAccessor.cs @@ -23,7 +23,7 @@ public interface IHttpUserAgentParserContextAccessor : IHttpUserAgentParserAcces /// /// Returns the parsed of the current request, - /// or outside of a request or without User-Agent header + /// or outside of a request or without User-Agent header (or with only white space) /// HttpUserAgentInformation? Get(); } diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 82196c5..308dd3c 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -30,7 +30,7 @@ internal static class HttpUserAgentParserAspNetCoreMeters /// /// /// The prefix to use. When null, the default prefix is used. When empty, - /// no prefix is applied. Otherwise, the prefix must be alphanumeric and end with '.'. + /// no prefix is applied. Otherwise, the prefix must be ASCII letters or digits followed by '.'. /// /// The full meter name. /// Thrown when the prefix is not empty and does not match the required format. @@ -44,9 +44,9 @@ public static string GetMeterName(string? meterPrefix) #endif /// - /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. + /// The meters this class created (the default meter and meters with a prefixed name), by name. /// - private static Meter? s_ownedMeter; + private static readonly Dictionary s_ownedMeters = new(StringComparer.Ordinal); private static Instruments? s_instruments; @@ -71,7 +71,7 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on a meter named that this class creates and owns. /// /// - /// An owned meter is created once per name; it is disposed when another meter replaces it. + /// An owned meter is created once per name and reused when the name is registered again. /// public static void EnableOwnedMeter(string meterName) => Use(null, meterName); @@ -82,28 +82,16 @@ private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - Meter? previousOwnedMeter = s_ownedMeter; - if (meter is null) + // Own meters are created once per name and kept: a replaced meter is not disposed, so a measurement that read + // the previous instruments just before the switch is still recorded. Meters of the caller are never disposed. + if (meter is null && !s_ownedMeters.TryGetValue(ownedMeterName, out meter)) { - meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) - ? previousOwnedMeter - : new Meter(ownedMeterName); - s_ownedMeter = meter; - } - else - { - s_ownedMeter = null; + meter = new Meter(ownedMeterName); + s_ownedMeters.Add(ownedMeterName, meter); } // Instruments are created once per meter and published only after all of them exist. Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); - - // A replaced owned meter is no longer used: dispose it, so repeated registrations do not keep meters alive. - // Meters passed in by the caller are never disposed. - if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) - { - previousOwnedMeter.Dispose(); - } } } @@ -129,8 +117,12 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - s_ownedMeter?.Dispose(); - s_ownedMeter = null; + foreach (Meter ownedMeter in s_ownedMeters.Values) + { + ownedMeter.Dispose(); + } + + s_ownedMeters.Clear(); s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index c99966a..8c04cd0 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -32,7 +32,7 @@ Usage with the `HttpContext`: public sealed class MyController(IHttpUserAgentParserAccessor accessor) : ControllerBase { [HttpGet] - public HttpUserAgentInformation? Get() => accessor.Get(HttpContext); // null without User-Agent header + public HttpUserAgentInformation? Get() => accessor.Get(HttpContext); // null without (or with an empty) User-Agent header } // Minimal API @@ -66,6 +66,7 @@ Telemetry is **modular** and **opt-in**. ```csharp services + .AddHttpUserAgentParser() .AddHttpUserAgentParserAccessor() .WithAspNetCoreTelemetry(); ``` @@ -93,13 +94,14 @@ This package can also emit native `System.Diagnostics.Metrics` instruments. ```csharp services + .AddHttpUserAgentParser() .AddHttpUserAgentParserAccessor() .WithAspNetCoreMeterTelemetry(); ``` Pass your own `Meter` to `WithAspNetCoreMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. -Meters the package creates itself (without argument or with a prefix) are created once per name and disposed when they are replaced. +Meters the package creates itself (without argument or with a prefix) are created once per name and reused. ### Meter + instruments diff --git a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs index 4b86b6f..d42e8d1 100644 --- a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs +++ b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs @@ -24,6 +24,10 @@ public static HttpUserAgentParserDependencyInjectionOptions WithMemoryCacheTelem /// /// Enables native System.Diagnostics.Metrics telemetry for the MemoryCache provider. /// + /// + /// is used by the other cache package: the core and the MemoryCache package need separate meters, + /// because both create the instruments cache.hit, cache.miss and cache.size. + /// public static HttpUserAgentParserDependencyInjectionOptions WithMemoryCacheMeterTelemetry( this HttpUserAgentParserDependencyInjectionOptions options, Meter? meter = null) diff --git a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs index cbe8534..d0aeec4 100644 --- a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs +++ b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs @@ -12,7 +12,8 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; public static class HttpUserAgentParserMemoryCacheServiceCollectionExtensions { /// - /// Registers as singleton to + /// Registers as singleton to ; + /// the container disposes it, and with it its /// public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentMemoryCachedParser( this IServiceCollection services, Action? options = null) diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index 503a82b..328c90d 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -6,11 +6,14 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache; -/// +/// /// /// that caches the results in an . /// -public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvider +/// +/// The provider owns its ; disposing the provider disposes the cache. +/// +public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvider, IDisposable { /// /// The name of the Meter used for metrics. @@ -59,19 +62,32 @@ public HttpUserAgentInformation Parse(string userAgent) return ParseAndCache(userAgent); } + /// + /// Disposes the internal ; the provider must not be used afterwards. + /// + public void Dispose() + { + HttpUserAgentParserMemoryCacheTelemetryState.Unregister(this); + _memoryCache.Dispose(); + GC.SuppressFinalize(this); + } + /// /// Parses the user agent and adds the result to the cache (miss path). /// /// + /// Every entry gets all + /// (expiration, priority, expiration tokens, eviction callbacks) and the size 1, unless the options specify a size. /// Like other cache implementations, concurrent misses of the same user agent may parse it more than once; the last result is kept. /// private HttpUserAgentInformation ParseAndCache(string userAgent) { HttpUserAgentInformation information = HttpUserAgentParser.Parse(userAgent); + MemoryCacheEntryOptions entryOptions = _options.CacheEntryOptions; using ICacheEntry entry = _memoryCache.CreateEntry(userAgent); - entry.SlidingExpiration = _options.CacheEntryOptions.SlidingExpiration; - entry.Size = 1; + entry.SetOptions(entryOptions); + entry.Size = entryOptions.Size ?? 1; entry.Value = information; if (HttpUserAgentParserMemoryCacheTelemetry.IsEnabled) diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 2b8d083..a601233 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -25,7 +25,7 @@ internal static class HttpUserAgentParserMemoryCacheMeters /// /// /// The prefix to use. When null, the default prefix is used. When empty, - /// no prefix is applied. Otherwise, the prefix must be alphanumeric and end with '.'. + /// no prefix is applied. Otherwise, the prefix must be ASCII letters or digits followed by '.'. /// /// The full meter name. /// Thrown when the prefix is not empty and does not match the required format. @@ -39,9 +39,9 @@ public static string GetMeterName(string? meterPrefix) #endif /// - /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. + /// The meters this class created (the default meter and meters with a prefixed name), by name. /// - private static Meter? s_ownedMeter; + private static readonly Dictionary s_ownedMeters = new(StringComparer.Ordinal); private static Instruments? s_instruments; @@ -64,7 +64,7 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on a meter named that this class creates and owns. /// /// - /// An owned meter is created once per name; it is disposed when another meter replaces it. + /// An owned meter is created once per name and reused when the name is registered again. /// public static void EnableOwnedMeter(string meterName) => Use(null, meterName); @@ -75,28 +75,19 @@ private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - Meter? previousOwnedMeter = s_ownedMeter; - if (meter is null) + // Own meters are created once per name and kept: a replaced meter is not disposed, so a measurement that read + // the previous instruments just before the switch is still recorded. Meters of the caller are never disposed. + if (meter is null && !s_ownedMeters.TryGetValue(ownedMeterName, out meter)) { - meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) - ? previousOwnedMeter - : new Meter(ownedMeterName); - s_ownedMeter = meter; - } - else - { - s_ownedMeter = null; + meter = new Meter(ownedMeterName); + s_ownedMeters.Add(ownedMeterName, meter); } + // The core and the MemoryCache package must not share a meter (same instrument names). + HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(meter); + // Instruments are created once per meter and published only after all of them exist. Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); - - // A replaced owned meter is no longer used: dispose it, so repeated registrations do not keep meters alive. - // Meters passed in by the caller are never disposed. - if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) - { - previousOwnedMeter.Dispose(); - } } } @@ -111,8 +102,13 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - s_ownedMeter?.Dispose(); - s_ownedMeter = null; + foreach (Meter ownedMeter in s_ownedMeters.Values) + { + ownedMeter.Dispose(); + } + + s_ownedMeters.Clear(); + HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs index 299f67b..914753e 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs @@ -20,6 +20,16 @@ internal static class HttpUserAgentParserMemoryCacheTelemetryState /// public static void Register(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Add(provider, null); + /// + /// Removes a disposed provider, whose entries no longer count. + /// + public static void Unregister(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Remove(provider); + + /// + /// Gets whether the entries of count towards . + /// + public static bool IsRegistered(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.TryGetValue(provider, out _); + /// /// Gets the number of entries of all live memory caches. /// diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/readme.md index 0b2b1e2..0163d97 100644 --- a/src/HttpUserAgentParser.MemoryCache/readme.md +++ b/src/HttpUserAgentParser.MemoryCache/readme.md @@ -25,6 +25,7 @@ Then inject `IHttpUserAgentParserProvider`: public sealed class MyService(IHttpUserAgentParserProvider parser) { public HttpUserAgentInformation Parse(string userAgent) => parser.Parse(userAgent); +} ``` ### Configure cache @@ -39,8 +40,11 @@ services.AddHttpUserAgentMemoryCachedParser(options => Notes: -- Each unique user-agent string counts as one cache entry. -- The provider is registered as singleton and owns its internal `MemoryCache` instance. +- Each unique user-agent string counts as one cache entry (the exact string, ordinal). +- Every entry gets all `CacheEntryOptions` (e.g. `AbsoluteExpirationRelativeToNow`, `Priority`, expiration tokens, eviction callbacks) + and the size 1, unless `CacheEntryOptions.Size` is set. +- The provider is registered as singleton and owns its internal `MemoryCache` instance; disposing the provider (the container does + that) disposes the cache. - Like any cache, concurrent requests for a new key can race; counters are best-effort. ## Telemetry (EventCounters) @@ -101,7 +105,9 @@ services Pass your own `Meter` to `WithMemoryCacheMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. -Meters the package creates itself (without argument or with a prefix) are created once per name and disposed when they are replaced. +Meters the package creates itself (without argument or with a prefix) are created once per name and reused. +The core and the MemoryCache package need separate meters (both create `cache.hit`, `cache.miss` and `cache.size`); passing the meter +of one to the other throws an `ArgumentException`. ### Meter + instruments diff --git a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs index e1aa007..f4b5d5c 100644 --- a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs +++ b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions.cs @@ -25,6 +25,10 @@ public static HttpUserAgentParserDependencyInjectionOptions WithTelemetry( /// Enables native System.Diagnostics.Metrics telemetry for the parser. /// This is opt-in to keep the default path free of telemetry overhead. /// + /// + /// is used by the other cache package: the core and the MemoryCache package need separate meters, + /// because both create the instruments cache.hit, cache.miss and cache.size. + /// public static HttpUserAgentParserDependencyInjectionOptions WithMeterTelemetry( this HttpUserAgentParserDependencyInjectionOptions options, Meter? meter = null) diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 1bdd151..3bae4f0 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -19,8 +19,9 @@ public static class HttpUserAgentParser /// /// Characters that end a product token ("product/version") or a comment entry of a user agent. + /// A token starts at the beginning of the user agent or after one of them; + stands for a space in URL-encoded logs. /// - private static readonly SearchValues s_productTokenDelimiters = SearchValues.Create(" \t;(),"); + private static readonly SearchValues s_productTokenDelimiters = SearchValues.Create(" \t;(),+"); /// /// Parses given user agent @@ -109,53 +110,65 @@ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out Http /// /// returns the browser or null /// + /// + /// Rules are evaluated in priority order (specific browsers before the browsers their user agents contain); the first rule + /// with a version wins. Browser and version tokens only count at the start of a token, i.e. at the beginning of the user agent + /// or after a space, tab, +, ;, (, ) or ,. + /// public static (string Name, string? Version)? GetBrowser(string userAgent) { ReadOnlySpan ua = userAgent.AsSpan(); - // Rules are evaluated in priority order (specific browsers before the browsers their user agents contain). foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) { - if (TryIndexOf(ua, detectToken, out int detectIndex) - && TryReadBrowserVersion(ua, detectToken, detectIndex, versionToken, out Range version)) + // Fast path: most rules do not match at all, and a match usually starts a token. + int detectIndex = ua.IndexOf(detectToken, StringComparison.OrdinalIgnoreCase); + if (detectIndex < 0) { - return (name, ua[version].ToString()); + continue; + } + + if (!IsTokenStart(ua, detectIndex)) + { + detectIndex = IndexOfTokenStart(ua, detectToken, detectIndex + 1); + if (detectIndex < 0) + { + continue; + } } - // Token not found or without version: try the next rule + if (TryReadBrowserVersion(ua, detectToken, detectIndex, versionToken, out Range version)) + { + return (name, ua[version].ToString()); + } } return null; } /// - /// Reads the version of a browser rule whose detect token occurs first at . + /// Reads the version of a browser rule whose detect token starts a token at first. /// private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectToken, int detectIndex, string? versionToken, out Range version) { if (versionToken is null) { - // Pattern Token/. Without '/' the token is likely a misspelling or part of another word (e.g. Edgg, Oprea, Chromee). - return TryReadVersionAfter(ua, detectToken, detectIndex, slashRequired: true, out version); + // "Token/1.2". Without '/' the token is likely a misspelling or another product (e.g. Edgg, Oprea, ChromeHelper). + return TryReadVersion(ua, detectToken, detectIndex, allowSpace: false, out version); } - // A separate version token (e.g. Safari "Version/") only counts at the start of a token: - // in "VendorVersion/120.0" or "Vendor-Version/120.0" the version belongs to another product. - bool sameToken = string.Equals(detectToken, versionToken, StringComparison.Ordinal); - int versionIndex = IndexOfTokenStart(ua, versionToken, sameToken ? detectIndex : 0); + // A separate version token ("Version/1.2", "rv:11.0"); with the same token as the detect token (Safari "Version/", + // "MSIE 6.0") the detect token has been found already. + int versionIndex = string.Equals(detectToken, versionToken, StringComparison.Ordinal) + ? detectIndex + : IndexOfTokenStart(ua, versionToken, 0); if (versionIndex >= 0) { - return TryReadVersionAfter(ua, versionToken, versionIndex, slashRequired: false, out version); - } - - // Without version token the version follows the detect token (e.g. "Opera/9.80"), unless both are the same. - if (sameToken) - { - version = default; - return false; + return TryReadVersion(ua, versionToken, versionIndex, allowSpace: true, out version); } - return TryReadVersionAfter(ua, detectToken, detectIndex, slashRequired: false, out version); + // Without version token the version follows the detect token ("Opera/9.80", "Opera 9.50"). + return TryReadVersion(ua, detectToken, detectIndex, allowSpace: true, out version); } /// @@ -163,17 +176,24 @@ private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectTo /// if that one has none, after a later occurrence that starts a token. /// /// - /// The given occurrence may continue a word, as before (HeadlessChrome/120 is Chrome); later occurrences must start - /// a token, so MyChrome/2.0 does not count. The search continues behind the product token examined before, because - /// a token cannot start inside it; so every character is examined once, independent of the number of occurrences. + /// + /// The version follows the token as Token/1.2 (the first digits of the product token, which ends at the next + /// delimiter), directly after a token that ends with its separator (Version/1.2, rv:11.0) or, if + /// is set, as Token 1.2 (MSIE 6.0, Opera 9.50, also with +). + /// + /// + /// The search continues behind the characters examined before, where no token can start; so every character is + /// examined a constant number of times, independent of the number of occurrences. + /// /// - private static bool TryReadVersionAfter(ReadOnlySpan ua, string token, int index, bool slashRequired, out Range version) + private static bool TryReadVersion(ReadOnlySpan ua, string token, int index, bool allowSpace, out Range version) { + bool separatorIncluded = token[^1] is '/' or ':'; do { int end = index + token.Length; int next = index + 1; - if (!slashRequired || (end < ua.Length && ua[end] == '/')) + if (separatorIncluded || (end < ua.Length && ua[end] == '/')) { if (TryExtractVersion(ua[end..], out Range range, out int productTokenLength)) { @@ -183,6 +203,23 @@ private static bool TryReadVersionAfter(ReadOnlySpan ua, string token, int next = end + productTokenLength; } + else if (allowSpace && end < ua.Length && IsSpace(ua[end])) + { + int versionStart = end + 1; + while (versionStart < ua.Length && IsSpace(ua[versionStart])) + { + versionStart++; + } + + if (versionStart < ua.Length && char.IsAsciiDigit(ua[versionStart])) + { + int length = ua[versionStart..].IndexOfAnyExcept(s_versionCharacters); + version = new Range(versionStart, length < 0 ? ua.Length : versionStart + length); + return true; + } + + next = versionStart; + } index = IndexOfTokenStart(ua, token, next); } @@ -192,6 +229,19 @@ private static bool TryReadVersionAfter(ReadOnlySpan ua, string token, int return false; } + /// + /// Returns whether a token at starts a token of its own (at the beginning or after a delimiter). + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool IsTokenStart(ReadOnlySpan ua, int index) + => index == 0 || s_productTokenDelimiters.Contains(ua[index - 1]); + + /// + /// Returns whether separates a product name from its version in Token 1.2 + /// (+ stands for a space in URL-encoded logs). + /// + private static bool IsSpace(char c) => c is ' ' or '\t' or '+'; + /// /// Returns the index of the first occurrence of at or after /// that starts a token (at the beginning or after a delimiter), or -1. @@ -207,7 +257,7 @@ private static int IndexOfTokenStart(ReadOnlySpan ua, string token, int st } int index = start + offset; - if (index == 0 || s_productTokenDelimiters.Contains(ua[index - 1])) + if (IsTokenStart(ua, index)) { return index; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 7cacc9c..1a92d36 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -33,20 +33,21 @@ internal static readonly (string Token, HttpUserAgentPlatformInformation Platfor ("windows nt 6.3", new(HttpUserAgentPlatformRegexId.WindowsNt63, "Windows 8.1", HttpUserAgentPlatformType.Windows)), ("windows nt 6.2", new(HttpUserAgentPlatformRegexId.WindowsNt62, "Windows 8", HttpUserAgentPlatformType.Windows)), ("windows nt 6.0", new(HttpUserAgentPlatformRegexId.WindowsNt60, "Windows Vista", HttpUserAgentPlatformType.Windows)), + // Windows Phone 8.1 and 10 user agents contain "Android" (and "iPhone"), so this comes first + ("windows phone", new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows)), // Android (very common on mobile) ("android", new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android)), // iOS devices (very common) ("iphone", new(HttpUserAgentPlatformRegexId.IPhone, "iOS", HttpUserAgentPlatformType.IOS)), ("ipad", new(HttpUserAgentPlatformRegexId.IPad, "iOS", HttpUserAgentPlatformType.IOS)), ("ipod", new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS)), - // ChromeOS (must be before "os x" to avoid false match with "CrOS") - ("cros", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), + // ChromeOS ("CrOS x86_64"), before "os x", which "CrOS x86_64" contains; with the space, "Microsoft" does not match + ("cros ", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), // Mac OS (common) ("os x", new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS)), // Linux (common) ("linux", new(HttpUserAgentPlatformRegexId.Linux, "Linux", HttpUserAgentPlatformType.Linux)), // Other Windows versions - ("windows phone", new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows)), ("windows nt 5.2", new(HttpUserAgentPlatformRegexId.WindowsNt52, "Windows 2003", HttpUserAgentPlatformType.Windows)), ("windows nt 5.1", new(HttpUserAgentPlatformRegexId.WindowsNt51, "Windows XP", HttpUserAgentPlatformType.Windows)), ("windows nt 5.0", new(HttpUserAgentPlatformRegexId.WindowsNt50, "Windows 2000", HttpUserAgentPlatformType.Windows)), @@ -110,7 +111,7 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) ("Firefox", "Firefox", null), ("Firefox", "FxiOS", null), // Internet Explorer (legacy but still in use - MSIE before Trident to avoid false matches) - ("Internet Explorer", "MSIE", "MSIE "), + ("Internet Explorer", "MSIE", "MSIE"), // "MSIE 6.0" ("Internet Explorer", "Trident", "rv:"), ("Internet Explorer", "Internet Explorer", null), // Less common browsers @@ -125,12 +126,15 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) ("Phoenix", "Phoenix", null), ("iCab", "icab", null), ("Lynx", "Lynx", null), + ("ELinks", "ELinks", null), ("Links", "Links", null), ("HotJava", "hotjava", null), ("Amaya", "amaya", null), ("IBrowse", "IBrowse", null), ("Apple iPod", "ipod touch", null), ("Ubuntu Web Browser", "Ubuntu", null), + // Headless Chrome (automation): last, it costs other browsers nothing there + ("Chrome", "HeadlessChrome", null), ]; /// @@ -234,7 +238,7 @@ internal static readonly (string Key, string Value)[] Robots = ( "MistralAI-User", "MistralAI-User" ), ( "DuckAssistBot", "DuckAssistBot" ), ( "AI2Bot", "AI2Bot" ), - ( "YouBot", "YouBot" ), + ( "YouBot/", "YouBot" ), // "YouBot" alone would match "ShowyouBot" ]; /// diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs new file mode 100644 index 0000000..722ad47 --- /dev/null +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs @@ -0,0 +1,87 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Diagnostics.Metrics; + +namespace MyCSharp.HttpUserAgentParser.Telemetry; + +/// +/// Prevents the core and the MemoryCache package from recording to the same . +/// +/// +/// Both packages create the instruments cache.hit, cache.miss and cache.size. On one meter, the counters +/// with the same name, unit and description are the same instrument, and exporters keep only one of the two gauges, so the +/// values of both packages would mix. The ASP.NET Core package has no instrument in common with them and may share a meter. +/// +internal static class HttpUserAgentParserCacheMeterGuard +{ + private const string CorePackage = "MyCSharp.HttpUserAgentParser"; + private const string MemoryCachePackage = "MyCSharp.HttpUserAgentParser.MemoryCache"; + +#if NET9_0_OR_GREATER + private static readonly Lock s_lock = new(); +#else + private static readonly object s_lock = new(); +#endif + + private static Meter? s_coreMeter; + private static Meter? s_memoryCacheMeter; + + /// + /// Records that the core package uses from now on. + /// + /// The MemoryCache package uses . + public static void UseForCore(Meter meter) + { + lock (s_lock) + { + ThrowIfUsed(meter, s_memoryCacheMeter, MemoryCachePackage); + s_coreMeter = meter; + } + } + + /// + /// Records that the MemoryCache package uses from now on. + /// + /// The core package uses . + public static void UseForMemoryCache(Meter meter) + { + lock (s_lock) + { + ThrowIfUsed(meter, s_coreMeter, CorePackage); + s_memoryCacheMeter = meter; + } + } + + /// + /// Forgets the meter of the core package (unit tests). + /// + public static void ResetCoreForTests() + { + lock (s_lock) + { + s_coreMeter = null; + } + } + + /// + /// Forgets the meter of the MemoryCache package (unit tests). + /// + public static void ResetMemoryCacheForTests() + { + lock (s_lock) + { + s_memoryCacheMeter = null; + } + } + + private static void ThrowIfUsed(Meter meter, Meter? meterOfOtherPackage, string otherPackage) + { + if (ReferenceEquals(meter, meterOfOtherPackage)) + { + throw new ArgumentException( + $"The meter '{meter.Name}' is already used by {otherPackage}. The core and the MemoryCache package both create the instruments " + + "cache.hit, cache.miss and cache.size, so each of them needs its own meter.", + nameof(meter)); + } + } +} diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterNameHelper.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterNameHelper.cs index df0e094..6fe1e9f 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterNameHelper.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterNameHelper.cs @@ -35,8 +35,8 @@ internal static class HttpUserAgentParserMeterNameHelper /// /// The fully composed meter name. /// - /// Thrown when is non-empty but either does not end with . - /// or contains non-alphanumeric characters (excluding the trailing dot). + /// Thrown when is non-empty but does not consist of at least one ASCII letter or digit + /// followed by .. /// public static string GetMeterName(string? meterPrefix, string meterNameSuffix) { @@ -51,17 +51,16 @@ public static string GetMeterName(string? meterPrefix, string meterNameSuffix) return meterNameSuffix; } - if (!meterPrefix.EndsWith('.')) + if (meterPrefix.Length < 2 || meterPrefix[^1] != '.') { - throw new ArgumentException("Meter prefix must end with '.'.", nameof(meterPrefix)); + throw new ArgumentException("Meter prefix must be ASCII letters or digits followed by '.', e.g. \"acme.\".", nameof(meterPrefix)); } for (int i = 0; i < meterPrefix.Length - 1; i++) { - char c = meterPrefix[i]; - if (!char.IsLetterOrDigit(c)) + if (!char.IsAsciiLetterOrDigit(meterPrefix[i])) { - throw new ArgumentException("Meter prefix must be alphanumeric.", nameof(meterPrefix)); + throw new ArgumentException("Meter prefix must be ASCII letters or digits followed by '.', e.g. \"acme.\".", nameof(meterPrefix)); } } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index 34a8979..6d092c9 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -31,7 +31,7 @@ internal static class HttpUserAgentParserMeters /// /// /// The prefix to use. When null, the default prefix is used. When empty, - /// no prefix is applied. Otherwise, the prefix must be alphanumeric and end with '.'. + /// no prefix is applied. Otherwise, the prefix must be ASCII letters or digits followed by '.'. /// /// The full meter name. /// Thrown when the prefix is not empty and does not match the required format. @@ -45,9 +45,9 @@ public static string GetMeterName(string? meterPrefix) #endif /// - /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. + /// The meters this class created (the default meter and meters with a prefixed name), by name. /// - private static Meter? s_ownedMeter; + private static readonly Dictionary s_ownedMeters = new(StringComparer.Ordinal); private static Instruments? s_instruments; @@ -78,7 +78,7 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on a meter named that this class creates and owns. /// /// - /// An owned meter is created once per name; it is disposed when another meter replaces it. + /// An owned meter is created once per name and reused when the name is registered again. /// public static void EnableOwnedMeter(string meterName) => Use(null, meterName); @@ -89,28 +89,19 @@ private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - Meter? previousOwnedMeter = s_ownedMeter; - if (meter is null) + // Own meters are created once per name and kept: a replaced meter is not disposed, so a measurement that read + // the previous instruments just before the switch is still recorded. Meters of the caller are never disposed. + if (meter is null && !s_ownedMeters.TryGetValue(ownedMeterName, out meter)) { - meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) - ? previousOwnedMeter - : new Meter(ownedMeterName); - s_ownedMeter = meter; - } - else - { - s_ownedMeter = null; + meter = new Meter(ownedMeterName); + s_ownedMeters.Add(ownedMeterName, meter); } + // The core and the MemoryCache package must not share a meter (same instrument names). + HttpUserAgentParserCacheMeterGuard.UseForCore(meter); + // Instruments are created once per meter and published only after all of them exist. Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); - - // A replaced owned meter is no longer used: dispose it, so repeated registrations do not keep meters alive. - // Meters passed in by the caller are never disposed. - if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) - { - previousOwnedMeter.Dispose(); - } } } @@ -146,8 +137,13 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - s_ownedMeter?.Dispose(); - s_ownedMeter = null; + foreach (Meter ownedMeter in s_ownedMeters.Values) + { + ownedMeter.Dispose(); + } + + s_ownedMeters.Clear(); + HttpUserAgentParserCacheMeterGuard.ResetCoreForTests(); s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index 6b24e48..12c1225 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -2,7 +2,8 @@ Fast HTTP User-Agent parsing for .NET. -- Allocation-free detection with vectorized `SearchValues` (only the version string is allocated), no regular expressions in the parser +- Allocation-free detection with vectorized searches (`SearchValues` on .NET 9+); for a user agent without surrounding + white space only the version string is allocated; no regular expressions in the parser - Trimming and Native AOT compatible - Detects the most used browsers and current search engine, SEO and AI crawlers @@ -27,7 +28,7 @@ HttpUserAgentInformation info = HttpUserAgentParser.Parse(userAgent); The parser itself does not execute regular expressions. `HttpUserAgentStatics.Platforms`, `HttpUserAgentStatics.Browsers` and `HttpUserAgentPlatformInformation.Regex` provide source-generated regular expressions (`[GeneratedRegex]`) for your own -matching; they are created on first access. They use `RegexOptions.IgnoreCase` with culture-invariant case mapping and +matching; the browser regexes are created when `HttpUserAgentStatics` is first used, a platform regex on first access. They use `RegexOptions.IgnoreCase` with culture-invariant case mapping and no `RegexOptions.Compiled`, because the source generator already emits the matching code. ## Native AOT @@ -109,7 +110,9 @@ services Pass your own `Meter` to `WithMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. -Meters the package creates itself (without argument or with a prefix) are created once per name and disposed when they are replaced. +Meters the package creates itself (without argument or with a prefix) are created once per name and reused. +The core and the MemoryCache package need separate meters (both create `cache.hit`, `cache.miss` and `cache.size`); passing the meter +of one to the other throws an `ArgumentException`. ### Meter + instruments diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index 35fbcd1..29638db 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -52,4 +52,28 @@ public void AddHttpUserAgentParserContextAccessor_Keeps_A_Registered_Accessor() Assert.IsType(provider.GetRequiredService()); Assert.IsType(provider.GetRequiredService()); } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void Accessor_Registrations_Are_Idempotent_In_Any_Order(bool contextAccessorFirst) + { + ServiceCollection services = new(); + HttpUserAgentParserDependencyInjectionOptions options = services.AddHttpUserAgentParser(); + + if (contextAccessorFirst) + { + options.AddHttpUserAgentParserContextAccessor().AddHttpUserAgentParserAccessor(); + } + else + { + options.AddHttpUserAgentParserAccessor().AddHttpUserAgentParserContextAccessor(); + } + + options.AddHttpUserAgentParserContextAccessor().AddHttpUserAgentParserAccessor(); + + using ServiceProvider provider = services.BuildServiceProvider(); + Assert.Single(provider.GetServices()); + Assert.Single(provider.GetServices()); + } } diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs index 65a2ce5..af7e5cb 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs @@ -32,4 +32,15 @@ public void Get(string userAgent) // verify _parserMock.Received(1).Parse(userAgent); } + + [Theory] + [InlineData("")] + [InlineData(" ")] + public void Get_Returns_Null_For_An_Empty_User_Agent(string userAgent) + { + HttpUserAgentParserAccessor accessor = new(_parserMock); + + Assert.Null(accessor.Get(HttpContextTestHelpers.GetHttpContext(userAgent))); + _parserMock.DidNotReceiveWithAnyArgs().Parse(default!); + } } diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs index 9e43707..5b01e80 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs @@ -107,34 +107,76 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() options.WithAspNetCoreMeterTelemetryPrefix("repeated."); } - Assert.Equal(1, CountLiveMeters("repeated.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), CountLiveMeters("repeated.http_user_agent_parser.aspnetcore")); } [Fact] - public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() + public void Own_Meters_Are_Reused_Per_Name_And_Meters_Of_The_Caller_Stay_Alive() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter callerMeter = new("caller.http_user_agent_parser.aspnetcore"); options.WithAspNetCoreMeterTelemetryPrefix("first."); options.WithAspNetCoreMeterTelemetryPrefix("second."); - Assert.Equal(0, CountLiveMeters("first.http_user_agent_parser.aspnetcore")); - Assert.Equal(1, CountLiveMeters("second.http_user_agent_parser.aspnetcore")); - + options.WithAspNetCoreMeterTelemetryPrefix("first."); // reuses the meter and the instruments of the first registration options.WithAspNetCoreMeterTelemetry(callerMeter); - Assert.Equal(0, CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + options.WithAspNetCoreMeterTelemetry(); + + Assert.Equal((1, 2), CountLiveMeters("first.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), CountLiveMeters("caller.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), CountLiveMeters("mycsharp.http_user_agent_parser.aspnetcore")); + } + + [Fact] + public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() + { + CancellationToken cancellationToken = TestContext.Current.CancellationToken; + long recorded = 0; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter.Name.StartsWith("switch.", StringComparison.Ordinal) + && string.Equals(instrument.Name, "user_agent.present", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + listener.SetMeasurementEventCallback((_, value, _, _) => Interlocked.Add(ref recorded, value)); + listener.Start(); + + HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter("switch.a"); + using CancellationTokenSource stop = new(TimeSpan.FromMilliseconds(300)); + Task switcher = Task.Run( + () => + { + for (int i = 0; !stop.IsCancellationRequested; i++) + { + HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter(i % 2 == 0 ? "switch.b" : "switch.a"); + } + }, + cancellationToken); + + long measurements = 0; + while (!stop.IsCancellationRequested) + { + HttpUserAgentParserAspNetCoreMeters.UserAgentPresent(); + measurements++; + } - options.WithAspNetCoreMeterTelemetry(); // the default meter replaces the meter of the caller - Assert.Equal(1, CountLiveMeters("caller.http_user_agent_parser.aspnetcore")); - Assert.Equal(1, CountLiveMeters("mycsharp.http_user_agent_parser.aspnetcore")); + await switcher; + Assert.Equal(measurements, Interlocked.Read(ref recorded)); } /// /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. /// - private static int CountLiveMeters(string meterName) + private static (int Meters, int Instruments) CountLiveMeters(string meterName) { HashSet meters = []; + int instruments = 0; using MeterListener listener = new() { InstrumentPublished = (instrument, _) => @@ -142,10 +184,11 @@ private static int CountLiveMeters(string meterName) if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) { meters.Add(instrument.Meter); + instruments++; } }, }; listener.Start(); - return meters.Count; + return (meters.Count, instruments); } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs index f26f865..93bfdb4 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs @@ -1,6 +1,11 @@ // Copyright © https://myCSharp.de - all rights reserved using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Primitives; +using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; +using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using MyCSharp.HttpUserAgentParser.Providers; using Xunit; namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; @@ -58,6 +63,70 @@ public void Keys_Are_Case_Sensitive() Assert.Equal(2, provider.CacheEntryCount); } + [Fact] + public void Entry_Size_Of_The_Options_Counts_Against_The_Size_Limit() + { + using HttpUserAgentParserMemoryCachedProvider sizeOne = new(new HttpUserAgentParserMemoryCachedProviderOptions(new MemoryCacheOptions { SizeLimit = 3 })); + using HttpUserAgentParserMemoryCachedProvider sizeTwo = new(new HttpUserAgentParserMemoryCachedProviderOptions( + new MemoryCacheOptions { SizeLimit = 3 }, new MemoryCacheEntryOptions { Size = 2 })); + + foreach (HttpUserAgentParserMemoryCachedProvider provider in new[] { sizeOne, sizeTwo }) + { + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Firefox/12"); + } + + Assert.Equal(2, sizeOne.CacheEntryCount); + Assert.InRange(sizeTwo.CacheEntryCount, 0, 1); // two entries of size 2 exceed the limit of 3 + } + + [Fact] + public void Expiration_Tokens_And_Eviction_Callbacks_Of_The_Options_Apply() + { + using CancellationTokenSource expire = new(); + int evicted = 0; + MemoryCacheEntryOptions entryOptions = new(); + entryOptions.ExpirationTokens.Add(new CancellationChangeToken(expire.Token)); + entryOptions.RegisterPostEvictionCallback((_, _, _, _) => Interlocked.Increment(ref evicted)); + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions(entryOptions)); + + HttpUserAgentInformation first = provider.Parse("Chrome/17"); + Assert.Same(first.Version, provider.Parse("Chrome/17").Version); // hit + + expire.Cancel(); + + Assert.NotSame(first.Version, provider.Parse("Chrome/17").Version); // expired: parsed again + Assert.True(SpinWait.SpinUntil(() => Volatile.Read(ref evicted) >= 1, TimeSpan.FromSeconds(10))); + } + + [Fact] + public void Dispose_Disposes_The_Cache_And_Removes_The_Provider_From_The_Cache_Size() + { + HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + _ = provider.Parse("Chrome/17"); + Assert.True(HttpUserAgentParserMemoryCacheTelemetryState.IsRegistered(provider)); + + provider.Dispose(); + provider.Dispose(); // a second call has no effect + + Assert.False(HttpUserAgentParserMemoryCacheTelemetryState.IsRegistered(provider)); + Assert.Throws(() => provider.Parse("Chrome/17")); + } + + [Fact] + public void The_Container_Disposes_The_Provider() + { + ServiceCollection services = new(); + services.AddHttpUserAgentMemoryCachedParser(); + ServiceProvider container = services.BuildServiceProvider(); + IHttpUserAgentParserProvider provider = container.GetRequiredService(); + _ = provider.Parse("Chrome/17"); + + container.Dispose(); + + Assert.Throws(() => provider.Parse("Chrome/17")); + } + private static void RunOnNewThread(Action action) { Thread thread = new(() => action()); diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index d601932..576a615 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -113,34 +113,76 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() options.WithMemoryCacheMeterTelemetryPrefix("repeated."); } - Assert.Equal(1, CountLiveMeters("repeated.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), CountLiveMeters("repeated.http_user_agent_parser.memorycache")); } [Fact] - public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() + public void Own_Meters_Are_Reused_Per_Name_And_Meters_Of_The_Caller_Stay_Alive() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter callerMeter = new("caller.http_user_agent_parser.memorycache"); options.WithMemoryCacheMeterTelemetryPrefix("first."); options.WithMemoryCacheMeterTelemetryPrefix("second."); - Assert.Equal(0, CountLiveMeters("first.http_user_agent_parser.memorycache")); - Assert.Equal(1, CountLiveMeters("second.http_user_agent_parser.memorycache")); - + options.WithMemoryCacheMeterTelemetryPrefix("first."); // reuses the meter and the instruments of the first registration options.WithMemoryCacheMeterTelemetry(callerMeter); - Assert.Equal(0, CountLiveMeters("second.http_user_agent_parser.memorycache")); + options.WithMemoryCacheMeterTelemetry(); - options.WithMemoryCacheMeterTelemetry(); // the default meter replaces the meter of the caller - Assert.Equal(1, CountLiveMeters("caller.http_user_agent_parser.memorycache")); - Assert.Equal(1, CountLiveMeters("mycsharp.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), CountLiveMeters("first.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), CountLiveMeters("second.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), CountLiveMeters("caller.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), CountLiveMeters("mycsharp.http_user_agent_parser.memorycache")); + } + + [Fact] + public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() + { + CancellationToken cancellationToken = TestContext.Current.CancellationToken; + long recorded = 0; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter.Name.StartsWith("switch.", StringComparison.Ordinal) + && string.Equals(instrument.Name, "cache.hit", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + listener.SetMeasurementEventCallback((_, value, _, _) => Interlocked.Add(ref recorded, value)); + listener.Start(); + + HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter("switch.a"); + using CancellationTokenSource stop = new(TimeSpan.FromMilliseconds(300)); + Task switcher = Task.Run( + () => + { + for (int i = 0; !stop.IsCancellationRequested; i++) + { + HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter(i % 2 == 0 ? "switch.b" : "switch.a"); + } + }, + cancellationToken); + + long measurements = 0; + while (!stop.IsCancellationRequested) + { + HttpUserAgentParserMemoryCacheMeters.CacheHit(); + measurements++; + } + + await switcher; + Assert.Equal(measurements, Interlocked.Read(ref recorded)); } /// /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. /// - private static int CountLiveMeters(string meterName) + private static (int Meters, int Instruments) CountLiveMeters(string meterName) { HashSet meters = []; + int instruments = 0; using MeterListener listener = new() { InstrumentPublished = (instrument, _) => @@ -148,10 +190,26 @@ private static int CountLiveMeters(string meterName) if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) { meters.Add(instrument.Meter); + instruments++; } }, }; listener.Start(); - return meters.Count; + return (meters.Count, instruments); + } + + [Fact] + public void A_Meter_Of_The_Core_Package_Is_Rejected() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + using Meter shared = new("test.memorycache.shared"); + using Meter coreMeter = new("test.memorycache.core"); + + options.WithMeterTelemetry(shared); + Assert.Throws(() => options.WithMemoryCacheMeterTelemetry(shared)); + + options.WithMeterTelemetry(coreMeter); // the core package moves to another meter + options.WithMemoryCacheMeterTelemetry(shared); + Assert.Throws(() => options.WithMeterTelemetry(shared)); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index a9d861c..622d32b 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -316,9 +316,24 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() [InlineData("Mozilla/5.0 Version/ XVersion/1.0 Version/17.0 Safari/604.1", "Safari", "17.0")] [InlineData("Version/17.0 Safari/604.1", "Safari", "17.0")] [InlineData("Opera/9.80 Vendor-Version/120.0", "Opera", "9.80")] - // Later occurrences only count at the start of a token; the first one may continue a word, as before + // Browser tokens only count at the start of a token [InlineData("ChromeHelper/1 MyChrome/2.0 Firefox/126.0", "Firefox", "126.0")] + [InlineData("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) MyChrome/2.0 Chrome/120.0.0.0 Safari/537.36", "Chrome", "120.0.0.0")] + [InlineData("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Knowledge/1.0", "Chrome", "120.0.0.0")] [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/120.0.6099.109 Safari/537.36", "Chrome", "120.0.6099.109")] + [InlineData("ELinks/0.12pre6 (textmode; Linux; 80x24-2)", "ELinks", "0.12")] + // "+" separates tokens like a space (URL-encoded logs, e.g. IIS) + [InlineData("Mozilla/5.0+(iPhone;+CPU+iPhone+OS+9_3_1+like+Mac+OS+X)+AppleWebKit/601.1.46+(KHTML,+like+Gecko)+Version/9.0+Mobile/13E238+Safari/601.1", "Safari", "9.0")] + [InlineData("Mozilla/5.0+(Windows+NT+10.0;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko", "Internet Explorer", "11.0")] + [InlineData("Opera/9.80+(Windows+NT+6.1;+WOW64)+Presto/2.12.388+Version/12.18", "Opera", "12.18")] + [InlineData("Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+6.1;+Trident/4.0)", "Internet Explorer", "8.0")] + // "Token 1.2" for rules with a version token + [InlineData("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", "Opera", "8.50")] + [InlineData("Mozilla/5.0 (Windows NT 6.0; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.51", "Opera", "9.51")] + [InlineData("LG-GD710/V10f; Mozilla/5.0 (Profile/MIDP-2.0 Configuration/CLDC-1.1; Opera Mini/att/4.2.14812; U; en) Opera 9.50", "Opera", "9.50")] + [InlineData("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", "Internet Explorer", "6.0")] + [InlineData("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", "Internet Explorer", "6.0")] + [InlineData("Mozilla/4.0 (compatible; MSIE MSIE 7.0; Windows NT 5.1)", "Internet Explorer", "7.0")] public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAgent, string expectedName, string expectedVersion) { (string Name, string? Version)? browser = HttpUserAgentParser.GetBrowser(userAgent); @@ -332,6 +347,10 @@ public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAge [InlineData("Mozilla/5.0 Firefox/(X11) 120")] [InlineData("Mozilla/5.0 VendorVersion/120.0 Safari/604.1")] [InlineData("Mozilla/5.0 Chrome/ Chrome")] + [InlineData("Checklinks/1.3 (pywikipedia robot; http://toolserver.org/~dispenser/view/Checklinks)")] + [InlineData("Mozilla/5.0 (compatible; TridentSpider/3.1)")] + [InlineData("Mozilla/5.0 Opera")] + [InlineData("Mozilla/4.0 (compatible; MSIE ")] public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userAgent) { Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); @@ -342,6 +361,8 @@ public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userA [InlineData("Chrome/a ")] // many product tokens [InlineData("Version/a")] [InlineData("Version/a ")] + [InlineData("MSIE ")] + [InlineData("Opera+a ")] public void GetBrowser_Time_Grows_Linearly_With_Repeated_Tokens(string repeated) { // A search that rescans the rest of the user agent for every occurrence needs seconds for 1,000,000 characters. @@ -362,4 +383,21 @@ public void GetBrowser_ExtractsAsciiVersion(string userAgent, string expectedVer { Assert.Equal(expectedVersion, HttpUserAgentParser.GetBrowser(userAgent)?.Version); } + + [Theory] + [InlineData("Microsoft Office/16.0 (Macintosh; Mac OS X 10.15.7; Microsoft Outlook 16.80.23121017; Pro)", "Mac OS X")] + [InlineData("Microsoft-CryptoAPI/10.0", null)] + [InlineData("Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "ChromeOS")] + [InlineData("Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15063", "Windows Phone")] + public void GetPlatform_Detects_ChromeOS_And_Windows_Phone_Only_By_Their_Own_Tokens(string userAgent, string? expectedPlatform) + { + Assert.Equal(expectedPlatform, HttpUserAgentParser.GetPlatform(userAgent)?.Name); + } + + [Fact] + public void GetRobot_Does_Not_Match_YouBot_Inside_Another_Name() + { + Assert.Null(HttpUserAgentParser.GetRobot("ShowyouBot (http://showyou.com/crawler)")); + Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; YouBot/1.0; +https://docs.you.com/youbot; env:prod) Chrome/X.X.X.X Safari/537.36")); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index e28ef8f..e0d7125 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -164,7 +164,9 @@ public void Parser_Platform_Rules_Resolve_The_Regex_Of_Their_Token() { foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { - Assert.Equal(Regex.Escape(token), platform.Regex.ToString()); + // The public pattern is the token; the parser token "cros " ends with a space, so "Microsoft" is no ChromeOS. + Assert.Equal(Regex.Escape(token.TrimEnd()), platform.Regex.ToString()); + Assert.Matches(platform.Regex, token); Assert.Contains(platform, HttpUserAgentStatics.Platforms); } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index 843fc74..6605814 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -116,6 +116,9 @@ public void WithMeterTelemetryPrefix_Throws_WhenInvalid() Assert.Throws(() => options.WithMeterTelemetryPrefix("acme")); Assert.Throws(() => options.WithMeterTelemetryPrefix("acme-")); Assert.Throws(() => options.WithMeterTelemetryPrefix("acme..")); + Assert.Throws(() => options.WithMeterTelemetryPrefix(".")); + Assert.Throws(() => options.WithMeterTelemetryPrefix("\u00E4.")); + Assert.Throws(() => options.WithMeterTelemetryPrefix("\uFF11.")); } [Fact] @@ -128,34 +131,76 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() options.WithMeterTelemetryPrefix("repeated."); } - Assert.Equal(1, CountLiveMeters("repeated.http_user_agent_parser")); + Assert.Equal((1, 5), CountLiveMeters("repeated.http_user_agent_parser")); } [Fact] - public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() + public void Own_Meters_Are_Reused_Per_Name_And_Meters_Of_The_Caller_Stay_Alive() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter callerMeter = new("caller.http_user_agent_parser"); options.WithMeterTelemetryPrefix("first."); options.WithMeterTelemetryPrefix("second."); - Assert.Equal(0, CountLiveMeters("first.http_user_agent_parser")); - Assert.Equal(1, CountLiveMeters("second.http_user_agent_parser")); - + options.WithMeterTelemetryPrefix("first."); // reuses the meter and the instruments of the first registration options.WithMeterTelemetry(callerMeter); - Assert.Equal(0, CountLiveMeters("second.http_user_agent_parser")); + options.WithMeterTelemetry(); - options.WithMeterTelemetry(); // the default meter replaces the meter of the caller - Assert.Equal(1, CountLiveMeters("caller.http_user_agent_parser")); - Assert.Equal(1, CountLiveMeters("mycsharp.http_user_agent_parser")); + Assert.Equal((1, 5), CountLiveMeters("first.http_user_agent_parser")); + Assert.Equal((1, 5), CountLiveMeters("second.http_user_agent_parser")); + Assert.Equal((1, 5), CountLiveMeters("caller.http_user_agent_parser")); + Assert.Equal((1, 5), CountLiveMeters("mycsharp.http_user_agent_parser")); + } + + [Fact] + public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() + { + CancellationToken cancellationToken = TestContext.Current.CancellationToken; + long recorded = 0; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter.Name.StartsWith("switch.", StringComparison.Ordinal) + && string.Equals(instrument.Name, "parse.requests", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + listener.SetMeasurementEventCallback((_, value, _, _) => Interlocked.Add(ref recorded, value)); + listener.Start(); + + HttpUserAgentParserMeters.EnableOwnedMeter("switch.a"); + using CancellationTokenSource stop = new(TimeSpan.FromMilliseconds(300)); + Task switcher = Task.Run( + () => + { + for (int i = 0; !stop.IsCancellationRequested; i++) + { + HttpUserAgentParserMeters.EnableOwnedMeter(i % 2 == 0 ? "switch.b" : "switch.a"); + } + }, + cancellationToken); + + long measurements = 0; + while (!stop.IsCancellationRequested) + { + HttpUserAgentParserMeters.ParseRequest(); + measurements++; + } + + await switcher; + Assert.Equal(measurements, Interlocked.Read(ref recorded)); } /// /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. /// - private static int CountLiveMeters(string meterName) + private static (int Meters, int Instruments) CountLiveMeters(string meterName) { HashSet meters = []; + int instruments = 0; using MeterListener listener = new() { InstrumentPublished = (instrument, _) => @@ -163,10 +208,44 @@ private static int CountLiveMeters(string meterName) if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) { meters.Add(instrument.Meter); + instruments++; } }, }; listener.Start(); - return meters.Count; + return (meters.Count, instruments); + } + + [Fact] + public void Core_And_MemoryCache_Cannot_Share_A_Meter() + { + using Meter shared = new("test.guard.shared"); + using Meter other = new("test.guard.other"); + using Meter third = new("test.guard.third"); + + HttpUserAgentParserCacheMeterGuard.UseForCore(shared); + Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(shared)); + + HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(other); + Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.UseForCore(other)); + + // The core package moves to another meter, so the MemoryCache package may use the first one. + HttpUserAgentParserCacheMeterGuard.UseForCore(third); + HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(shared); + + HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); + } + + [Fact] + public void WithMeterTelemetry_Rejects_The_Meter_Of_The_MemoryCache_Package() + { + using Meter shared = new("test.guard.memorycache"); + HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(shared); + + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + Assert.Throws(() => options.WithMeterTelemetry(shared)); + Assert.False(HttpUserAgentParserTelemetry.IsEnabled); + + HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); } } From eeaf4f5af476f365dea42c69ebaf47e248860f7b Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 20:16:38 +0100 Subject: [PATCH 08/41] fix: reserve cache meters for their lifetime, dispose replaced own meters Telemetry - A meter that the core or the MemoryCache package has used stays reserved for it while the meter lives: both create cache.hit, cache.miss and cache.size, and a meter keeps its instruments, so a handover after a switch mixed the series. The reservation is made before the instruments are created, which also covers a registration from a listener callback and a listener that throws. - If a listener throws while instruments are published, the meter in use stays active and a new own meter is disposed. - A replaced own meter (default or prefix) is disposed again, so changing prefixes keeps one meter; measurements racing with that switch are best effort. Meters of the caller are never disposed. Parser - The version tokens of Opera ("Version/") and Internet Explorer ("rv:") only count after the browser token. - ChromeOS: "cros+" for URL-encoded logs next to "cros ". - Robot key " YouBot/" so "ShowyouBot/1.0" is no YouBot. --- README.md | 4 +- .../HttpUserAgentParserAspNetCoreMeters.cs | 50 ++++++--- src/HttpUserAgentParser.AspNetCore/readme.md | 3 +- .../HttpUserAgentParserMemoryCacheMeters.cs | 52 ++++++--- src/HttpUserAgentParser.MemoryCache/readme.md | 7 +- .../HttpUserAgentParser.cs | 6 +- src/HttpUserAgentParser/HttpUserAgentRules.cs | 3 +- .../HttpUserAgentParserCacheMeterGuard.cs | 60 +++++------ .../Telemetry/HttpUserAgentParserMeters.cs | 52 ++++++--- src/HttpUserAgentParser/readme.md | 7 +- ...entParserAspNetCoreMetersTelemetryTests.cs | 67 ++++++++++-- ...ntParserMemoryCacheMetersTelemetryTests.cs | 102 +++++++++++++++--- .../HttpUserAgentParserTests.cs | 5 + .../HttpUserAgentStaticsTests.cs | 4 +- ...HttpUserAgentParserMetersTelemetryTests.cs | 84 ++++++++++++--- 15 files changed, 372 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index dd77d95..c076587 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ If you only need the raw header value, use `httpContext.GetUserAgentString()`. 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) 4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Yandex Browser, UC Browser and others -In every list the first matching entry wins. Browser and version tokens only count at the start of a token: at the beginning of the user agent or after a space, tab, `+`, `;`, `(`, `)` or `,`, so `Knowledge/1.0` is no Edge and `VendorVersion/1.0` no version token. The version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next of these characters; Opera and Internet Explorer also accept `Opera 9.50` and `MSIE 6.0`. If a token has no version, later occurrences of the token are checked, then the next rule. `+` stands for a space as in URL-encoded logs (IIS); decode other encodings such as `%20` before parsing, e.g. with `WebUtility.UrlDecode`. +In every list the first matching entry wins. Browser and version tokens only count at the start of a token: at the beginning of the user agent or after a space, tab, `+`, `;`, `(`, `)` or `,`, so `Knowledge/1.0` is no Edge and `VendorVersion/1.0` no version token. The version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next of these characters; Opera and Internet Explorer also accept `Opera 9.50` and `MSIE 6.0`; their separate version tokens (`Version/`, `rv:`) only count after the browser token. If a token has no version, later occurrences of the token are checked, then the next rule. `+` stands for a space as in URL-encoded logs (IIS); decode other encodings such as `%20` before parsing, e.g. with `WebUtility.UrlDecode`. Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome, as is Headless Chrome; iPadOS sends the macOS user agent by default. @@ -286,7 +286,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The package creates its own meters (without argument or with a prefix) once per name and reuses them; meters you pass in are never disposed. The core and the MemoryCache package need separate meters, because both create the instruments `cache.hit`, `cache.miss` and `cache.size`; passing the meter that one of them uses to the other throws an `ArgumentException`. The ASP.NET Core package may share a meter with either. +Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another meter replaces it; a measurement that runs exactly during that switch may be lost. Meters you pass in are never disposed. The core and the MemoryCache package need separate meters, because both create the instruments `cache.hit`, `cache.miss` and `cache.size`, and a meter keeps its instruments until it is disposed: a meter that one of them has used is rejected by the other with an `ArgumentException`, also after a switch. The ASP.NET Core package may share a meter with either. ### Meter names and instruments diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 308dd3c..49cbf17 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -44,9 +44,9 @@ public static string GetMeterName(string? meterPrefix) #endif /// - /// The meters this class created (the default meter and meters with a prefixed name), by name. + /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. /// - private static readonly Dictionary s_ownedMeters = new(StringComparer.Ordinal); + private static Meter? s_ownedMeter; private static Instruments? s_instruments; @@ -71,7 +71,7 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on a meter named that this class creates and owns. /// /// - /// An owned meter is created once per name and reused when the name is registered again. + /// The owned meter is reused for the same name; it is disposed when another meter replaces it. /// public static void EnableOwnedMeter(string meterName) => Use(null, meterName); @@ -82,16 +82,38 @@ private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - // Own meters are created once per name and kept: a replaced meter is not disposed, so a measurement that read - // the previous instruments just before the switch is still recorded. Meters of the caller are never disposed. - if (meter is null && !s_ownedMeters.TryGetValue(ownedMeterName, out meter)) + Meter? previousOwnedMeter = s_ownedMeter; + bool own = meter is null; + if (meter is null) { - meter = new Meter(ownedMeterName); - s_ownedMeters.Add(ownedMeterName, meter); + // Own meters: the current one is reused for the same name, another name gets a new meter. + meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) + ? previousOwnedMeter + : new Meter(ownedMeterName); } - // Instruments are created once per meter and published only after all of them exist. - Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); + Instruments instruments; + try + { + // Instruments are created once per meter; a listener may throw while they are published. + instruments = s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m)); + } + catch when (own && !ReferenceEquals(meter, previousOwnedMeter)) + { + meter.Dispose(); + throw; + } + + // Published only after all instruments exist. + Volatile.Write(ref s_instruments, instruments); + s_ownedMeter = own ? meter : null; + + // A replaced own meter is disposed, so changing names does not keep meters alive. A measurement that read its + // instruments just before the switch may be lost (best effort); meters of the caller are never disposed. + if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) + { + previousOwnedMeter.Dispose(); + } } } @@ -117,12 +139,8 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - foreach (Meter ownedMeter in s_ownedMeters.Values) - { - ownedMeter.Dispose(); - } - - s_ownedMeters.Clear(); + s_ownedMeter?.Dispose(); + s_ownedMeter = null; s_instrumentsByMeter.Clear(); } } diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index 8c04cd0..ff35298 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -101,7 +101,8 @@ services Pass your own `Meter` to `WithAspNetCoreMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. -Meters the package creates itself (without argument or with a prefix) are created once per name and reused. +The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another +meter replaces it; a measurement that runs exactly during that switch may be lost. Meters you pass in are never disposed. ### Meter + instruments diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index a601233..95928c4 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -39,9 +39,9 @@ public static string GetMeterName(string? meterPrefix) #endif /// - /// The meters this class created (the default meter and meters with a prefixed name), by name. + /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. /// - private static readonly Dictionary s_ownedMeters = new(StringComparer.Ordinal); + private static Meter? s_ownedMeter; private static Instruments? s_instruments; @@ -64,7 +64,7 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on a meter named that this class creates and owns. /// /// - /// An owned meter is created once per name and reused when the name is registered again. + /// The owned meter is reused for the same name; it is disposed when another meter replaces it. /// public static void EnableOwnedMeter(string meterName) => Use(null, meterName); @@ -75,19 +75,41 @@ private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - // Own meters are created once per name and kept: a replaced meter is not disposed, so a measurement that read - // the previous instruments just before the switch is still recorded. Meters of the caller are never disposed. - if (meter is null && !s_ownedMeters.TryGetValue(ownedMeterName, out meter)) + Meter? previousOwnedMeter = s_ownedMeter; + bool own = meter is null; + if (meter is null) { - meter = new Meter(ownedMeterName); - s_ownedMeters.Add(ownedMeterName, meter); + // Own meters: the current one is reused for the same name, another name gets a new meter. + meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) + ? previousOwnedMeter + : new Meter(ownedMeterName); } // The core and the MemoryCache package must not share a meter (same instrument names). - HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(meter); + HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache(meter); - // Instruments are created once per meter and published only after all of them exist. - Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); + Instruments instruments; + try + { + // Instruments are created once per meter; a listener may throw while they are published. + instruments = s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m)); + } + catch when (own && !ReferenceEquals(meter, previousOwnedMeter)) + { + meter.Dispose(); + throw; + } + + // Published only after all instruments exist. + Volatile.Write(ref s_instruments, instruments); + s_ownedMeter = own ? meter : null; + + // A replaced own meter is disposed, so changing names does not keep meters alive. A measurement that read its + // instruments just before the switch may be lost (best effort); meters of the caller are never disposed. + if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) + { + previousOwnedMeter.Dispose(); + } } } @@ -102,12 +124,8 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - foreach (Meter ownedMeter in s_ownedMeters.Values) - { - ownedMeter.Dispose(); - } - - s_ownedMeters.Clear(); + s_ownedMeter?.Dispose(); + s_ownedMeter = null; HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); s_instrumentsByMeter.Clear(); } diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/readme.md index 0163d97..f64ced1 100644 --- a/src/HttpUserAgentParser.MemoryCache/readme.md +++ b/src/HttpUserAgentParser.MemoryCache/readme.md @@ -105,9 +105,10 @@ services Pass your own `Meter` to `WithMemoryCacheMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. -Meters the package creates itself (without argument or with a prefix) are created once per name and reused. -The core and the MemoryCache package need separate meters (both create `cache.hit`, `cache.miss` and `cache.size`); passing the meter -of one to the other throws an `ArgumentException`. +The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another +meter replaces it; a measurement that runs exactly during that switch may be lost. Meters you pass in are never disposed. +The core and the MemoryCache package need separate meters (both create `cache.hit`, `cache.miss` and `cache.size`, and a meter keeps +its instruments): a meter that one of them has used is rejected by the other with an `ArgumentException`, also after a switch. ### Meter + instruments diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 3bae4f0..ad2deb1 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -157,11 +157,11 @@ private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectTo return TryReadVersion(ua, detectToken, detectIndex, allowSpace: false, out version); } - // A separate version token ("Version/1.2", "rv:11.0"); with the same token as the detect token (Safari "Version/", - // "MSIE 6.0") the detect token has been found already. + // A separate version token after the detect token ("Opera/9.80 ... Version/12.16", "Trident/7.0; rv:11.0"); with the same + // token as the detect token (Safari "Version/", "MSIE 6.0") the detect token has been found already. int versionIndex = string.Equals(detectToken, versionToken, StringComparison.Ordinal) ? detectIndex - : IndexOfTokenStart(ua, versionToken, 0); + : IndexOfTokenStart(ua, versionToken, detectIndex + detectToken.Length); if (versionIndex >= 0) { return TryReadVersion(ua, versionToken, versionIndex, allowSpace: true, out version); diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 1a92d36..5c586f4 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -43,6 +43,7 @@ internal static readonly (string Token, HttpUserAgentPlatformInformation Platfor ("ipod", new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS)), // ChromeOS ("CrOS x86_64"), before "os x", which "CrOS x86_64" contains; with the space, "Microsoft" does not match ("cros ", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), + ("cros+", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), // URL-encoded logs // Mac OS (common) ("os x", new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS)), // Linux (common) @@ -238,7 +239,7 @@ internal static readonly (string Key, string Value)[] Robots = ( "MistralAI-User", "MistralAI-User" ), ( "DuckAssistBot", "DuckAssistBot" ), ( "AI2Bot", "AI2Bot" ), - ( "YouBot/", "YouBot" ), // "YouBot" alone would match "ShowyouBot" + ( " YouBot/", "YouBot" ), // "YouBot/" alone would match "ShowyouBot/1.0" ]; /// diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs index 722ad47..6bafc63 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs @@ -1,6 +1,7 @@ // Copyright © https://myCSharp.de - all rights reserved using System.Diagnostics.Metrics; +using System.Runtime.CompilerServices; namespace MyCSharp.HttpUserAgentParser.Telemetry; @@ -10,7 +11,8 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// /// Both packages create the instruments cache.hit, cache.miss and cache.size. On one meter, the counters /// with the same name, unit and description are the same instrument, and exporters keep only one of the two gauges, so the -/// values of both packages would mix. The ASP.NET Core package has no instrument in common with them and may share a meter. +/// values of both packages would mix. The ASP.NET Core package has no instrument in common with them and may share a meter. A meter that one of the two packages +/// has used stays reserved for it, also after a switch to another meter, because its instruments remain on the meter. /// internal static class HttpUserAgentParserCacheMeterGuard { @@ -23,65 +25,57 @@ internal static class HttpUserAgentParserCacheMeterGuard private static readonly object s_lock = new(); #endif - private static Meter? s_coreMeter; - private static Meter? s_memoryCacheMeter; + // A meter keeps its instruments until it is disposed, so a reservation lasts as long as the meter (held weakly). + private static readonly ConditionalWeakTable s_coreMeters = new(); + private static readonly ConditionalWeakTable s_memoryCacheMeters = new(); /// - /// Records that the core package uses from now on. + /// Reserves for the core package before it creates its instruments on it. /// - /// The MemoryCache package uses . - public static void UseForCore(Meter meter) - { - lock (s_lock) - { - ThrowIfUsed(meter, s_memoryCacheMeter, MemoryCachePackage); - s_coreMeter = meter; - } - } + /// The MemoryCache package has used . + public static void ReserveForCore(Meter meter) => Reserve(meter, s_coreMeters, s_memoryCacheMeters, MemoryCachePackage); /// - /// Records that the MemoryCache package uses from now on. + /// Reserves for the MemoryCache package before it creates its instruments on it. /// - /// The core package uses . - public static void UseForMemoryCache(Meter meter) - { - lock (s_lock) - { - ThrowIfUsed(meter, s_coreMeter, CorePackage); - s_memoryCacheMeter = meter; - } - } + /// The core package has used . + public static void ReserveForMemoryCache(Meter meter) => Reserve(meter, s_memoryCacheMeters, s_coreMeters, CorePackage); /// - /// Forgets the meter of the core package (unit tests). + /// Forgets the reservations of the core package (unit tests). /// public static void ResetCoreForTests() { lock (s_lock) { - s_coreMeter = null; + s_coreMeters.Clear(); } } /// - /// Forgets the meter of the MemoryCache package (unit tests). + /// Forgets the reservations of the MemoryCache package (unit tests). /// public static void ResetMemoryCacheForTests() { lock (s_lock) { - s_memoryCacheMeter = null; + s_memoryCacheMeters.Clear(); } } - private static void ThrowIfUsed(Meter meter, Meter? meterOfOtherPackage, string otherPackage) + private static void Reserve(Meter meter, ConditionalWeakTable reservations, ConditionalWeakTable otherReservations, string otherPackage) { - if (ReferenceEquals(meter, meterOfOtherPackage)) + lock (s_lock) { - throw new ArgumentException( - $"The meter '{meter.Name}' is already used by {otherPackage}. The core and the MemoryCache package both create the instruments " - + "cache.hit, cache.miss and cache.size, so each of them needs its own meter.", - nameof(meter)); + if (otherReservations.TryGetValue(meter, out _)) + { + throw new ArgumentException( + $"The meter '{meter.Name}' is used by {otherPackage}. The core and the MemoryCache package both create the instruments " + + "cache.hit, cache.miss and cache.size, and a meter keeps them until it is disposed, so each package needs its own meter.", + nameof(meter)); + } + + reservations.AddOrUpdate(meter, null); } } } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index 6d092c9..96df187 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -45,9 +45,9 @@ public static string GetMeterName(string? meterPrefix) #endif /// - /// The meters this class created (the default meter and meters with a prefixed name), by name. + /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. /// - private static readonly Dictionary s_ownedMeters = new(StringComparer.Ordinal); + private static Meter? s_ownedMeter; private static Instruments? s_instruments; @@ -78,7 +78,7 @@ public static string GetMeterName(string? meterPrefix) /// Creates the metric instruments on a meter named that this class creates and owns. /// /// - /// An owned meter is created once per name and reused when the name is registered again. + /// The owned meter is reused for the same name; it is disposed when another meter replaces it. /// public static void EnableOwnedMeter(string meterName) => Use(null, meterName); @@ -89,19 +89,41 @@ private static void Use(Meter? meter, string ownedMeterName) { lock (s_lock) { - // Own meters are created once per name and kept: a replaced meter is not disposed, so a measurement that read - // the previous instruments just before the switch is still recorded. Meters of the caller are never disposed. - if (meter is null && !s_ownedMeters.TryGetValue(ownedMeterName, out meter)) + Meter? previousOwnedMeter = s_ownedMeter; + bool own = meter is null; + if (meter is null) { - meter = new Meter(ownedMeterName); - s_ownedMeters.Add(ownedMeterName, meter); + // Own meters: the current one is reused for the same name, another name gets a new meter. + meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) + ? previousOwnedMeter + : new Meter(ownedMeterName); } // The core and the MemoryCache package must not share a meter (same instrument names). - HttpUserAgentParserCacheMeterGuard.UseForCore(meter); + HttpUserAgentParserCacheMeterGuard.ReserveForCore(meter); - // Instruments are created once per meter and published only after all of them exist. - Volatile.Write(ref s_instruments, s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m))); + Instruments instruments; + try + { + // Instruments are created once per meter; a listener may throw while they are published. + instruments = s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m)); + } + catch when (own && !ReferenceEquals(meter, previousOwnedMeter)) + { + meter.Dispose(); + throw; + } + + // Published only after all instruments exist. + Volatile.Write(ref s_instruments, instruments); + s_ownedMeter = own ? meter : null; + + // A replaced own meter is disposed, so changing names does not keep meters alive. A measurement that read its + // instruments just before the switch may be lost (best effort); meters of the caller are never disposed. + if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) + { + previousOwnedMeter.Dispose(); + } } } @@ -137,12 +159,8 @@ public static void ResetForTests() lock (s_lock) { Volatile.Write(ref s_instruments, null); - foreach (Meter ownedMeter in s_ownedMeters.Values) - { - ownedMeter.Dispose(); - } - - s_ownedMeters.Clear(); + s_ownedMeter?.Dispose(); + s_ownedMeter = null; HttpUserAgentParserCacheMeterGuard.ResetCoreForTests(); s_instrumentsByMeter.Clear(); } diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index 12c1225..60a0b81 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -110,9 +110,10 @@ services Pass your own `Meter` to `WithMeterTelemetry(meter)` to record to it. A later registration with another meter replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. -Meters the package creates itself (without argument or with a prefix) are created once per name and reused. -The core and the MemoryCache package need separate meters (both create `cache.hit`, `cache.miss` and `cache.size`); passing the meter -of one to the other throws an `ArgumentException`. +The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another +meter replaces it; a measurement that runs exactly during that switch may be lost. Meters you pass in are never disposed. +The core and the MemoryCache package need separate meters (both create `cache.hit`, `cache.miss` and `cache.size`, and a meter keeps +its instruments): a meter that one of them has used is rejected by the other with an `ArgumentException`, also after a switch. ### Meter + instruments diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs index 5b01e80..43c49c5 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs @@ -111,27 +111,78 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() } [Fact] - public void Own_Meters_Are_Reused_Per_Name_And_Meters_Of_The_Caller_Stay_Alive() + public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter callerMeter = new("caller.http_user_agent_parser.aspnetcore"); options.WithAspNetCoreMeterTelemetryPrefix("first."); + options.WithAspNetCoreMeterTelemetryPrefix("first."); // the meter in use: kept + Assert.Equal((1, 2), CountLiveMeters("first.http_user_agent_parser.aspnetcore")); + options.WithAspNetCoreMeterTelemetryPrefix("second."); - options.WithAspNetCoreMeterTelemetryPrefix("first."); // reuses the meter and the instruments of the first registration + Assert.Equal((0, 0), CountLiveMeters("first.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + options.WithAspNetCoreMeterTelemetry(callerMeter); - options.WithAspNetCoreMeterTelemetry(); + Assert.Equal((0, 0), CountLiveMeters("second.http_user_agent_parser.aspnetcore")); - Assert.Equal((1, 2), CountLiveMeters("first.http_user_agent_parser.aspnetcore")); - Assert.Equal((1, 2), CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + options.WithAspNetCoreMeterTelemetry(); // the default meter replaces the meter of the caller Assert.Equal((1, 2), CountLiveMeters("caller.http_user_agent_parser.aspnetcore")); Assert.Equal((1, 2), CountLiveMeters("mycsharp.http_user_agent_parser.aspnetcore")); } [Fact] - public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() + public void Changing_Prefixes_Keep_Only_The_Meter_In_Use() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + for (int i = 0; i < 32; i++) + { + options.WithAspNetCoreMeterTelemetryPrefix($"changing{i}."); + } + + for (int i = 0; i < 31; i++) + { + Assert.Equal((0, 0), CountLiveMeters($"changing{i}.http_user_agent_parser.aspnetcore")); + } + + Assert.Equal((1, 2), CountLiveMeters("changing31.http_user_agent_parser.aspnetcore")); + } + + [Fact] + public void A_Throwing_Listener_Keeps_The_Meter_In_Use() + { + using Meter first = new("throwing.first"); + using Meter second = new("throwing.second"); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (instrument.Meter.Name.StartsWith("throwing.", StringComparison.Ordinal) && !ReferenceEquals(instrument.Meter, first)) + { + throw new InvalidOperationException("listener failure"); + } + }, + }; + listener.Start(); + + HttpUserAgentParserAspNetCoreMeters.Enable(first); + Assert.Throws(() => HttpUserAgentParserAspNetCoreMeters.Enable(second)); + Assert.Throws(() => HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter("throwing.own")); + Assert.Equal((0, 0), CountLiveMeters("throwing.own")); // the new own meter is disposed again + + using MeterTestListener recorder = new("throwing.first"); + HttpUserAgentParserAspNetCoreMeters.UserAgentPresent(); + Assert.Equal(new[] { "user_agent.present" }, recorder.InstrumentNames, StringComparer.Ordinal); + } + + [Fact] + public async Task No_Measurement_Is_Lost_While_Meters_Of_The_Caller_Are_Switched() { CancellationToken cancellationToken = TestContext.Current.CancellationToken; + using Meter a = new("switch.a"); + using Meter b = new("switch.b"); long recorded = 0; using MeterListener listener = new() { @@ -147,14 +198,14 @@ public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() listener.SetMeasurementEventCallback((_, value, _, _) => Interlocked.Add(ref recorded, value)); listener.Start(); - HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter("switch.a"); + HttpUserAgentParserAspNetCoreMeters.Enable(a); using CancellationTokenSource stop = new(TimeSpan.FromMilliseconds(300)); Task switcher = Task.Run( () => { for (int i = 0; !stop.IsCancellationRequested; i++) { - HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter(i % 2 == 0 ? "switch.b" : "switch.a"); + HttpUserAgentParserAspNetCoreMeters.Enable(i % 2 == 0 ? b : a); } }, cancellationToken); diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index 576a615..3d43184 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -117,27 +117,78 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() } [Fact] - public void Own_Meters_Are_Reused_Per_Name_And_Meters_Of_The_Caller_Stay_Alive() + public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter callerMeter = new("caller.http_user_agent_parser.memorycache"); options.WithMemoryCacheMeterTelemetryPrefix("first."); + options.WithMemoryCacheMeterTelemetryPrefix("first."); // the meter in use: kept + Assert.Equal((1, 3), CountLiveMeters("first.http_user_agent_parser.memorycache")); + options.WithMemoryCacheMeterTelemetryPrefix("second."); - options.WithMemoryCacheMeterTelemetryPrefix("first."); // reuses the meter and the instruments of the first registration + Assert.Equal((0, 0), CountLiveMeters("first.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), CountLiveMeters("second.http_user_agent_parser.memorycache")); + options.WithMemoryCacheMeterTelemetry(callerMeter); - options.WithMemoryCacheMeterTelemetry(); + Assert.Equal((0, 0), CountLiveMeters("second.http_user_agent_parser.memorycache")); - Assert.Equal((1, 3), CountLiveMeters("first.http_user_agent_parser.memorycache")); - Assert.Equal((1, 3), CountLiveMeters("second.http_user_agent_parser.memorycache")); + options.WithMemoryCacheMeterTelemetry(); // the default meter replaces the meter of the caller Assert.Equal((1, 3), CountLiveMeters("caller.http_user_agent_parser.memorycache")); Assert.Equal((1, 3), CountLiveMeters("mycsharp.http_user_agent_parser.memorycache")); } [Fact] - public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() + public void Changing_Prefixes_Keep_Only_The_Meter_In_Use() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + for (int i = 0; i < 32; i++) + { + options.WithMemoryCacheMeterTelemetryPrefix($"changing{i}."); + } + + for (int i = 0; i < 31; i++) + { + Assert.Equal((0, 0), CountLiveMeters($"changing{i}.http_user_agent_parser.memorycache")); + } + + Assert.Equal((1, 3), CountLiveMeters("changing31.http_user_agent_parser.memorycache")); + } + + [Fact] + public void A_Throwing_Listener_Keeps_The_Meter_In_Use() + { + using Meter first = new("throwing.first"); + using Meter second = new("throwing.second"); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (instrument.Meter.Name.StartsWith("throwing.", StringComparison.Ordinal) && !ReferenceEquals(instrument.Meter, first)) + { + throw new InvalidOperationException("listener failure"); + } + }, + }; + listener.Start(); + + HttpUserAgentParserMemoryCacheMeters.Enable(first); + Assert.Throws(() => HttpUserAgentParserMemoryCacheMeters.Enable(second)); + Assert.Throws(() => HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter("throwing.own")); + Assert.Equal((0, 0), CountLiveMeters("throwing.own")); // the new own meter is disposed again + + using MeterTestListener recorder = new("throwing.first"); + HttpUserAgentParserMemoryCacheMeters.CacheHit(); + Assert.Equal(new[] { "cache.hit" }, recorder.InstrumentNames, StringComparer.Ordinal); + } + + [Fact] + public async Task No_Measurement_Is_Lost_While_Meters_Of_The_Caller_Are_Switched() { CancellationToken cancellationToken = TestContext.Current.CancellationToken; + using Meter a = new("switch.a"); + using Meter b = new("switch.b"); long recorded = 0; using MeterListener listener = new() { @@ -153,14 +204,14 @@ public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() listener.SetMeasurementEventCallback((_, value, _, _) => Interlocked.Add(ref recorded, value)); listener.Start(); - HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter("switch.a"); + HttpUserAgentParserMemoryCacheMeters.Enable(a); using CancellationTokenSource stop = new(TimeSpan.FromMilliseconds(300)); Task switcher = Task.Run( () => { for (int i = 0; !stop.IsCancellationRequested; i++) { - HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter(i % 2 == 0 ? "switch.b" : "switch.a"); + HttpUserAgentParserMemoryCacheMeters.Enable(i % 2 == 0 ? b : a); } }, cancellationToken); @@ -199,17 +250,44 @@ private static (int Meters, int Instruments) CountLiveMeters(string meterName) } [Fact] - public void A_Meter_Of_The_Core_Package_Is_Rejected() + public void A_Meter_Of_The_Core_Package_Is_Rejected_Also_After_A_Switch() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter shared = new("test.memorycache.shared"); using Meter coreMeter = new("test.memorycache.core"); + using Meter memoryCacheMeter = new("test.memorycache.own"); options.WithMeterTelemetry(shared); Assert.Throws(() => options.WithMemoryCacheMeterTelemetry(shared)); - options.WithMeterTelemetry(coreMeter); // the core package moves to another meter - options.WithMemoryCacheMeterTelemetry(shared); - Assert.Throws(() => options.WithMeterTelemetry(shared)); + // The core instruments remain on the shared meter, so it stays reserved after the core package moved on. + options.WithMeterTelemetry(coreMeter); + Assert.Throws(() => options.WithMemoryCacheMeterTelemetry(shared)); + + options.WithMemoryCacheMeterTelemetry(memoryCacheMeter); + Assert.Throws(() => options.WithMeterTelemetry(memoryCacheMeter)); + } + + [Fact] + public void A_Nested_Registration_While_The_Core_Instruments_Are_Published_Is_Rejected() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + using Meter shared = new("test.memorycache.nested"); + Exception? nested = null; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (ReferenceEquals(instrument.Meter, shared) && string.Equals(instrument.Name, "parse.requests", StringComparison.Ordinal)) + { + nested = Record.Exception(() => options.WithMemoryCacheMeterTelemetry(shared)); + } + }, + }; + listener.Start(); + + options.WithMeterTelemetry(shared); + + Assert.IsType(nested); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 622d32b..69b3dff 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -313,6 +313,9 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() [InlineData("Mozilla/5.0 Version/ Mobile Version/17.0 Safari/604.1", "Safari", "17.0")] // A version token inside another word belongs to another product [InlineData("Opera/9.80 VendorVersion/120.0", "Opera", "9.80")] + // A version token only counts after the browser token + [InlineData("Version/99.0 Opera/9.80 Version/12.16", "Opera", "12.16")] + [InlineData("rv:99.0; Trident/7.0; rv:11.0", "Internet Explorer", "11.0")] [InlineData("Mozilla/5.0 Version/ XVersion/1.0 Version/17.0 Safari/604.1", "Safari", "17.0")] [InlineData("Version/17.0 Safari/604.1", "Safari", "17.0")] [InlineData("Opera/9.80 Vendor-Version/120.0", "Opera", "9.80")] @@ -388,6 +391,7 @@ public void GetBrowser_ExtractsAsciiVersion(string userAgent, string expectedVer [InlineData("Microsoft Office/16.0 (Macintosh; Mac OS X 10.15.7; Microsoft Outlook 16.80.23121017; Pro)", "Mac OS X")] [InlineData("Microsoft-CryptoAPI/10.0", null)] [InlineData("Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "ChromeOS")] + [InlineData("Mozilla/5.0+(X11;+CrOS+x86_64+14541.0.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/120.0.0.0+Safari/537.36", "ChromeOS")] [InlineData("Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15063", "Windows Phone")] public void GetPlatform_Detects_ChromeOS_And_Windows_Phone_Only_By_Their_Own_Tokens(string userAgent, string? expectedPlatform) { @@ -398,6 +402,7 @@ public void GetPlatform_Detects_ChromeOS_And_Windows_Phone_Only_By_Their_Own_Tok public void GetRobot_Does_Not_Match_YouBot_Inside_Another_Name() { Assert.Null(HttpUserAgentParser.GetRobot("ShowyouBot (http://showyou.com/crawler)")); + Assert.Null(HttpUserAgentParser.GetRobot("ShowyouBot/1.0")); Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; YouBot/1.0; +https://docs.you.com/youbot; env:prod) Chrome/X.X.X.X Safari/537.36")); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index e0d7125..bfc77c2 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -165,8 +165,8 @@ public void Parser_Platform_Rules_Resolve_The_Regex_Of_Their_Token() foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { // The public pattern is the token; the parser token "cros " ends with a space, so "Microsoft" is no ChromeOS. - Assert.Equal(Regex.Escape(token.TrimEnd()), platform.Regex.ToString()); - Assert.Matches(platform.Regex, token); + Assert.Equal(Regex.Escape(token.TrimEnd(' ', '+')), platform.Regex.ToString()); + Assert.Matches(platform.Regex, token.TrimEnd(' ', '+')); Assert.Contains(platform, HttpUserAgentStatics.Platforms); } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index 6605814..aba1313 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -135,27 +135,78 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() } [Fact] - public void Own_Meters_Are_Reused_Per_Name_And_Meters_Of_The_Caller_Stay_Alive() + public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() { HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); using Meter callerMeter = new("caller.http_user_agent_parser"); options.WithMeterTelemetryPrefix("first."); + options.WithMeterTelemetryPrefix("first."); // the meter in use: kept + Assert.Equal((1, 5), CountLiveMeters("first.http_user_agent_parser")); + options.WithMeterTelemetryPrefix("second."); - options.WithMeterTelemetryPrefix("first."); // reuses the meter and the instruments of the first registration + Assert.Equal((0, 0), CountLiveMeters("first.http_user_agent_parser")); + Assert.Equal((1, 5), CountLiveMeters("second.http_user_agent_parser")); + options.WithMeterTelemetry(callerMeter); - options.WithMeterTelemetry(); + Assert.Equal((0, 0), CountLiveMeters("second.http_user_agent_parser")); - Assert.Equal((1, 5), CountLiveMeters("first.http_user_agent_parser")); - Assert.Equal((1, 5), CountLiveMeters("second.http_user_agent_parser")); + options.WithMeterTelemetry(); // the default meter replaces the meter of the caller Assert.Equal((1, 5), CountLiveMeters("caller.http_user_agent_parser")); Assert.Equal((1, 5), CountLiveMeters("mycsharp.http_user_agent_parser")); } [Fact] - public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() + public void Changing_Prefixes_Keep_Only_The_Meter_In_Use() + { + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + + for (int i = 0; i < 32; i++) + { + options.WithMeterTelemetryPrefix($"changing{i}."); + } + + for (int i = 0; i < 31; i++) + { + Assert.Equal((0, 0), CountLiveMeters($"changing{i}.http_user_agent_parser")); + } + + Assert.Equal((1, 5), CountLiveMeters("changing31.http_user_agent_parser")); + } + + [Fact] + public void A_Throwing_Listener_Keeps_The_Meter_In_Use() + { + using Meter first = new("throwing.first"); + using Meter second = new("throwing.second"); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (instrument.Meter.Name.StartsWith("throwing.", StringComparison.Ordinal) && !ReferenceEquals(instrument.Meter, first)) + { + throw new InvalidOperationException("listener failure"); + } + }, + }; + listener.Start(); + + HttpUserAgentParserMeters.Enable(first); + Assert.Throws(() => HttpUserAgentParserMeters.Enable(second)); + Assert.Throws(() => HttpUserAgentParserMeters.EnableOwnedMeter("throwing.own")); + Assert.Equal((0, 0), CountLiveMeters("throwing.own")); // the new own meter is disposed again + + using MeterTestListener recorder = new("throwing.first"); + HttpUserAgentParserMeters.ParseRequest(); + Assert.Equal(new[] { "parse.requests" }, recorder.InstrumentNames, StringComparer.Ordinal); + } + + [Fact] + public async Task No_Measurement_Is_Lost_While_Meters_Of_The_Caller_Are_Switched() { CancellationToken cancellationToken = TestContext.Current.CancellationToken; + using Meter a = new("switch.a"); + using Meter b = new("switch.b"); long recorded = 0; using MeterListener listener = new() { @@ -171,14 +222,14 @@ public async Task No_Measurement_Is_Lost_While_Own_Meters_Are_Switched() listener.SetMeasurementEventCallback((_, value, _, _) => Interlocked.Add(ref recorded, value)); listener.Start(); - HttpUserAgentParserMeters.EnableOwnedMeter("switch.a"); + HttpUserAgentParserMeters.Enable(a); using CancellationTokenSource stop = new(TimeSpan.FromMilliseconds(300)); Task switcher = Task.Run( () => { for (int i = 0; !stop.IsCancellationRequested; i++) { - HttpUserAgentParserMeters.EnableOwnedMeter(i % 2 == 0 ? "switch.b" : "switch.a"); + HttpUserAgentParserMeters.Enable(i % 2 == 0 ? b : a); } }, cancellationToken); @@ -223,15 +274,16 @@ public void Core_And_MemoryCache_Cannot_Share_A_Meter() using Meter other = new("test.guard.other"); using Meter third = new("test.guard.third"); - HttpUserAgentParserCacheMeterGuard.UseForCore(shared); - Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(shared)); + HttpUserAgentParserCacheMeterGuard.ReserveForCore(shared); + HttpUserAgentParserCacheMeterGuard.ReserveForCore(shared); // again: no effect + Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache(shared)); - HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(other); - Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.UseForCore(other)); + HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache(other); + Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.ReserveForCore(other)); - // The core package moves to another meter, so the MemoryCache package may use the first one. - HttpUserAgentParserCacheMeterGuard.UseForCore(third); - HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(shared); + // The instruments of the core package remain on the first meter after it moved to another one. + HttpUserAgentParserCacheMeterGuard.ReserveForCore(third); + Assert.Throws(() => HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache(shared)); HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); } @@ -240,7 +292,7 @@ public void Core_And_MemoryCache_Cannot_Share_A_Meter() public void WithMeterTelemetry_Rejects_The_Meter_Of_The_MemoryCache_Package() { using Meter shared = new("test.guard.memorycache"); - HttpUserAgentParserCacheMeterGuard.UseForMemoryCache(shared); + HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache(shared); HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); Assert.Throws(() => options.WithMeterTelemetry(shared)); From 21636450aa75d6d328d364745fcfc4953607e801 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 20:37:40 +0100 Subject: [PATCH 09/41] fix: run no listener code under the meter registration lock Telemetry (one registration implementation for all packages) - .NET calls MeterListener callbacks while instruments are created and while a meter is disposed. Both happen outside the registration lock now; the lock only switches the state. Mutual registrations of the core and MemoryCache packages from listener callbacks no longer deadlock, and a nested registration of another own meter leaves no meter behind. - Each meter gets one instrument container before any instrument is created. After a listener threw, a later registration only adds the missing instruments: cache.size exists at most once per meter and reports while its meter is in use. - Passing the own meter in use keeps it (no disposal). Robots - "YouBot/" matches again at any position; ShowyouBot has an entry of its own before it. --- .../HttpUserAgentParserAspNetCoreMeters.cs | 118 +++---------- .../HttpUserAgentParserMemoryCacheMeters.cs | 140 ++++----------- src/HttpUserAgentParser/HttpUserAgentRules.cs | 3 +- .../HttpUserAgentParserMeterRegistration.cs | 136 +++++++++++++++ .../Telemetry/HttpUserAgentParserMeters.cs | 164 +++++------------- ...ntParserMemoryCacheMetersTelemetryTests.cs | 77 ++++++++ .../HttpUserAgentParserTests.cs | 9 +- ...HttpUserAgentParserMetersTelemetryTests.cs | 94 ++++++++++ 8 files changed, 406 insertions(+), 335 deletions(-) create mode 100644 src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 49cbf17..8e7624a 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -10,8 +10,7 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// System.Diagnostics.Metrics instruments emitted by MyCSharp.HttpUserAgentParser.AspNetCore. /// /// -/// All instruments of a meter are created before they become visible, so concurrent registrations never observe -/// a partially initialized state. The last registered meter is used. +/// See for the registration rules. /// internal static class HttpUserAgentParserAspNetCoreMeters { @@ -37,127 +36,54 @@ internal static class HttpUserAgentParserAspNetCoreMeters public static string GetMeterName(string? meterPrefix) => HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix, MeterNameSuffix); -#if NET9_0_OR_GREATER - private static readonly Lock s_lock = new(); -#else - private static readonly object s_lock = new(); -#endif - - /// - /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. - /// - private static Meter? s_ownedMeter; - - private static Instruments? s_instruments; - - /// - /// The instruments of every registered meter; a meter registered again reuses its instruments. - /// - private static readonly ConditionalWeakTable s_instrumentsByMeter = new(); + private static readonly HttpUserAgentParserMeterRegistration s_registration = new( + static meter => new Instruments(meter), + static _ => { }, // no instrument in common with the other packages: a meter may be shared + static () => { }); /// /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// - /// - /// Optional externally managed instance. If not provided, - /// a meter named is used. - /// - /// - /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. - /// - public static void Enable(Meter? meter = null) => Use(meter, MeterName); + public static void Enable(Meter? meter = null) => s_registration.Use(meter, MeterName); /// /// Creates the metric instruments on a meter named that this class creates and owns. /// - /// - /// The owned meter is reused for the same name; it is disposed when another meter replaces it. - /// - public static void EnableOwnedMeter(string meterName) => Use(null, meterName); - - /// - /// Uses or, if null, an owned meter named . - /// - private static void Use(Meter? meter, string ownedMeterName) - { - lock (s_lock) - { - Meter? previousOwnedMeter = s_ownedMeter; - bool own = meter is null; - if (meter is null) - { - // Own meters: the current one is reused for the same name, another name gets a new meter. - meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) - ? previousOwnedMeter - : new Meter(ownedMeterName); - } - - Instruments instruments; - try - { - // Instruments are created once per meter; a listener may throw while they are published. - instruments = s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m)); - } - catch when (own && !ReferenceEquals(meter, previousOwnedMeter)) - { - meter.Dispose(); - throw; - } - - // Published only after all instruments exist. - Volatile.Write(ref s_instruments, instruments); - s_ownedMeter = own ? meter : null; - - // A replaced own meter is disposed, so changing names does not keep meters alive. A measurement that read its - // instruments just before the switch may be lost (best effort); meters of the caller are never disposed. - if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) - { - previousOwnedMeter.Dispose(); - } - } - } + public static void EnableOwnedMeter(string meterName) => s_registration.Use(null, meterName); /// /// Records a metric indicating that a User-Agent header was present. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void UserAgentPresent() - => Volatile.Read(ref s_instruments)?.UserAgentPresent.Add(1); + public static void UserAgentPresent() => s_registration.Current?.UserAgentPresent.Add(1); /// /// Records a metric indicating that a User-Agent header was missing. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void UserAgentMissing() - => Volatile.Read(ref s_instruments)?.UserAgentMissing.Add(1); + public static void UserAgentMissing() => s_registration.Current?.UserAgentMissing.Add(1); /// /// Resets static state to support isolated unit tests. /// - public static void ResetForTests() - { - lock (s_lock) - { - Volatile.Write(ref s_instruments, null); - s_ownedMeter?.Dispose(); - s_ownedMeter = null; - s_instrumentsByMeter.Clear(); - } - } + public static void ResetForTests() => s_registration.ResetForTests(); /// /// The instruments of one meter. /// - private sealed class Instruments(Meter meter) + private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstruments(meter) { - public Counter UserAgentPresent { get; } = meter.CreateCounter( - name: "user_agent.present", - unit: "{call}", - description: "User-Agent header present"); + private Counter? _userAgentPresent; + private Counter? _userAgentMissing; + + public Counter UserAgentPresent => _userAgentPresent!; - public Counter UserAgentMissing { get; } = meter.CreateCounter( - name: "user_agent.missing", - unit: "{call}", - description: "User-Agent header missing"); + public Counter UserAgentMissing => _userAgentMissing!; + + public override void CreateMissingInstruments() + { + _userAgentPresent ??= Meter.CreateCounter(name: "user_agent.present", unit: "{call}", description: "User-Agent header present"); + _userAgentMissing ??= Meter.CreateCounter(name: "user_agent.missing", unit: "{call}", description: "User-Agent header missing"); + } } } diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 95928c4..c0ce668 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -10,9 +10,8 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// System.Diagnostics.Metrics instruments emitted by MyCSharp.HttpUserAgentParser.MemoryCache. /// /// -/// All instruments of a meter are created before they become visible to the provider, so concurrent -/// registrations never observe a partially initialized state. The last registered meter is used; a replaced meter -/// no longer reports the cache size. +/// See for the registration rules; a replaced meter no longer +/// reports the cache size. /// internal static class HttpUserAgentParserMemoryCacheMeters { @@ -32,140 +31,61 @@ internal static class HttpUserAgentParserMemoryCacheMeters public static string GetMeterName(string? meterPrefix) => HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix, MeterNameSuffix); -#if NET9_0_OR_GREATER - private static readonly Lock s_lock = new(); -#else - private static readonly object s_lock = new(); -#endif + private static readonly HttpUserAgentParserMeterRegistration s_registration = new( + static meter => new Instruments(meter), + HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache, // the core and the MemoryCache package must not share a meter + HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests); - /// - /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. - /// - private static Meter? s_ownedMeter; - - private static Instruments? s_instruments; - - /// - /// The instruments of every registered meter; a meter registered again reuses its instruments. - /// - private static readonly ConditionalWeakTable s_instrumentsByMeter = new(); - - public static bool IsEnabled => Volatile.Read(ref s_instruments) is not null; + public static bool IsEnabled => s_registration.Current is not null; /// /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// - /// - /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. - /// - public static void Enable(Meter? meter = null) => Use(meter, MeterName); + public static void Enable(Meter? meter = null) => s_registration.Use(meter, MeterName); /// /// Creates the metric instruments on a meter named that this class creates and owns. /// - /// - /// The owned meter is reused for the same name; it is disposed when another meter replaces it. - /// - public static void EnableOwnedMeter(string meterName) => Use(null, meterName); - - /// - /// Uses or, if null, an owned meter named . - /// - private static void Use(Meter? meter, string ownedMeterName) - { - lock (s_lock) - { - Meter? previousOwnedMeter = s_ownedMeter; - bool own = meter is null; - if (meter is null) - { - // Own meters: the current one is reused for the same name, another name gets a new meter. - meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) - ? previousOwnedMeter - : new Meter(ownedMeterName); - } - - // The core and the MemoryCache package must not share a meter (same instrument names). - HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache(meter); - - Instruments instruments; - try - { - // Instruments are created once per meter; a listener may throw while they are published. - instruments = s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m)); - } - catch when (own && !ReferenceEquals(meter, previousOwnedMeter)) - { - meter.Dispose(); - throw; - } - - // Published only after all instruments exist. - Volatile.Write(ref s_instruments, instruments); - s_ownedMeter = own ? meter : null; - - // A replaced own meter is disposed, so changing names does not keep meters alive. A measurement that read its - // instruments just before the switch may be lost (best effort); meters of the caller are never disposed. - if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) - { - previousOwnedMeter.Dispose(); - } - } - } + public static void EnableOwnedMeter(string meterName) => s_registration.Use(null, meterName); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheHit() => Volatile.Read(ref s_instruments)?.CacheHit.Add(1); + public static void CacheHit() => s_registration.Current?.CacheHit.Add(1); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheMiss() => Volatile.Read(ref s_instruments)?.CacheMiss.Add(1); + public static void CacheMiss() => s_registration.Current?.CacheMiss.Add(1); - public static void ResetForTests() - { - lock (s_lock) - { - Volatile.Write(ref s_instruments, null); - s_ownedMeter?.Dispose(); - s_ownedMeter = null; - HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); - s_instrumentsByMeter.Clear(); - } - } + public static void ResetForTests() => s_registration.ResetForTests(); /// /// The instruments of one meter. /// - private sealed class Instruments + private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstruments(meter) { - public Instruments(Meter meter) - { - CacheHit = meter.CreateCounter( - name: "cache.hit", - unit: "{call}", - description: "Cache hit"); - - CacheMiss = meter.CreateCounter( - name: "cache.miss", - unit: "{call}", - description: "Cache miss"); - - CacheSize = meter.CreateObservableGauge( - name: "cache.size", - observeValues: ObserveCacheSize, - unit: "{entry}", - description: "Cache size"); - } + private Counter? _cacheHit; + private Counter? _cacheMiss; + private int _cacheSizeCreated; - public Counter CacheHit { get; } + public Counter CacheHit => _cacheHit!; - public Counter CacheMiss { get; } + public Counter CacheMiss => _cacheMiss!; - public ObservableGauge CacheSize { get; } + public override void CreateMissingInstruments() + { + _cacheHit ??= Meter.CreateCounter(name: "cache.hit", unit: "{call}", description: "Cache hit"); + _cacheMiss ??= Meter.CreateCounter(name: "cache.miss", unit: "{call}", description: "Cache miss"); + + // Observable instruments are not shared by the meter: created at most once, also if a listener threw. + if (Interlocked.Exchange(ref _cacheSizeCreated, 1) == 0) + { + _ = Meter.CreateObservableGauge(name: "cache.size", observeValues: ObserveCacheSize, unit: "{entry}", description: "Cache size"); + } + } /// /// Reports the cache size only while these instruments are in use, so a replaced meter does not report it as well. /// private IEnumerable> ObserveCacheSize() - => ReferenceEquals(Volatile.Read(ref s_instruments), this) + => ReferenceEquals(s_registration.Current, this) ? [new Measurement(HttpUserAgentParserMemoryCacheTelemetryState.CacheSize)] : []; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 5c586f4..10e7433 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -239,7 +239,8 @@ internal static readonly (string Key, string Value)[] Robots = ( "MistralAI-User", "MistralAI-User" ), ( "DuckAssistBot", "DuckAssistBot" ), ( "AI2Bot", "AI2Bot" ), - ( " YouBot/", "YouBot" ), // "YouBot/" alone would match "ShowyouBot/1.0" + ( "ShowyouBot", "ShowyouBot" ), // before YouBot, whose key it contains + ( "YouBot/", "YouBot" ), ]; /// diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs new file mode 100644 index 0000000..ef734dd --- /dev/null +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs @@ -0,0 +1,136 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Diagnostics.Metrics; +using System.Runtime.CompilerServices; + +namespace MyCSharp.HttpUserAgentParser.Telemetry; + +/// +/// The instruments of one package on one meter. +/// +/// The meter the instruments belong to. +internal abstract class HttpUserAgentParserMeterInstruments(Meter meter) +{ + /// + /// Gets the meter the instruments belong to. + /// + public Meter Meter { get; } = meter; + + /// + /// Creates the instruments that do not exist yet. + /// + /// + /// .NET runs the callbacks while an instrument is created, so listener code + /// runs here and may throw or register meters itself; no lock is held. An instrument that was published before a listener + /// threw exists on the meter, so a later call must not create it again: counters and histograms with the same name, unit and + /// description are returned by the meter, observable instruments have to be created at most once by the implementation. + /// + public abstract void CreateMissingInstruments(); +} + +/// +/// Registration of the meter a package records to (shared by all packages). +/// +/// +/// +/// The last registered meter is used. A meter that is registered again reuses its instruments. The meter a package creates itself +/// (the default meter or a meter with a prefixed name) is reused while it is in use and disposed when another meter replaces it; +/// a measurement that runs exactly during that switch may be lost. Meters of the caller are never disposed. +/// +/// +/// Listener code never runs while the lock is held: instruments are created and replaced meters are disposed outside of it, so +/// listeners may register meters of any package without deadlocks. The lock only protects the switch of the state. +/// +/// +/// The instruments of the package. +/// Creates the (still empty) instruments of a meter; must not create instruments itself. +/// Reserves a meter for the package before its instruments are created; throws if the meter must not be used. +/// Forgets the reservations of the package (unit tests). +internal sealed class HttpUserAgentParserMeterRegistration( + Func createInstruments, Action reserve, Action resetReservations) + where TInstruments : HttpUserAgentParserMeterInstruments +{ +#if NET9_0_OR_GREATER + private readonly Lock _lock = new(); +#else + private readonly object _lock = new(); +#endif + + // Keyed by the non-generic base type: the table's value type needs a trimming annotation a generic argument cannot provide. + private readonly ConditionalWeakTable _instrumentsByMeter = new(); + private readonly ConditionalWeakTable.CreateValueCallback _createInstruments = createInstruments.Invoke; + + private Meter? _ownedMeter; + private TInstruments? _current; + + /// + /// Gets the instruments in use, or before the first registration. + /// + public TInstruments? Current => Volatile.Read(ref _current); + + /// + /// Records to from now on or, if , to a meter named + /// that the package creates and owns. + /// + public void Use(Meter? meter, string ownedMeterName) + { + bool own = meter is null; + lock (_lock) + { + // Already in use: nothing to do. This also keeps the own meter from being disposed if a caller passes it in. + bool inUse = own + ? _ownedMeter is not null && string.Equals(_ownedMeter.Name, ownedMeterName, StringComparison.Ordinal) + : ReferenceEquals(meter, _ownedMeter); + if (inUse) + { + return; + } + } + + // A new own meter is visible to nobody until it is published below. + meter ??= new Meter(ownedMeterName); + + TInstruments instruments; + try + { + reserve(meter); + instruments = (TInstruments)_instrumentsByMeter.GetValue(meter, _createInstruments); + instruments.CreateMissingInstruments(); + } + catch when (own) + { + meter.Dispose(); + throw; + } + + Meter? replacedOwnedMeter; + lock (_lock) + { + // Published only after all instruments exist. + Volatile.Write(ref _current, instruments); + replacedOwnedMeter = _ownedMeter; + _ownedMeter = own ? meter : null; + } + + // Disposing notifies listeners, so it runs outside of the lock. + replacedOwnedMeter?.Dispose(); + } + + /// + /// Resets the registration (unit tests). + /// + public void ResetForTests() + { + Meter? ownedMeter; + lock (_lock) + { + Volatile.Write(ref _current, null); + ownedMeter = _ownedMeter; + _ownedMeter = null; + _instrumentsByMeter.Clear(); + } + + ownedMeter?.Dispose(); + resetReservations(); + } +} diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index 96df187..355113b 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -10,9 +10,8 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// This is opt-in and designed to keep overhead negligible unless a listener is enabled. /// /// -/// All instruments of a meter are created before they become visible to the parser, so concurrent -/// registrations never observe a partially initialized state. The last registered meter is used; a replaced meter -/// no longer reports the cache size. +/// See for the registration rules; a replaced meter no longer +/// reports the cache size. /// internal static class HttpUserAgentParserMeters { @@ -38,183 +37,98 @@ internal static class HttpUserAgentParserMeters public static string GetMeterName(string? meterPrefix) => HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix, MeterNameSuffix); -#if NET9_0_OR_GREATER - private static readonly Lock s_lock = new(); -#else - private static readonly object s_lock = new(); -#endif - - /// - /// The meter this class created and uses (the default meter or a meter with a prefixed name), if any. - /// - private static Meter? s_ownedMeter; - - private static Instruments? s_instruments; - - /// - /// The instruments of every registered meter; a meter registered again reuses its instruments. - /// - private static readonly ConditionalWeakTable s_instrumentsByMeter = new(); + private static readonly HttpUserAgentParserMeterRegistration s_registration = new( + static meter => new Instruments(meter), + HttpUserAgentParserCacheMeterGuard.ReserveForCore, // the core and the MemoryCache package must not share a meter + HttpUserAgentParserCacheMeterGuard.ResetCoreForTests); /// /// Gets whether meters have been initialized. /// - public static bool IsEnabled => Volatile.Read(ref s_instruments) is not null; + public static bool IsEnabled => s_registration.Current is not null; /// /// Gets whether the parse duration histogram is currently enabled by a listener. /// - public static bool IsParseDurationEnabled => Volatile.Read(ref s_instruments)?.ParseDuration.Enabled ?? false; + public static bool IsParseDurationEnabled => s_registration.Current?.ParseDuration.Enabled ?? false; /// /// Creates the metric instruments on (or on a default meter) and uses them from now on. /// - /// - /// Another meter replaces the one in use. A meter that is registered again reuses its instruments. - /// - public static void Enable(Meter? meter = null) => Use(meter, MeterName); + public static void Enable(Meter? meter = null) => s_registration.Use(meter, MeterName); /// /// Creates the metric instruments on a meter named that this class creates and owns. /// - /// - /// The owned meter is reused for the same name; it is disposed when another meter replaces it. - /// - public static void EnableOwnedMeter(string meterName) => Use(null, meterName); - - /// - /// Uses or, if null, an owned meter named . - /// - private static void Use(Meter? meter, string ownedMeterName) - { - lock (s_lock) - { - Meter? previousOwnedMeter = s_ownedMeter; - bool own = meter is null; - if (meter is null) - { - // Own meters: the current one is reused for the same name, another name gets a new meter. - meter = previousOwnedMeter is not null && string.Equals(previousOwnedMeter.Name, ownedMeterName, StringComparison.Ordinal) - ? previousOwnedMeter - : new Meter(ownedMeterName); - } - - // The core and the MemoryCache package must not share a meter (same instrument names). - HttpUserAgentParserCacheMeterGuard.ReserveForCore(meter); - - Instruments instruments; - try - { - // Instruments are created once per meter; a listener may throw while they are published. - instruments = s_instrumentsByMeter.GetValue(meter, static m => new Instruments(m)); - } - catch when (own && !ReferenceEquals(meter, previousOwnedMeter)) - { - meter.Dispose(); - throw; - } - - // Published only after all instruments exist. - Volatile.Write(ref s_instruments, instruments); - s_ownedMeter = own ? meter : null; - - // A replaced own meter is disposed, so changing names does not keep meters alive. A measurement that read its - // instruments just before the switch may be lost (best effort); meters of the caller are never disposed. - if (previousOwnedMeter is not null && !ReferenceEquals(previousOwnedMeter, meter)) - { - previousOwnedMeter.Dispose(); - } - } - } + public static void EnableOwnedMeter(string meterName) => s_registration.Use(null, meterName); /// /// Emits a counter increment for a parse request. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ParseRequest() => Volatile.Read(ref s_instruments)?.ParseRequests.Add(1); + public static void ParseRequest() => s_registration.Current?.ParseRequests.Add(1); /// /// Records the parse duration in seconds. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ParseDuration(double seconds) => Volatile.Read(ref s_instruments)?.ParseDuration.Record(seconds); + public static void ParseDuration(double seconds) => s_registration.Current?.ParseDuration.Record(seconds); /// /// Emits a counter increment for a cache hit. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheHit() => Volatile.Read(ref s_instruments)?.CacheHit.Add(1); + public static void CacheHit() => s_registration.Current?.CacheHit.Add(1); /// /// Emits a counter increment for a cache miss. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CacheMiss() => Volatile.Read(ref s_instruments)?.CacheMiss.Add(1); + public static void CacheMiss() => s_registration.Current?.CacheMiss.Add(1); /// /// Resets static state to support isolated unit tests. /// - public static void ResetForTests() - { - lock (s_lock) - { - Volatile.Write(ref s_instruments, null); - s_ownedMeter?.Dispose(); - s_ownedMeter = null; - HttpUserAgentParserCacheMeterGuard.ResetCoreForTests(); - s_instrumentsByMeter.Clear(); - } - } + public static void ResetForTests() => s_registration.ResetForTests(); /// /// The instruments of one meter. /// - private sealed class Instruments + private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstruments(meter) { - public Instruments(Meter meter) - { - ParseRequests = meter.CreateCounter( - name: "parse.requests", - unit: "{call}", - description: "User-Agent parse requests"); - - ParseDuration = meter.CreateHistogram( - name: "parse.duration", - unit: "s", - description: "Parse duration"); - - CacheHit = meter.CreateCounter( - name: "cache.hit", - unit: "{call}", - description: "Cache hit"); - - CacheMiss = meter.CreateCounter( - name: "cache.miss", - unit: "{call}", - description: "Cache miss"); - - CacheSize = meter.CreateObservableGauge( - name: "cache.size", - observeValues: ObserveCacheSize, - unit: "{entry}", - description: "Cache size"); - } + private Counter? _parseRequests; + private Histogram? _parseDuration; + private Counter? _cacheHit; + private Counter? _cacheMiss; + private int _cacheSizeCreated; - public Counter ParseRequests { get; } + public Counter ParseRequests => _parseRequests!; - public Histogram ParseDuration { get; } + public Histogram ParseDuration => _parseDuration!; - public Counter CacheHit { get; } + public Counter CacheHit => _cacheHit!; - public Counter CacheMiss { get; } + public Counter CacheMiss => _cacheMiss!; - public ObservableGauge CacheSize { get; } + public override void CreateMissingInstruments() + { + _parseRequests ??= Meter.CreateCounter(name: "parse.requests", unit: "{call}", description: "User-Agent parse requests"); + _parseDuration ??= Meter.CreateHistogram(name: "parse.duration", unit: "s", description: "Parse duration"); + _cacheHit ??= Meter.CreateCounter(name: "cache.hit", unit: "{call}", description: "Cache hit"); + _cacheMiss ??= Meter.CreateCounter(name: "cache.miss", unit: "{call}", description: "Cache miss"); + + // Observable instruments are not shared by the meter: created at most once, also if a listener threw. + if (Interlocked.Exchange(ref _cacheSizeCreated, 1) == 0) + { + _ = Meter.CreateObservableGauge(name: "cache.size", observeValues: ObserveCacheSize, unit: "{entry}", description: "Cache size"); + } + } /// /// Reports the cache size only while these instruments are in use, so a replaced meter does not report it as well. /// private IEnumerable> ObserveCacheSize() - => ReferenceEquals(Volatile.Read(ref s_instruments), this) + => ReferenceEquals(s_registration.Current, this) ? [new Measurement(HttpUserAgentParserTelemetryState.ConcurrentCacheSize)] : []; } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index 3d43184..2012830 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -290,4 +290,81 @@ public void A_Nested_Registration_While_The_Core_Instruments_Are_Published_Is_Re Assert.IsType(nested); } + + [Fact] + public void A_Cache_Size_Gauge_Whose_Publication_Failed_Is_Not_Created_Again() + { + using Meter meter = new("retry.memorycache"); + bool fail = true; + using MeterListener failing = new() + { + InstrumentPublished = (instrument, _) => + { + if (ReferenceEquals(instrument.Meter, meter) && string.Equals(instrument.Name, "cache.size", StringComparison.Ordinal) && fail) + { + fail = false; + throw new InvalidOperationException("listener failure"); + } + }, + }; + failing.Start(); + + Assert.Throws(() => HttpUserAgentParserMemoryCacheMeters.Enable(meter)); + HttpUserAgentParserMemoryCacheMeters.Enable(meter); // the retry completes the instruments + + int gauges = 0; + long? size = null; + using MeterListener observer = new() + { + InstrumentPublished = (instrument, target) => + { + if (ReferenceEquals(instrument.Meter, meter) && string.Equals(instrument.Name, "cache.size", StringComparison.Ordinal)) + { + gauges++; + target.EnableMeasurementEvents(instrument); + } + }, + }; + observer.SetMeasurementEventCallback((_, value, _, _) => size = value); + observer.Start(); + observer.RecordObservableInstruments(); + + Assert.Equal(1, gauges); + Assert.NotNull(size); // the gauge published first reports, because its meter is in use + } + + [Fact] + public async Task Mutual_Registrations_From_Listener_Callbacks_Do_Not_Block() + { + CancellationToken cancellationToken = TestContext.Current.CancellationToken; + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + using Meter coreMeter = new("mutual.core"); + using Meter memoryCacheMeter = new("mutual.memorycache"); + using Meter nestedCoreMeter = new("mutual.core.nested"); + using Meter nestedMemoryCacheMeter = new("mutual.memorycache.nested"); + using Barrier bothInCallbacks = new(2); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + // Each callback waits until the other registration is in its callback as well, then registers the other package. + if (ReferenceEquals(instrument.Meter, coreMeter) && string.Equals(instrument.Name, "parse.requests", StringComparison.Ordinal)) + { + bothInCallbacks.SignalAndWait(TimeSpan.FromSeconds(10), cancellationToken); + options.WithMemoryCacheMeterTelemetry(nestedMemoryCacheMeter); + } + else if (ReferenceEquals(instrument.Meter, memoryCacheMeter) && string.Equals(instrument.Name, "cache.hit", StringComparison.Ordinal)) + { + bothInCallbacks.SignalAndWait(TimeSpan.FromSeconds(10), cancellationToken); + options.WithMeterTelemetry(nestedCoreMeter); + } + }, + }; + listener.Start(); + + Task core = Task.Run(() => options.WithMeterTelemetry(coreMeter), cancellationToken); + Task memoryCache = Task.Run(() => options.WithMemoryCacheMeterTelemetry(memoryCacheMeter), cancellationToken); + + await Task.WhenAll(core, memoryCache).WaitAsync(TimeSpan.FromSeconds(20), cancellationToken); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 69b3dff..4fa78b4 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -399,10 +399,13 @@ public void GetPlatform_Detects_ChromeOS_And_Windows_Phone_Only_By_Their_Own_Tok } [Fact] - public void GetRobot_Does_Not_Match_YouBot_Inside_Another_Name() + public void GetRobot_Tells_YouBot_And_ShowyouBot_Apart() { - Assert.Null(HttpUserAgentParser.GetRobot("ShowyouBot (http://showyou.com/crawler)")); - Assert.Null(HttpUserAgentParser.GetRobot("ShowyouBot/1.0")); + Assert.Equal("ShowyouBot", HttpUserAgentParser.GetRobot("ShowyouBot (http://showyou.com/crawler)")); + Assert.Equal("ShowyouBot", HttpUserAgentParser.GetRobot("ShowyouBot/1.0")); + Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("YouBot/1.0")); + Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (YouBot/1.0)")); + Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0+(compatible;+YouBot/1.0)")); Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; YouBot/1.0; +https://docs.you.com/youbot; env:prod) Chrome/X.X.X.X Safari/537.36")); } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index aba1313..700f8a4 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -300,4 +300,98 @@ public void WithMeterTelemetry_Rejects_The_Meter_Of_The_MemoryCache_Package() HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); } + + [Fact] + public void A_Nested_Registration_Of_Another_Own_Meter_Leaves_No_Meter_Behind() + { + using Meter callerMeter = new("nested.caller"); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, "nested.a", StringComparison.Ordinal) + && string.Equals(instrument.Name, "parse.requests", StringComparison.Ordinal)) + { + HttpUserAgentParserMeters.EnableOwnedMeter("nested.b"); + } + }, + }; + listener.Start(); + + HttpUserAgentParserMeters.EnableOwnedMeter("nested.a"); // registers nested.b while its instruments are created + Assert.Equal((1, 5), CountLiveMeters("nested.a")); + Assert.Equal((0, 0), CountLiveMeters("nested.b")); + + HttpUserAgentParserMeters.Enable(callerMeter); + Assert.Equal((0, 0), CountLiveMeters("nested.a")); + } + + [Fact] + public void Passing_The_Own_Meter_In_Use_Keeps_It() + { + HttpUserAgentParserMeters.EnableOwnedMeter("own.inuse"); + Meter? ownMeter = null; + using (MeterListener finder = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, "own.inuse", StringComparison.Ordinal)) + { + ownMeter = instrument.Meter; + } + }, + }) + { + finder.Start(); + } + + HttpUserAgentParserMeters.Enable(ownMeter!); + + Assert.Equal((1, 5), CountLiveMeters("own.inuse")); + using MeterTestListener recorder = new("own.inuse"); + HttpUserAgentParserMeters.ParseRequest(); + Assert.Equal(new[] { "parse.requests" }, recorder.InstrumentNames, StringComparer.Ordinal); + } + + [Fact] + public void A_Cache_Size_Gauge_Whose_Publication_Failed_Is_Not_Created_Again() + { + using Meter meter = new("retry.core"); + bool fail = true; + using MeterListener failing = new() + { + InstrumentPublished = (instrument, _) => + { + if (ReferenceEquals(instrument.Meter, meter) && string.Equals(instrument.Name, "cache.size", StringComparison.Ordinal) && fail) + { + fail = false; + throw new InvalidOperationException("listener failure"); + } + }, + }; + failing.Start(); + + Assert.Throws(() => HttpUserAgentParserMeters.Enable(meter)); + HttpUserAgentParserMeters.Enable(meter); // the retry completes the instruments + + int gauges = 0; + long? size = null; + using MeterListener observer = new() + { + InstrumentPublished = (instrument, target) => + { + if (ReferenceEquals(instrument.Meter, meter) && string.Equals(instrument.Name, "cache.size", StringComparison.Ordinal)) + { + gauges++; + target.EnableMeasurementEvents(instrument); + } + }, + }; + observer.SetMeasurementEventCallback((_, value, _, _) => size = value); + observer.Start(); + observer.RecordObservableInstruments(); + + Assert.Equal(1, gauges); + Assert.NotNull(size); // the gauge published first reports, because its meter is in use + } } From f8cedd4cde74f31abfc0997fd411342168570b82 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Sun, 22 Nov 2026 21:25:41 +0100 Subject: [PATCH 10/41] feat!: robots API instead of a mutable public array - HttpUserAgentStatics.Robots is a read-only list now; SetRobots replaces the robots the parser detects (atomically, for all following parses), DefaultRobots holds the defaults. Writing into the array is no longer possible. - The parser works on an immutable robot set (list, anchor prefilter, grouped matcher) and reads it once per parse. The check that the keys of the public array were unchanged (95 reference comparisons, 17 ns on .NET 11 for every user agent) and the slow paths for replaced keys are gone. - Benchmarks: BenchmarkDotNet 0.16.0-preview.2 runs every case in its own process on .NET 11 as well, so --inProcess is no longer needed; in one process Dynamic PGO adapted the code to the cases measured before (Googlebot 9 ns alone, 20 ns after the other user agents). The library comparison uses the ShortRun job out of process, too. --- Directory.Packages.props | 2 +- README.md | 78 +++++++----- .../LibraryComparisonBenchmarks.cs | 9 +- .../HttpUserAgentParser.cs | 57 +++------ .../HttpUserAgentRobotSet.cs | 70 ++++++++++ src/HttpUserAgentParser/HttpUserAgentRules.cs | 52 +++----- .../HttpUserAgentStatics.cs | 42 +++++- ...pUserAgentStaticsRobotsReplacementTests.cs | 120 ++++++++++-------- .../HttpUserAgentStaticsTests.cs | 6 +- .../PriorityTokenMatcherTests.cs | 10 +- .../Telemetry/TelemetryCollection.cs | 2 +- 11 files changed, 262 insertions(+), 186 deletions(-) create mode 100644 src/HttpUserAgentParser/HttpUserAgentRobotSet.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 1bcc284..44be207 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -30,7 +30,7 @@ - + diff --git a/README.md b/README.md index c076587..a8af544 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,13 @@ The parser does not execute regular expressions. `HttpUserAgentStatics.Platforms The patterns use `RegexOptions.IgnoreCase` with culture-invariant case mapping, so a match does not depend on the current culture (e.g. `LINUX` matches `linux` under `tr-TR` as well). `RegexOptions.Compiled` is not set, because the source generator already emits the matching code. -`HttpUserAgentStatics.Robots` is the array the parser uses: if you replace an entry, the parser honors it. +### Custom robots + +`HttpUserAgentStatics.Robots` lists the robots the parser detects (read-only, initially `HttpUserAgentStatics.DefaultRobots`). `HttpUserAgentStatics.SetRobots` replaces the list for all following parses in the process; the first entry whose key occurs in the user agent (ignoring case) wins. Set it once at startup, building the matchers takes a moment: + +```csharp +HttpUserAgentStatics.SetRobots([.. HttpUserAgentStatics.DefaultRobots, ("MyCrawler", "My Crawler")]); +``` ## Native AOT and trimming @@ -441,26 +447,26 @@ Run the parser benchmarks with the .NET 11 runtime (use `-f net8.0`, `net9.0` or ```shell # 7 typical user agents -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks*" --inProcess +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks*" # mixed real-world workload (closest to production) -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*MixedWorkloadBenchmarks*" --inProcess +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*MixedWorkloadBenchmarks*" # every browser (current and previous browser version) and every crawler of the test catalog -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*BrowserUserAgentBenchmarks*" "*RobotUserAgentBenchmarks*" --inProcess +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*BrowserUserAgentBenchmarks*" "*RobotUserAgentBenchmarks*" ``` The user agents come from `tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs`, which the unit tests use as well. ### Parser performance -BenchmarkDotNet 0.15.8 in-process, x64, Windows 10 and an AMD Ryzen 9 9950X, without caching. For a user agent without leading or trailing white space, the only allocation is the version string; otherwise `Parse` also allocates the trimmed string. +BenchmarkDotNet 0.16.0-preview.2 (default job: every benchmark case runs in its own process), x64, Windows 10 and an AMD Ryzen 9 9950X, without caching. For a user agent without leading or trailing white space, the only allocation is the version string; otherwise `Parse` also allocates the trimmed string. Mixed workload: the catalog user agents parsed in a loop, mean time per user agent. | Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | .NET 11.0.0 | Allocated | | --- | ---: | ---: | ---: | ---: | ---: | -| 44 browser user agents | 764.5 ns | 367.4 ns | 365.5 ns | 298.4 ns | 38 B | -| 48 crawler user agents | 385.4 ns | 186.2 ns | 177.3 ns | 160.5 ns | 0 B | -| All 96 user agents | 597.6 ns | 295.1 ns | 282.0 ns | 247.5 ns | 18 B | +| 44 browser user agents | 754.0 ns | 331.8 ns | 291.7 ns | 262.5 ns | 38 B | +| 48 crawler user agents | 355.5 ns | 159.0 ns | 227.4 ns | 151.5 ns | 0 B | +| All 96 user agents | 609.4 ns | 261.0 ns | 262.3 ns | 216.2 ns | 18 B | .NET 8 has no `SearchValues`; the parser checks the tokens one by one there. @@ -468,13 +474,13 @@ Single user agents on .NET 11: | User agent | Mean | Allocated | | --- | ---: | ---: | -| Chrome on Windows | 254.7 ns | 40 B | -| Firefox on Linux | 356.4 ns | 32 B | -| Chrome on Android | 289.8 ns | 40 B | -| Safari on iPhone | 306.0 ns | 32 B | -| Applebot | 178.5 ns | 0 B | -| Googlebot | 9.58 ns | 0 B | -| Unknown client | 411.4 ns | 0 B | +| Chrome on Windows | 248.6 ns | 40 B | +| Firefox on Linux | 373.1 ns | 32 B | +| Chrome on Android | 267.5 ns | 40 B | +| Safari on iPhone | 289.2 ns | 32 B | +| Applebot | 195.5 ns | 0 B | +| Googlebot | 6.98 ns | 0 B | +| Unknown client | 378.2 ns | 0 B | Startup in a new .NET 11 process (median of 7 runs): @@ -489,33 +495,35 @@ Startup in a new .NET 11 process (median of 7 runs): dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*LibraryComparison*" ``` -The ShortRun job (3 iterations) executes in-process. +The ShortRun job (3 iterations) runs every benchmark case in its own process. ```shell -BenchmarkDotNet v0.15.8, Windows 10 (10.0.19045.7846/22H2/2022Update) +BenchmarkDotNet v0.16.0-preview.2, Windows 10 (10.0.19045.7846/22H2/2022Update) AMD Ryzen 9 9950X 4.30GHz, 1 CPU, 32 logical and 16 physical cores +Memory: 61,64 GB Total, 31,34 GB Available .NET SDK 11.0.100 - [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 + [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 + ShortRun : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 -Job=ShortRun Toolchain=InProcessEmitToolchain IterationCount=3 -LaunchCount=1 WarmupCount=3 +Job=ShortRun IterationCount=3 LaunchCount=1 +WarmupCount=3 ``` -| Method | Categories | Data | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio | -|------------------- |----------- |------------- |-----------------:|-----------------:|---------------:|----------:|---------:|---------:|---------:|--------:|-----------:|------------:| -| MyCSharp | Basic | Chrome Win10 | 290.42 ns | 21.325 ns | 1.169 ns | 1.00 | 0.00 | - | - | - | 48 B | 1.00 | -| UAParser | Basic | Chrome Win10 | 11,049,381.25 ns | 2,603,063.009 ns | 142,682.668 ns | 38,046.15 | 445.58 | 656.2500 | 468.7500 | 93.7500 | 11654118 B | 242,794.12 | -| DeviceDetector.NET | Basic | Chrome Win10 | 6,239,145.83 ns | 1,814,748.937 ns | 99,472.513 ns | 21,483.15 | 305.89 | 335.9375 | 179.6875 | 46.8750 | 5529599 B | 115,199.98 | -| | | | | | | | | | | | | | -| MyCSharp | Basic | Google-Bot | 246.81 ns | 96.469 ns | 5.288 ns | 1.00 | 0.03 | - | - | - | - | NA | -| UAParser | Basic | Google-Bot | 13,090,585.94 ns | 3,799,306.664 ns | 208,252.819 ns | 53,054.68 | 1,231.46 | 718.7500 | 484.3750 | 31.2500 | 12010207 B | NA | -| DeviceDetector.NET | Basic | Google-Bot | 7,389,143.49 ns | 348,698.377 ns | 19,113.335 ns | 29,947.37 | 563.38 | 609.3750 | 132.8125 | 23.4375 | 10124580 B | NA | -| | | | | | | | | | | | | | -| MyCSharp | Cached | Chrome Win10 | 24.20 ns | 16.275 ns | 0.892 ns | 1.00 | 0.05 | - | - | - | - | NA | -| UAParser | Cached | Chrome Win10 | 146,715.00 ns | 23,237.727 ns | 1,273.738 ns | 6,069.10 | 203.13 | 2.1973 | - | - | 37402 B | NA | -| | | | | | | | | | | | | | -| MyCSharp | Cached | Google-Bot | 18.58 ns | 0.046 ns | 0.002 ns | 1.00 | 0.00 | - | - | - | - | NA | -| UAParser | Cached | Google-Bot | 125,494.21 ns | 6,022.587 ns | 330.118 ns | 6,754.11 | 15.41 | 2.6855 | - | - | 45834 B | NA | +| Method | Categories | Data | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio | +|------------------- |----------- |------------- |----------------:|-----------------:|---------------:|----------:|--------:|---------:|---------:|---------:|-----------:|------------:| +| MyCSharp | Basic | Chrome Win10 | 304.64 ns | 9.540 ns | 0.523 ns | 1.00 | 0.00 | 0.0029 | - | - | 48 B | 1.00 | +| UAParser | Basic | Chrome Win10 | 9,491,617.71 ns | 1,334,799.918 ns | 73,164.888 ns | 31,156.50 | 213.09 | 671.8750 | 609.3750 | 109.3750 | 11653583 B | 242,782.98 | +| DeviceDetector.NET | Basic | Chrome Win10 | 5,911,814.32 ns | 2,450,967.779 ns | 134,345.815 ns | 19,405.70 | 383.00 | 335.9375 | 179.6875 | 46.8750 | 5529304 B | 115,193.83 | +| | | | | | | | | | | | | | +| MyCSharp | Basic | Google-Bot | 239.51 ns | 12.113 ns | 0.664 ns | 1.00 | 0.00 | - | - | - | - | NA | +| UAParser | Basic | Google-Bot | 9,398,484.90 ns | 2,371,656.128 ns | 129,998.476 ns | 39,239.89 | 479.38 | 687.5000 | 625.0000 | 125.0000 | 12010118 B | NA | +| DeviceDetector.NET | Basic | Google-Bot | 7,600,150.00 ns | 1,546,038.456 ns | 84,743.585 ns | 31,731.61 | 315.73 | 656.2500 | 179.6875 | 70.3125 | 10123039 B | NA | +| | | | | | | | | | | | | | +| MyCSharp | Cached | Chrome Win10 | 18.95 ns | 0.720 ns | 0.039 ns | 1.00 | 0.00 | - | - | - | - | NA | +| UAParser | Cached | Chrome Win10 | 126,033.06 ns | 11,193.962 ns | 613.579 ns | 6,652.00 | 30.50 | 2.1973 | - | - | 37400 B | NA | +| | | | | | | | | | | | | | +| MyCSharp | Cached | Google-Bot | 13.42 ns | 1.006 ns | 0.055 ns | 1.00 | 0.00 | - | - | - | - | NA | +| UAParser | Cached | Google-Bot | 108,784.53 ns | 19,649.227 ns | 1,077.040 ns | 8,105.83 | 75.26 | 2.6855 | - | - | 45832 B | NA | ## Disclaimer diff --git a/perf/HttpUserAgentParser.Benchmarks/LibraryComparison/LibraryComparisonBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/LibraryComparison/LibraryComparisonBenchmarks.cs index 7728b48..f1f8c3f 100644 --- a/perf/HttpUserAgentParser.Benchmarks/LibraryComparison/LibraryComparisonBenchmarks.cs +++ b/perf/HttpUserAgentParser.Benchmarks/LibraryComparison/LibraryComparisonBenchmarks.cs @@ -3,8 +3,6 @@ using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Toolchains.InProcess.Emit; using DeviceDetectorNET; using MyCSharp.HttpUserAgentParser; using MyCSharp.HttpUserAgentParser.Providers; @@ -12,17 +10,12 @@ namespace HttpUserAgentParser.Benchmarks.LibraryComparison; // BenchmarkDotNet 0.15.8 cannot build out-of-process jobs for .NET 11, so the short run executes in-process. -[Config(typeof(InProcessShortRunConfig))] +[ShortRunJob] [MemoryDiagnoser] [CategoriesColumn] [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] public class LibraryComparisonBenchmarks { - private sealed class InProcessShortRunConfig : ManualConfig - { - public InProcessShortRunConfig() => AddJob(Job.ShortRun.WithToolchain(InProcessEmitToolchain.Instance)); - } - public record TestData(string Label, string UserAgent) { public override string ToString() => Label; diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index ad2deb1..a567fca 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -280,55 +280,30 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri /// public static string? GetRobot(string userAgent) { - ReadOnlySpan ua = userAgent.AsSpan(); - (string Key, string Value)[] robots = HttpUserAgentRules.Robots; - string[] defaultKeys = HttpUserAgentRules.DefaultRobotKeys; + HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; - // Googlebot, by far the most common robot, comes first: if the entry is unchanged and matches, it wins. - (string firstKey, string firstValue) = robots[0]; - if (ReferenceEquals(firstKey, defaultKeys[0]) && ContainsIgnoreCase(ua, firstKey)) + // The first robot (Googlebot in the default list, by far the most common robot) is checked on its own. + if (robots.FirstKey is { } firstKey && ContainsIgnoreCase(userAgent, firstKey)) { - return firstValue; + return robots.FirstValue; } - if (HttpUserAgentRules.AreRobotKeysUnchanged()) - { - // The few anchors rule out most user agents (browsers) before the full key search. - if (!HttpUserAgentRules.RobotAnchorMatcher.ContainsAny(ua)) - { - return null; - } - - int index = HttpUserAgentRules.RobotMatcher.Find(ua, 1, out _); - return index >= 0 ? robots[index].Value : null; - } + return FindRobot(userAgent, robots); + } - // The public array is mutable and callers replaced keys: they are checked one by one, in array order. -#if NET9_0_OR_GREATER - // Default keys are filtered by group. - foreach (ref readonly PriorityTokenGroup group in HttpUserAgentRules.RobotMatcher.Groups) - { - bool mayMatchDefaultKey = group.MayMatch(ua); - for (int i = group.Start; i < group.End; i++) - { - (string key, string value) = robots[i]; - if ((mayMatchDefaultKey || !ReferenceEquals(key, defaultKeys[i])) && ContainsIgnoreCase(ua, key)) - { - return value; - } - } - } -#else - foreach ((string key, string value) in robots) + /// + /// Finds the first robot after the first one; separate from , so its check of the first robot stays small. + /// + private static string? FindRobot(ReadOnlySpan ua, HttpUserAgentRobotSet robots) + { + // The few anchors rule out most user agents (browsers) before the full key search. + if (!robots.AnchorMatcher.ContainsAny(ua)) { - if (ContainsIgnoreCase(ua, key)) - { - return value; - } + return null; } -#endif - return null; + int index = robots.Matcher.Find(ua, 1, out _); + return index >= 0 ? robots.Entries[index].Value : null; } /// diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs new file mode 100644 index 0000000..a0d2227 --- /dev/null +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -0,0 +1,70 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Collections.ObjectModel; + +namespace MyCSharp.HttpUserAgentParser; + +/// +/// An immutable list of robots with the matchers the parser needs for it. +/// +/// +/// creates a new set and replaces the current one atomically; a parse reads the +/// current set once, so it never sees a partially replaced list. +/// +internal sealed class HttpUserAgentRobotSet +{ + /// + /// Creates the set for in priority order; the array must not be changed afterwards. + /// + public HttpUserAgentRobotSet((string Key, string Value)[] robots) + { + Entries = robots; + ReadOnlyEntries = Array.AsReadOnly(robots); + Keys = Array.ConvertAll(robots, static robot => robot.Key); + + // Without robots there is no first robot. + (FirstKey, FirstValue) = robots.Length > 0 ? robots[0] : (null, null); + + // The first robot is checked on its own (Googlebot in the default list, by far the most common robot): own group. + Matcher = Keys.Length > 1 + ? new PriorityTokenMatcher(Keys, 1) + : new PriorityTokenMatcher(Keys); + AnchorMatcher = new PriorityTokenMatcher( + HttpUserAgentRules.CreateRobotAnchors(Keys, HttpUserAgentRules.CuratedRobotAnchors)); + } + + /// + /// Gets the key of the first robot, or without robots. + /// + public string? FirstKey { get; } + + /// + /// Gets the name of the first robot. + /// + public string? FirstValue { get; } + + /// + /// Gets the robots in priority order. + /// + public (string Key, string Value)[] Entries { get; } + + /// + /// Gets the robots as read-only list for . + /// + public ReadOnlyCollection<(string Key, string Value)> ReadOnlyEntries { get; } + + /// + /// Gets the keys of . + /// + public string[] Keys { get; } + + /// + /// Gets the matcher over . + /// + public PriorityTokenMatcher Matcher { get; } + + /// + /// Gets the matcher over the anchors: every key contains one, so a user agent without any anchor matches no key. + /// + public PriorityTokenMatcher AnchorMatcher { get; } +} diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 10e7433..712c437 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -139,9 +139,9 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) ]; /// - /// Robot rules. This array instance is exposed as ; entries replaced by callers are honored. + /// The default robots in priority order (); never changed. /// - internal static readonly (string Key, string Value)[] Robots = + internal static readonly (string Key, string Value)[] DefaultRobots = [ ( "googlebot", "Googlebot" ), ( "meta-externalagent", "meta-externalagent" ), @@ -243,16 +243,6 @@ internal static readonly (string Key, string Value)[] Robots = ( "YouBot/", "YouBot" ), ]; - /// - /// The default robot keys, used to detect entries replaced by callers. - /// - internal static readonly string[] DefaultRobotKeys = Array.ConvertAll(Robots, static robot => robot.Key); - - /// - /// Robot token matcher over the default keys. "googlebot" gets its own group: it is by far the most common robot. - /// - internal static readonly PriorityTokenMatcher RobotMatcher = new(DefaultRobotKeys, 1); - /// /// Short substrings ("anchors") of the default robot keys. Every key contains at least one anchor, /// so a user agent without any anchor cannot match a default key. The few anchors need far fewer searches @@ -267,9 +257,21 @@ internal static readonly (string Key, string Value)[] Robots = ]; /// - /// Matcher over the robot anchors, see . + /// The default robots with their matchers. + /// + internal static readonly HttpUserAgentRobotSet DefaultRobotSet = new(DefaultRobots); + + private static HttpUserAgentRobotSet s_robotSet = DefaultRobotSet; + + /// + /// Gets the robots the parser detects. + /// + internal static HttpUserAgentRobotSet RobotSet => Volatile.Read(ref s_robotSet); + + /// + /// Replaces the robots the parser detects. /// - internal static readonly PriorityTokenMatcher RobotAnchorMatcher = new(CreateRobotAnchors(DefaultRobotKeys, CuratedRobotAnchors)); + internal static void SetRobotSet(HttpUserAgentRobotSet robotSet) => Volatile.Write(ref s_robotSet, robotSet); /// /// Returns plus every key that contains none of them, @@ -289,28 +291,6 @@ internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAncho return [.. anchors]; } - /// - /// Returns if no key of has been replaced. - /// - /// - /// Compares the key references with . Replaced display names (values) do not matter: - /// the parser returns the current value of the matching entry. - /// - internal static bool AreRobotKeysUnchanged() - { - ReadOnlySpan defaultKeys = DefaultRobotKeys; - ReadOnlySpan<(string Key, string Value)> robots = Robots.AsSpan(0, defaultKeys.Length); - for (int i = 0; i < defaultKeys.Length; i++) - { - if (!ReferenceEquals(robots[i].Key, defaultKeys[i])) - { - return false; - } - } - - return true; - } - /// /// Mobile device rules in priority order: the most specific match wins. /// diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index 8c13aa1..3a849a8 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -10,7 +10,7 @@ namespace MyCSharp.HttpUserAgentParser; /// /// /// The parser does not read , , or ; -/// they are provided for consumers. is shared with the parser: replaced entries are honored. +/// they are provided for consumers. The parser detects the ; change them with . /// All regular expressions are source-generated (no runtime compilation, trimming and Native AOT compatible). /// public static class HttpUserAgentStatics @@ -119,12 +119,46 @@ public static class HttpUserAgentStatics public static readonly FrozenDictionary Mobiles = HttpUserAgentRules.CreateMobileDictionary(); /// - /// Robots + /// The robots the parser detects, in priority order: the first entry whose key occurs in the user agent wins. /// /// - /// The parser uses this array directly: the first matching entry wins and replaced entries are honored. + /// Read-only; replaces the list. Initially . /// - public static readonly (string Key, string Value)[] Robots = HttpUserAgentRules.Robots; + public static IReadOnlyList<(string Key, string Value)> Robots => HttpUserAgentRules.RobotSet.ReadOnlyEntries; + + /// + /// The robots of this library, in priority order. + /// + public static IReadOnlyList<(string Key, string Value)> DefaultRobots => HttpUserAgentRules.DefaultRobotSet.ReadOnlyEntries; + + /// + /// Replaces the robots the parser detects, in priority order: the first entry whose key occurs in the user agent + /// (ignoring case) wins, and its value is the robot name. + /// + /// + /// The list applies to all following parses in the process; it is replaced atomically, so a parse running at the same + /// time uses either the previous or the new list. To extend the defaults, pass e.g. + /// [.. HttpUserAgentStatics.DefaultRobots, ("MyCrawler", "My Crawler")]; restores them. + /// Building the matchers takes a moment, so set the list once at startup rather than per request. + /// + /// The robots in priority order. + /// is . + /// A key is or empty, or a value is . + public static void SetRobots(IEnumerable<(string Key, string Value)> robots) + { + ArgumentNullException.ThrowIfNull(robots); + + (string Key, string Value)[] entries = [.. robots]; + foreach ((string key, string value) in entries) + { + if (string.IsNullOrEmpty(key) || value is null) + { + throw new ArgumentException("A robot needs a key that is not empty and a value.", nameof(robots)); + } + } + + HttpUserAgentRules.SetRobotSet(new HttpUserAgentRobotSet(entries)); + } /// /// Tools diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs index 9c757ea..a6bcdab 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -1,87 +1,103 @@ // Copyright © https://myCSharp.de - all rights reserved +using MyCSharp.HttpUserAgentParser.TestHelpers; using MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests; /// -/// is a public, mutable array that the parser reads directly. -/// Replacing an entry changes process-wide state, so these tests run in the non-parallel collection. +/// changes process-wide state, so these tests run in the non-parallel collection +/// and restore the default robots afterwards. /// [Collection(TelemetryCollection.Name)] -public class HttpUserAgentStaticsRobotsReplacementTests +public sealed class HttpUserAgentStaticsRobotsReplacementTests : IDisposable { + private const string Chrome = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"; + + public void Dispose() => HttpUserAgentRules.SetRobotSet(HttpUserAgentRules.DefaultRobotSet); + [Fact] - public void Robots_Are_Unchanged_By_Default() + public void Robots_Are_The_Defaults_And_Read_Only() { - Assert.True(HttpUserAgentRules.AreRobotKeysUnchanged()); - Assert.Equal("YouBot", HttpUserAgentParser.GetRobot(HttpUserAgentStatics.Robots[^1].Key)); + Assert.Same(HttpUserAgentRules.DefaultRobotSet, HttpUserAgentRules.RobotSet); + Assert.Equal(HttpUserAgentStatics.DefaultRobots, HttpUserAgentStatics.Robots); + Assert.Equal(HttpUserAgentRules.DefaultRobots, HttpUserAgentStatics.Robots); + Assert.IsNotType<(string Key, string Value)[]>(HttpUserAgentStatics.Robots, exactMatch: false); + Assert.Throws(() => ((IList<(string Key, string Value)>)HttpUserAgentStatics.Robots)[0] = ("x", "y")); } [Fact] - public void GetRobot_UsesReplacementRuleInOriginalOrder() + public void SetRobots_Extends_The_Defaults() { - int last = HttpUserAgentStatics.Robots.Length - 1; - (string Key, string Value) original = HttpUserAgentStatics.Robots[last]; - - try - { - HttpUserAgentStatics.Robots[last] = ("CustomTestCrawler", "Custom crawler"); - Assert.False(HttpUserAgentRules.AreRobotKeysUnchanged()); - - Assert.Equal("Custom crawler", HttpUserAgentParser.GetRobot("customtestcrawler/1.0")); - Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("customtestcrawler/1.0 googlebot/2.1")); - Assert.Equal("BingBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); - Assert.Null(HttpUserAgentParser.GetRobot(original.Key)); - Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/158.0.0.0")); - } - finally - { - HttpUserAgentStatics.Robots[last] = original; - } + HttpUserAgentStatics.SetRobots([.. HttpUserAgentStatics.DefaultRobots, ("CustomTestCrawler", "Custom crawler")]); - Assert.True(HttpUserAgentRules.AreRobotKeysUnchanged()); + Assert.Equal("Custom crawler", HttpUserAgentParser.GetRobot("customtestcrawler/1.0")); + Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("customtestcrawler/1.0 googlebot/2.1")); // priority order + Assert.Equal("BingBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); + Assert.Null(HttpUserAgentParser.GetRobot(Chrome)); + Assert.Equal(HttpUserAgentType.Robot, HttpUserAgentParser.Parse("customtestcrawler/1.0").Type); } [Fact] - public void GetRobot_Returns_Replaced_Display_Name() + public void SetRobots_Replaces_Keys_And_Names() { - int index = Array.FindIndex(HttpUserAgentStatics.Robots, static robot => string.Equals(robot.Key, "bingbot", StringComparison.Ordinal)); - (string Key, string Value) original = HttpUserAgentStatics.Robots[index]; + HttpUserAgentStatics.SetRobots([("ExampleBot", "Example"), ("bingbot", "Bing crawler")]); - try - { - // Only the display name changes: the keys are unchanged, so the fast path stays active. - HttpUserAgentStatics.Robots[index] = (original.Key, "Bing crawler"); - Assert.True(HttpUserAgentRules.AreRobotKeysUnchanged()); + Assert.Equal("Example", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; ExampleBot/1.0)")); // first entry + Assert.Equal("Bing crawler", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); + Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")); + Assert.Null(HttpUserAgentParser.GetRobot(Chrome)); + } - Assert.Equal("Bing crawler", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); - } - finally - { - HttpUserAgentStatics.Robots[index] = original; - } + [Fact] + public void SetRobots_Accepts_A_Single_Robot_And_No_Robots() + { + HttpUserAgentStatics.SetRobots([("ExampleBot", "Example")]); + Assert.Equal("Example", HttpUserAgentParser.GetRobot("ExampleBot/1.0")); + Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); + + HttpUserAgentStatics.SetRobots([]); + Assert.Empty(HttpUserAgentStatics.Robots); + Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; Googlebot/2.1)")); + Assert.Equal(HttpUserAgentType.Browser, HttpUserAgentParser.Parse(Chrome).Type); } [Fact] - public void GetRobot_Honors_Replaced_First_Entry() + public void SetRobots_Keeps_No_Reference_To_The_Input() { - (string Key, string Value) original = HttpUserAgentStatics.Robots[0]; + (string Key, string Value)[] robots = [("ExampleBot", "Example")]; + HttpUserAgentStatics.SetRobots(robots); - try - { - HttpUserAgentStatics.Robots[0] = ("ExampleBot", "Example"); + robots[0] = ("OtherBot", "Other"); - Assert.Equal("Example", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; ExampleBot/1.0)")); - Assert.Null(HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")); - Assert.Equal("BingBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; bingbot/2.0)")); - } - finally + Assert.Equal("Example", HttpUserAgentParser.GetRobot("ExampleBot/1.0")); + Assert.Null(HttpUserAgentParser.GetRobot("OtherBot/1.0")); + } + + [Fact] + public void SetRobots_With_The_Defaults_Detects_Like_The_Defaults() + { + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); + + Assert.NotSame(HttpUserAgentRules.DefaultRobotSet, HttpUserAgentRules.RobotSet); + foreach (string userAgent in UserAgentCatalog.All) { - HttpUserAgentStatics.Robots[0] = original; + HttpUserAgentRules.SetRobotSet(HttpUserAgentRules.DefaultRobotSet); + string? expected = HttpUserAgentParser.GetRobot(userAgent); + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); + Assert.Equal(expected, HttpUserAgentParser.GetRobot(userAgent)); } + } + + [Fact] + public void SetRobots_Rejects_Invalid_Robots() + { + Assert.Throws(() => HttpUserAgentStatics.SetRobots(null!)); + Assert.Throws(() => HttpUserAgentStatics.SetRobots([("", "Empty")])); + Assert.Throws(() => HttpUserAgentStatics.SetRobots([(null!, "Null")])); + Assert.Throws(() => HttpUserAgentStatics.SetRobots([("bot", null!)])); - Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")); + Assert.Same(HttpUserAgentRules.DefaultRobotSet, HttpUserAgentRules.RobotSet); // unchanged } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index bfc77c2..0dd584f 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -147,10 +147,10 @@ public void Mobiles_Contain_All_Rules() } [Fact] - public void Robots_Is_The_Array_Used_By_The_Parser() + public void DefaultRobots_Are_The_Robots_Of_The_Library() { - Assert.Same(HttpUserAgentRules.Robots, HttpUserAgentStatics.Robots); - Assert.Contains(("googlebot", "Googlebot"), HttpUserAgentStatics.Robots); + Assert.Equal(HttpUserAgentRules.DefaultRobots, HttpUserAgentStatics.DefaultRobots); + Assert.Contains(("googlebot", "Googlebot"), HttpUserAgentStatics.DefaultRobots); } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs index ee45240..d91df08 100644 --- a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs @@ -154,11 +154,11 @@ public void Groups_Start_At_Requested_Indices() [Fact] public void Built_In_Matchers_Use_Small_Vectorized_Groups() { - Assert.All(HttpUserAgentRules.RobotMatcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); + Assert.All(HttpUserAgentRules.DefaultRobotSet.Matcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); Assert.All(HttpUserAgentRules.MobileMatcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); // Googlebot, by far the most common robot, is checked on its own. - Assert.Equal((0, 1), (HttpUserAgentRules.RobotMatcher.Groups[0].Start, HttpUserAgentRules.RobotMatcher.Groups[0].End)); + Assert.Equal((0, 1), (HttpUserAgentRules.DefaultRobotSet.Matcher.Groups[0].Start, HttpUserAgentRules.DefaultRobotSet.Matcher.Groups[0].End)); } #endif @@ -185,7 +185,7 @@ public void Curated_Robot_Anchors_Cover_All_Default_Robot_Keys() { // When a new robot key is not covered, it becomes an anchor on its own (correct, but an extra search). // Extend the curated anchors instead. - Assert.Equal(HttpUserAgentRules.CuratedRobotAnchors.Length, HttpUserAgentRules.RobotAnchorMatcher.Count); + Assert.Equal(HttpUserAgentRules.CuratedRobotAnchors.Length, HttpUserAgentRules.DefaultRobotSet.AnchorMatcher.Count); } public static TheoryData CatalogBrowserUserAgents => [.. UserAgentCatalog.Browsers.Select(static ua => ua.UserAgent)]; @@ -194,7 +194,7 @@ public void Curated_Robot_Anchors_Cover_All_Default_Robot_Keys() [MemberData(nameof(CatalogBrowserUserAgents))] public void Robot_Anchors_Do_Not_Occur_In_Browser_User_Agents(string userAgent) { - Assert.False(HttpUserAgentRules.RobotAnchorMatcher.ContainsAny(userAgent)); + Assert.False(HttpUserAgentRules.DefaultRobotSet.AnchorMatcher.ContainsAny(userAgent)); } [Theory] @@ -221,7 +221,7 @@ public void GetRobot_Equals_Sequential_Scan(string userAgent) public void Built_In_Matchers_Equal_Sequential_Scan(string userAgent) { AssertEqualsSequentialScan(HttpUserAgentRules.MobileMatcher, [.. HttpUserAgentRules.Mobiles.Select(static rule => rule.Key)], userAgent); - AssertEqualsSequentialScan(HttpUserAgentRules.RobotMatcher, HttpUserAgentRules.DefaultRobotKeys, userAgent); + AssertEqualsSequentialScan(HttpUserAgentRules.DefaultRobotSet.Matcher, HttpUserAgentRules.DefaultRobotSet.Keys, userAgent); } private static void AssertEqualsSequentialScan(PriorityTokenMatcher matcher, string[] tokens, string input) diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs index 628c6f5..b12a9f5 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/TelemetryCollection.cs @@ -5,7 +5,7 @@ namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; /// -/// Telemetry switches and are process-wide static state. Tests that change or depend on it run in this collection, +/// Telemetry switches and the robots set with are process-wide static state. Tests that change or depend on it run in this collection, /// which is not parallelized and runs after all parallel tests, so no other test observes a foreign telemetry state. /// [CollectionDefinition(Name, DisableParallelization = true)] From 4964bfe5d01b94801fd6ebefbe45fd4a544b8606 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 09:43:21 +0100 Subject: [PATCH 11/41] refactor(parser): update robot rules handling and telemetry --- README.md | 2 +- .../HttpUserAgentParserAspNetCoreMeters.cs | 7 +- .../HttpUserAgentParserAspNetCoreTelemetry.cs | 12 +- ...HttpUserAgentParserMemoryCachedProvider.cs | 29 +++- .../HttpUserAgentParserMemoryCacheMeters.cs | 7 +- ...HttpUserAgentParserMemoryCacheTelemetry.cs | 12 +- .../HttpUserAgentParser.cs | 108 +++++++++++--- .../HttpUserAgentRobotSet.cs | 6 +- src/HttpUserAgentParser/HttpUserAgentRules.cs | 23 ++- .../HttpUserAgentStatics.cs | 21 +-- .../HttpUserAgentParserCachedProvider.cs | 43 ++++-- .../HttpUserAgentParserMeterRegistration.cs | 139 ++++++++++++++---- .../Telemetry/HttpUserAgentParserMeters.cs | 11 +- .../Telemetry/HttpUserAgentParserTelemetry.cs | 12 +- ...gentParserMemoryCacheTelemetryPathTests.cs | 62 ++++++++ .../Program.cs | 8 + .../HttpUserAgentParserTests.cs | 40 +++++ ...pUserAgentStaticsRobotsReplacementTests.cs | 60 ++++++++ .../HttpUserAgentStaticsTests.cs | 19 +-- ...HttpUserAgentParserMetersTelemetryTests.cs | 46 ++++++ .../HttpUserAgentParserTelemetryPathTests.cs | 40 ++++- 21 files changed, 569 insertions(+), 138 deletions(-) diff --git a/README.md b/README.md index a8af544..11106a2 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ The patterns use `RegexOptions.IgnoreCase` with culture-invariant case mapping, ### Custom robots -`HttpUserAgentStatics.Robots` lists the robots the parser detects (read-only, initially `HttpUserAgentStatics.DefaultRobots`). `HttpUserAgentStatics.SetRobots` replaces the list for all following parses in the process; the first entry whose key occurs in the user agent (ignoring case) wins. Set it once at startup, building the matchers takes a moment: +`HttpUserAgentStatics.Robots` lists the robots in priority order. The first key found in the user agent wins, ignoring case. `SetRobots` replaces the list for the entire process, including existing instances of both built-in cache providers. A parse already in progress can finish with its previous rules. To extend the defaults at startup, pass the default entries followed by your own. ```csharp HttpUserAgentStatics.SetRobots([.. HttpUserAgentStatics.DefaultRobots, ("MyCrawler", "My Crawler")]); diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 8e7624a..48d3b22 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -39,7 +39,8 @@ public static string GetMeterName(string? meterPrefix) private static readonly HttpUserAgentParserMeterRegistration s_registration = new( static meter => new Instruments(meter), static _ => { }, // no instrument in common with the other packages: a meter may be shared - static () => { }); + static () => { }, + HttpUserAgentParserAspNetCoreTelemetry.MarkMetersEnabled); /// /// Creates the metric instruments on (or on a default meter) and uses them from now on. @@ -82,8 +83,8 @@ private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstrume public override void CreateMissingInstruments() { - _userAgentPresent ??= Meter.CreateCounter(name: "user_agent.present", unit: "{call}", description: "User-Agent header present"); - _userAgentMissing ??= Meter.CreateCounter(name: "user_agent.missing", unit: "{call}", description: "User-Agent header missing"); + CreateInstrument(ref _userAgentPresent, Meter.CreateCounter, "user_agent.present", "{call}", "User-Agent header present"); + CreateInstrument(ref _userAgentMissing, Meter.CreateCounter, "user_agent.missing", "{call}", "User-Agent header missing"); } } } diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs index 15c437e..fa139e2 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs @@ -59,19 +59,15 @@ public static void Enable() /// Enables native System.Diagnostics.Metrics telemetry for the AspNetCore package. /// public static void EnableMeters(Meter? meter = null) - { - HttpUserAgentParserAspNetCoreMeters.Enable(meter); - Interlocked.Or(ref s_enabledFlags, MetersFlag); - } + => HttpUserAgentParserAspNetCoreMeters.Enable(meter); /// /// Enables native System.Diagnostics.Metrics telemetry with a meter named that the package owns. /// public static void EnableMetersWithName(string meterName) - { - HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter(meterName); - Interlocked.Or(ref s_enabledFlags, MetersFlag); - } + => HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter(meterName); + + internal static void MarkMetersEnabled() => Interlocked.Or(ref s_enabledFlags, MetersFlag); /// /// Records telemetry indicating that a User-Agent header was present. diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index 328c90d..c63d613 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -1,6 +1,8 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Runtime.CompilerServices; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Primitives; using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; using MyCSharp.HttpUserAgentParser.Providers; @@ -15,6 +17,18 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache; /// public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvider, IDisposable { + // MemoryCache checks passive expiration tokens on every lookup, also when a miss from an + // older generation finishes after SetRobots. The cache key and callback value stay public types. + internal sealed class RobotRulesChangeToken(IReadOnlyList<(string Key, string Value)> entries) : IChangeToken + { + public bool HasChanged => !ReferenceEquals(entries, HttpUserAgentRules.RobotSet.ReadOnlyEntries); + public bool ActiveChangeCallbacks => false; + public IDisposable RegisterChangeCallback(Action callback, object? state) + => CancellationToken.None.Register(callback, state); + } + + private static readonly ConditionalWeakTable s_changeTokens = new(); + /// /// The name of the Meter used for metrics. /// @@ -82,14 +96,19 @@ public void Dispose() /// private HttpUserAgentInformation ParseAndCache(string userAgent) { - HttpUserAgentInformation information = HttpUserAgentParser.Parse(userAgent); + HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; + HttpUserAgentInformation information = HttpUserAgentParser.Parse(userAgent, robots); MemoryCacheEntryOptions entryOptions = _options.CacheEntryOptions; - using ICacheEntry entry = _memoryCache.CreateEntry(userAgent); - entry.SetOptions(entryOptions); - entry.Size = entryOptions.Size ?? 1; - entry.Value = information; + using (ICacheEntry entry = _memoryCache.CreateEntry(userAgent)) + { + entry.SetOptions(entryOptions); + entry.ExpirationTokens.Add(s_changeTokens.GetValue(robots, static rules => new RobotRulesChangeToken(rules.ReadOnlyEntries))); + entry.Size = entryOptions.Size ?? 1; + entry.Value = information; + } + // Listeners can parse the same user agent. Publish the entry before notifying them. if (HttpUserAgentParserMemoryCacheTelemetry.IsEnabled) { HttpUserAgentParserMemoryCacheTelemetry.CacheMiss(); diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index c0ce668..103d3f0 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -34,7 +34,8 @@ public static string GetMeterName(string? meterPrefix) private static readonly HttpUserAgentParserMeterRegistration s_registration = new( static meter => new Instruments(meter), HttpUserAgentParserCacheMeterGuard.ReserveForMemoryCache, // the core and the MemoryCache package must not share a meter - HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests); + HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests, + HttpUserAgentParserMemoryCacheTelemetry.MarkMetersEnabled); public static bool IsEnabled => s_registration.Current is not null; @@ -71,8 +72,8 @@ private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstrume public override void CreateMissingInstruments() { - _cacheHit ??= Meter.CreateCounter(name: "cache.hit", unit: "{call}", description: "Cache hit"); - _cacheMiss ??= Meter.CreateCounter(name: "cache.miss", unit: "{call}", description: "Cache miss"); + CreateInstrument(ref _cacheHit, Meter.CreateCounter, "cache.hit", "{call}", "Cache hit"); + CreateInstrument(ref _cacheMiss, Meter.CreateCounter, "cache.miss", "{call}", "Cache miss"); // Observable instruments are not shared by the meter: created at most once, also if a listener threw. if (Interlocked.Exchange(ref _cacheSizeCreated, 1) == 0) diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs index ac9a5f2..5b1a6df 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs @@ -41,19 +41,15 @@ public static void Enable() /// Enables native System.Diagnostics.Metrics telemetry for the MemoryCache provider. /// public static void EnableMeters(Meter? meter = null) - { - HttpUserAgentParserMemoryCacheMeters.Enable(meter); - Interlocked.Or(ref s_enabledFlags, MetersFlag); - } + => HttpUserAgentParserMemoryCacheMeters.Enable(meter); /// /// Enables native System.Diagnostics.Metrics telemetry with a meter named that the package owns. /// public static void EnableMetersWithName(string meterName) - { - HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter(meterName); - Interlocked.Or(ref s_enabledFlags, MetersFlag); - } + => HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter(meterName); + + internal static void MarkMetersEnabled() => Interlocked.Or(ref s_enabledFlags, MetersFlag); /// /// Records a cache hit. diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index a567fca..d6c6854 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -21,7 +21,7 @@ public static class HttpUserAgentParser /// Characters that end a product token ("product/version") or a comment entry of a user agent. /// A token starts at the beginning of the user agent or after one of them; + stands for a space in URL-encoded logs. /// - private static readonly SearchValues s_productTokenDelimiters = SearchValues.Create(" \t;(),+"); + private static readonly SearchValues s_productTokenDelimiters = SearchValues.Create(" \t;(),"); /// /// Parses given user agent @@ -31,10 +31,13 @@ public static class HttpUserAgentParser /// The telemetry check is designed to be zero-overhead when disabled (using a volatile boolean check). /// public static HttpUserAgentInformation Parse(string userAgent) + => Parse(userAgent, HttpUserAgentRules.RobotSet); + + internal static HttpUserAgentInformation Parse(string userAgent, HttpUserAgentRobotSet robots) { if (!HttpUserAgentParserTelemetry.IsEnabled) { - return ParseInternal(userAgent); + return ParseInternal(userAgent, robots); } bool measureDuration = HttpUserAgentParserTelemetry.ShouldMeasureParseDuration; @@ -42,7 +45,7 @@ public static HttpUserAgentInformation Parse(string userAgent) HttpUserAgentParserTelemetry.ParseRequest(); - HttpUserAgentInformation result = ParseInternal(userAgent); + HttpUserAgentInformation result = ParseInternal(userAgent, robots); if (measureDuration) { @@ -52,21 +55,26 @@ public static HttpUserAgentInformation Parse(string userAgent) return result; } - private static HttpUserAgentInformation ParseInternal(string userAgent) + private static HttpUserAgentInformation ParseInternal(string userAgent, HttpUserAgentRobotSet robots) { // prepare userAgent = Cleanup(userAgent); // analyze - if (TryGetRobot(userAgent, out string? robotName)) + if (GetRobot(userAgent, robots) is { } robotName) { return HttpUserAgentInformation.CreateForRobot(userAgent, robotName); } - HttpUserAgentPlatformInformation? platform = GetPlatform(userAgent); - string? mobileDeviceType = GetMobileDevice(userAgent); + return DetectProducts(userAgent, AnalyzeProducts); + } - if (GetBrowser(userAgent) is { } browser) + private static HttpUserAgentInformation AnalyzeProducts(string userAgent, ReadOnlySpan ua) + { + HttpUserAgentPlatformInformation? platform = FindPlatform(ua); + string? mobileDeviceType = FindMobileDevice(ua); + + if (FindBrowser(ua) is { } browser) { return HttpUserAgentInformation.CreateForBrowser(userAgent, platform, browser.Name, browser.Version, mobileDeviceType); } @@ -74,6 +82,38 @@ private static HttpUserAgentInformation ParseInternal(string userAgent) return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType); } + private delegate T ProductDetector(string original, ReadOnlySpan products); + + // IIS logs use '+' for spaces, including spaces inside product names. Keep the original + // string in the result and use the decoded span for all three product detectors. + private static T DetectProducts(string userAgent, ProductDetector detect) + { + ReadOnlySpan ua = userAgent.AsSpan(); + if (!ua.Contains('+')) + { + return detect(userAgent, ua); + } + + if (ua.Length <= 512) + { + Span decoded = stackalloc char[ua.Length]; + ua.Replace(decoded, '+', ' '); + return detect(userAgent, decoded); + } + + char[] buffer = ArrayPool.Shared.Rent(ua.Length); + try + { + Span decoded = buffer.AsSpan(0, ua.Length); + ua.Replace(decoded, '+', ' '); + return detect(userAgent, decoded); + } + finally + { + ArrayPool.Shared.Return(buffer); + } + } + /// /// pre-cleanup of user agent /// @@ -83,10 +123,12 @@ private static HttpUserAgentInformation ParseInternal(string userAgent) /// returns the platform or null /// public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent) + => DetectProducts(userAgent, static (_, ua) => FindPlatform(ua)); + + private static HttpUserAgentPlatformInformation? FindPlatform(ReadOnlySpan ua) { // Rules are sorted by frequency, so a sequential scan usually stops after a few tokens. // (Measured with a mixed real-world workload, this beats vectorized token groups here.) - ReadOnlySpan ua = userAgent.AsSpan(); foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { if (ContainsIgnoreCase(ua, token)) @@ -116,9 +158,10 @@ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out Http /// or after a space, tab, +, ;, (, ) or ,. /// public static (string Name, string? Version)? GetBrowser(string userAgent) - { - ReadOnlySpan ua = userAgent.AsSpan(); + => DetectProducts(userAgent, static (_, ua) => FindBrowser(ua)); + private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua) + { foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) { // Fast path: most rules do not match at all, and a match usually starts a token. @@ -159,16 +202,31 @@ private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectTo // A separate version token after the detect token ("Opera/9.80 ... Version/12.16", "Trident/7.0; rv:11.0"); with the same // token as the detect token (Safari "Version/", "MSIE 6.0") the detect token has been found already. - int versionIndex = string.Equals(detectToken, versionToken, StringComparison.Ordinal) - ? detectIndex - : IndexOfTokenStart(ua, versionToken, detectIndex + detectToken.Length); - if (versionIndex >= 0) + if (string.Equals(detectToken, versionToken, StringComparison.Ordinal)) { - return TryReadVersion(ua, versionToken, versionIndex, allowSpace: true, out version); + return TryReadVersion(ua, detectToken, detectIndex, allowSpace: true, out version); } - // Without version token the version follows the detect token ("Opera/9.80", "Opera 9.50"). - return TryReadVersion(ua, detectToken, detectIndex, allowSpace: true, out version); + // A separate version belongs to a complete product name. Skip prefixes such as TridentSpider. + while (detectIndex >= 0) + { + int end = detectIndex + detectToken.Length; + if (end == ua.Length || ua[end] == '/' || s_productTokenDelimiters.Contains(ua[end])) + { + int versionIndex = IndexOfTokenStart(ua, versionToken, end); + if (versionIndex >= 0 && TryReadVersion(ua, versionToken, versionIndex, allowSpace: true, out version)) + { + return true; + } + + return TryReadVersion(ua, detectToken, detectIndex, allowSpace: true, out version); + } + + detectIndex = IndexOfTokenStart(ua, detectToken, end); + } + + version = default; + return false; } /// @@ -240,7 +298,7 @@ private static bool IsTokenStart(ReadOnlySpan ua, int index) /// Returns whether separates a product name from its version in Token 1.2 /// (+ stands for a space in URL-encoded logs). /// - private static bool IsSpace(char c) => c is ' ' or '\t' or '+'; + private static bool IsSpace(char c) => c is ' ' or '\t'; /// /// Returns the index of the first occurrence of at or after @@ -279,9 +337,10 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri /// returns the robot or null /// public static string? GetRobot(string userAgent) - { - HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; + => GetRobot(userAgent, HttpUserAgentRules.RobotSet); + private static string? GetRobot(string userAgent, HttpUserAgentRobotSet robots) + { // The first robot (Googlebot in the default list, by far the most common robot) is checked on its own. if (robots.FirstKey is { } firstKey && ContainsIgnoreCase(userAgent, firstKey)) { @@ -292,7 +351,7 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri } /// - /// Finds the first robot after the first one; separate from , so its check of the first robot stays small. + /// Finds the first robot after the first one; separate from , so its check of the first robot stays small. /// private static string? FindRobot(ReadOnlySpan ua, HttpUserAgentRobotSet robots) { @@ -319,8 +378,11 @@ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? /// returns the device or null /// public static string? GetMobileDevice(string userAgent) + => DetectProducts(userAgent, static (_, ua) => FindMobileDevice(ua)); + + private static string? FindMobileDevice(ReadOnlySpan ua) { - int index = HttpUserAgentRules.MobileMatcher.Find(userAgent, 0, out _); + int index = HttpUserAgentRules.MobileMatcher.Find(ua, 0, out _); return index >= 0 ? HttpUserAgentRules.Mobiles[index].Value : null; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs index a0d2227..399c370 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -1,7 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Collections.ObjectModel; - namespace MyCSharp.HttpUserAgentParser; /// @@ -19,7 +17,7 @@ internal sealed class HttpUserAgentRobotSet public HttpUserAgentRobotSet((string Key, string Value)[] robots) { Entries = robots; - ReadOnlyEntries = Array.AsReadOnly(robots); + ReadOnlyEntries = [.. robots]; Keys = Array.ConvertAll(robots, static robot => robot.Key); // Without robots there is no first robot. @@ -51,7 +49,7 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) /// /// Gets the robots as read-only list for . /// - public ReadOnlyCollection<(string Key, string Value)> ReadOnlyEntries { get; } + public IReadOnlyList<(string Key, string Value)> ReadOnlyEntries { get; } /// /// Gets the keys of . diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 712c437..edb9193 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -43,7 +43,6 @@ internal static readonly (string Token, HttpUserAgentPlatformInformation Platfor ("ipod", new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS)), // ChromeOS ("CrOS x86_64"), before "os x", which "CrOS x86_64" contains; with the space, "Microsoft" does not match ("cros ", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), - ("cros+", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), // URL-encoded logs // Mac OS (common) ("os x", new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS)), // Linux (common) @@ -65,21 +64,21 @@ internal static readonly (string Token, HttpUserAgentPlatformInformation Platfor ("blackberry", new(HttpUserAgentPlatformRegexId.BlackBerry, "BlackBerry", HttpUserAgentPlatformType.BlackBerry)), ("ppc mac", new(HttpUserAgentPlatformRegexId.PpcMac, "Power PC Mac", HttpUserAgentPlatformType.MacOS)), ("debian", new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux)), - ("freebsd", new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Linux)), - ("ppc", new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.Linux)), + ("freebsd", new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Unix)), ("gnu", new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux)), - ("unix", new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix)), ("openbsd", new(HttpUserAgentPlatformRegexId.OpenBsd, "OpenBSD", HttpUserAgentPlatformType.Unix)), ("symbian", new(HttpUserAgentPlatformRegexId.Symbian, "Symbian OS", HttpUserAgentPlatformType.Symbian)), - ("sunos", new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Generic)), + ("sunos", new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Unix)), ("beos", new(HttpUserAgentPlatformRegexId.BeOs, "BeOS", HttpUserAgentPlatformType.Generic)), ("apachebench", new(HttpUserAgentPlatformRegexId.ApacheBench, "ApacheBench", HttpUserAgentPlatformType.Generic)), - ("aix", new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Generic)), - ("irix", new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Generic)), - ("osf", new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Generic)), - ("hp-ux", new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Windows)), - ("netbsd", new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Generic)), - ("bsdi", new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Generic)), + ("aix", new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Unix)), + ("irix", new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Unix)), + ("osf", new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Unix)), + ("hp-ux", new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Unix)), + ("netbsd", new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Unix)), + ("bsdi", new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Unix)), + ("unix", new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix)), + ("ppc", new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.MacOS)), ]; /// @@ -92,7 +91,6 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) // Most specific browsers first (contain Chrome/Mozilla in their UA) ("Opera", "OPR", null), ("Opera", "Opera", "Version/"), - ("Opera", "Opera", null), ("Edge", "Edg", null), ("Edge", "Edge", null), ("Edge", "EdgA", null), @@ -155,7 +153,6 @@ internal static readonly (string Key, string Value)[] DefaultRobots = ( "perplexity.ai/perplexitybot", "PerplexityBot" ), ( "developer.amazon.com/support/amazonbot", "Amazonbot" ), ( "trendictionbot", "trendictionbot" ), - ( "openai.com/searchbot", "OAI-SearchBot" ), ( "Bytespider", "Bytespider" ), ( "MojeekBot", "MojeekBot" ), ( "SeekportBot", "SeekportBot" ), diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index 3a849a8..5bb6bf1 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -49,19 +49,19 @@ public static class HttpUserAgentStatics new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS), new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS), new(HttpUserAgentPlatformRegexId.PpcMac, "Power PC Mac", HttpUserAgentPlatformType.MacOS), - new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Linux), - new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.Linux), + new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.MacOS), new(HttpUserAgentPlatformRegexId.Linux, "Linux", HttpUserAgentPlatformType.Linux), new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux), - new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Unix), new(HttpUserAgentPlatformRegexId.BeOs, "BeOS", HttpUserAgentPlatformType.Generic), new(HttpUserAgentPlatformRegexId.ApacheBench, "ApacheBench", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Generic), + new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Unix), + new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Unix), new(HttpUserAgentPlatformRegexId.OpenBsd, "OpenBSD", HttpUserAgentPlatformType.Unix), new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux), new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix), @@ -137,7 +137,8 @@ public static class HttpUserAgentStatics /// /// /// The list applies to all following parses in the process; it is replaced atomically, so a parse running at the same - /// time uses either the previous or the new list. To extend the defaults, pass e.g. + /// time uses either the previous or the new list. Both built-in cache providers honor the change on the next call. + /// To extend the defaults, pass e.g. /// [.. HttpUserAgentStatics.DefaultRobots, ("MyCrawler", "My Crawler")]; restores them. /// Building the matchers takes a moment, so set the list once at startup rather than per request. /// diff --git a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs index 42275f3..7a0948a 100644 --- a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs +++ b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs @@ -16,7 +16,29 @@ public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider /// /// The key is the exact user agent (ordinal): the result contains the user agent, so a differently cased one is another entry. /// - private readonly ConcurrentDictionary _cache = new(StringComparer.Ordinal); + private sealed class Cache(HttpUserAgentRobotSet robots) + { + public HttpUserAgentRobotSet Robots { get; } = robots; + public ConcurrentDictionary Entries { get; } = new(StringComparer.Ordinal); + } + + private Cache _cache = new(HttpUserAgentRules.RobotSet); + + private Cache GetCurrentCache() + { + while (true) + { + Cache cache = Volatile.Read(ref _cache); + HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; + if (ReferenceEquals(cache.Robots, robots)) + { + return cache; + } + + // A parse already in progress can finish writing to its own generation. + Interlocked.CompareExchange(ref _cache, new Cache(robots), cache); + } + } /// /// Creates a provider with an empty cache. @@ -32,32 +54,31 @@ public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider /// public HttpUserAgentInformation Parse(string userAgent) { + Cache cache = GetCurrentCache(); if (!HttpUserAgentParserTelemetry.IsEnabled) { - return _cache.GetOrAdd(userAgent, static ua => HttpUserAgentParser.Parse(ua)); + return cache.Entries.GetOrAdd(userAgent, static (ua, robots) => HttpUserAgentParser.Parse(ua, robots), cache.Robots); } - if (_cache.TryGetValue(userAgent, out HttpUserAgentInformation cached)) + if (cache.Entries.TryGetValue(userAgent, out HttpUserAgentInformation cached)) { HttpUserAgentParserTelemetry.ConcurrentCacheHit(); return cached; } - // Note: ConcurrentDictionary can invoke the factory multiple times in races; counters are best-effort. - return _cache.GetOrAdd(userAgent, static ua => - { - HttpUserAgentParserTelemetry.ConcurrentCacheMiss(); - return HttpUserAgentParser.Parse(ua); - }); + // Report the observed miss after insertion so a synchronous listener can read the entry. + HttpUserAgentInformation information = cache.Entries.GetOrAdd(userAgent, static (ua, robots) => HttpUserAgentParser.Parse(ua, robots), cache.Robots); + HttpUserAgentParserTelemetry.ConcurrentCacheMiss(); + return information; } /// /// Total count of entries in cache /// - public int CacheEntryCount => _cache.Count; + public int CacheEntryCount => GetCurrentCache().Entries.Count; /// /// returns true if given user agent is in cache /// - public bool HasCacheEntry(string userAgent) => _cache.ContainsKey(userAgent); + public bool HasCacheEntry(string userAgent) => GetCurrentCache().Entries.ContainsKey(userAgent); } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs index ef734dd..42be360 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs @@ -11,6 +11,40 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// The meter the instruments belong to. internal abstract class HttpUserAgentParserMeterInstruments(Meter meter) { + // Shared across packages. Listener callbacks may synchronously register another package + // or delegate that work to a task and wait for it. + internal sealed class Publication : IDisposable + { + private static readonly AsyncLocal s_current = new(); + private readonly Publication? _parent = s_current.Value; + private volatile bool _finished; + + public Publication() => s_current.Value = this; + + public static bool InProgress + { + get + { + for (Publication? scope = s_current.Value; scope is not null; scope = scope._parent) + { + if (!scope._finished) + { + return true; + } + } + + return false; + } + } + + public void Dispose() + { + // ExecutionContext may have been captured by a listener for work that runs later. + _finished = true; + s_current.Value = _parent; + } + } + /// /// Gets the meter the instruments belong to. /// @@ -22,10 +56,38 @@ internal abstract class HttpUserAgentParserMeterInstruments(Meter meter) /// /// .NET runs the callbacks while an instrument is created, so listener code /// runs here and may throw or register meters itself; no lock is held. An instrument that was published before a listener - /// threw exists on the meter, so a later call must not create it again: counters and histograms with the same name, unit and - /// description are returned by the meter, observable instruments have to be created at most once by the implementation. + /// threw exists on the meter even when its factory did not return it. /// public abstract void CreateMissingInstruments(); + + protected void CreateInstrument(ref T? field, Func create, string name, string unit, string description) + where T : Instrument + { + try + { + field ??= create(name, unit, description); + } + catch + { + // Publication precedes insertion in Meter's counter cache. Recover the published + // instance so retrying after a listener exception cannot create a second instrument. + T? published = null; + using MeterListener inventory = new() + { + InstrumentPublished = (instrument, _) => + { + if (instrument is T candidate && ReferenceEquals(instrument.Meter, Meter) + && (instrument.Name, instrument.Unit, instrument.Description).Equals((name, unit, description))) + { + published = candidate; + } + }, + }; + inventory.Start(); + field = published; + throw; + } + } } /// @@ -46,15 +108,15 @@ internal abstract class HttpUserAgentParserMeterInstruments(Meter meter) /// Creates the (still empty) instruments of a meter; must not create instruments itself. /// Reserves a meter for the package before its instruments are created; throws if the meter must not be used. /// Forgets the reservations of the package (unit tests). +/// Enables recording after the complete set of instruments is published. internal sealed class HttpUserAgentParserMeterRegistration( - Func createInstruments, Action reserve, Action resetReservations) + Func createInstruments, Action reserve, Action resetReservations, Action markEnabled) where TInstruments : HttpUserAgentParserMeterInstruments { -#if NET9_0_OR_GREATER - private readonly Lock _lock = new(); -#else + // Monitor.Wait releases this lock while an independent registration finishes. private readonly object _lock = new(); -#endif + private readonly HashSet _publishingMeters = new(ReferenceEqualityComparer.Instance); + private readonly HashSet _publishingNames = new(StringComparer.Ordinal); // Keyed by the non-generic base type: the table's value type needs a trimming annotation a generic argument cannot provide. private readonly ConditionalWeakTable _instrumentsByMeter = new(); @@ -75,41 +137,66 @@ internal sealed class HttpUserAgentParserMeterRegistration( public void Use(Meter? meter, string ownedMeterName) { bool own = meter is null; + Meter target; lock (_lock) { - // Already in use: nothing to do. This also keeps the own meter from being disposed if a caller passes it in. - bool inUse = own - ? _ownedMeter is not null && string.Equals(_ownedMeter.Name, ownedMeterName, StringComparison.Ordinal) - : ReferenceEquals(meter, _ownedMeter); - if (inUse) + while (meter is null ? _publishingNames.Contains(ownedMeterName) : _publishingMeters.Contains(meter)) + { + if (HttpUserAgentParserMeterInstruments.Publication.InProgress) + { + return; // the in-flight registration will finish publishing these instruments + } + + Monitor.Wait(_lock); + } + + if (own ? string.Equals(_ownedMeter?.Name, ownedMeterName, StringComparison.Ordinal) : ReferenceEquals(meter, _current?.Meter)) { return; } - } - // A new own meter is visible to nobody until it is published below. - meter ??= new Meter(ownedMeterName); + target = meter ?? new Meter(ownedMeterName); + if (own) + { + _publishingNames.Add(ownedMeterName); + } + + _publishingMeters.Add(target); + } - TInstruments instruments; + using HttpUserAgentParserMeterInstruments.Publication publication = new(); + Meter? replacedOwnedMeter; try { - reserve(meter); - instruments = (TInstruments)_instrumentsByMeter.GetValue(meter, _createInstruments); + reserve(target); + TInstruments instruments = (TInstruments)_instrumentsByMeter.GetValue(target, _createInstruments); instruments.CreateMissingInstruments(); + + lock (_lock) + { + Volatile.Write(ref _current, instruments); + replacedOwnedMeter = _ownedMeter; + _ownedMeter = own ? target : null; + markEnabled(); + } } catch when (own) { - meter.Dispose(); + target.Dispose(); throw; } - - Meter? replacedOwnedMeter; - lock (_lock) + finally { - // Published only after all instruments exist. - Volatile.Write(ref _current, instruments); - replacedOwnedMeter = _ownedMeter; - _ownedMeter = own ? meter : null; + lock (_lock) + { + _publishingMeters.Remove(target); + if (own) + { + _publishingNames.Remove(ownedMeterName); + } + + Monitor.PulseAll(_lock); + } } // Disposing notifies listeners, so it runs outside of the lock. diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index 355113b..e4c955a 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -40,7 +40,8 @@ public static string GetMeterName(string? meterPrefix) private static readonly HttpUserAgentParserMeterRegistration s_registration = new( static meter => new Instruments(meter), HttpUserAgentParserCacheMeterGuard.ReserveForCore, // the core and the MemoryCache package must not share a meter - HttpUserAgentParserCacheMeterGuard.ResetCoreForTests); + HttpUserAgentParserCacheMeterGuard.ResetCoreForTests, + HttpUserAgentParserTelemetry.MarkMetersEnabled); /// /// Gets whether meters have been initialized. @@ -112,10 +113,10 @@ private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstrume public override void CreateMissingInstruments() { - _parseRequests ??= Meter.CreateCounter(name: "parse.requests", unit: "{call}", description: "User-Agent parse requests"); - _parseDuration ??= Meter.CreateHistogram(name: "parse.duration", unit: "s", description: "Parse duration"); - _cacheHit ??= Meter.CreateCounter(name: "cache.hit", unit: "{call}", description: "Cache hit"); - _cacheMiss ??= Meter.CreateCounter(name: "cache.miss", unit: "{call}", description: "Cache miss"); + CreateInstrument(ref _parseRequests, Meter.CreateCounter, "parse.requests", "{call}", "User-Agent parse requests"); + CreateInstrument(ref _parseDuration, Meter.CreateHistogram, "parse.duration", "s", "Parse duration"); + CreateInstrument(ref _cacheHit, Meter.CreateCounter, "cache.hit", "{call}", "Cache hit"); + CreateInstrument(ref _cacheMiss, Meter.CreateCounter, "cache.miss", "{call}", "Cache miss"); // Observable instruments are not shared by the meter: created at most once, also if a listener threw. if (Interlocked.Exchange(ref _cacheSizeCreated, 1) == 0) diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs index bcd6069..0d4a632 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs @@ -56,19 +56,15 @@ public static void Enable() /// Enables native System.Diagnostics.Metrics telemetry for the parser. /// public static void EnableMeters(Meter? meter = null) - { - HttpUserAgentParserMeters.Enable(meter); - Interlocked.Or(ref s_enabledFlags, MetersFlag); - } + => HttpUserAgentParserMeters.Enable(meter); /// /// Enables native System.Diagnostics.Metrics telemetry with a meter named that the package owns. /// public static void EnableMetersWithName(string meterName) - { - HttpUserAgentParserMeters.EnableOwnedMeter(meterName); - Interlocked.Or(ref s_enabledFlags, MetersFlag); - } + => HttpUserAgentParserMeters.EnableOwnedMeter(meterName); + + internal static void MarkMetersEnabled() => Interlocked.Or(ref s_enabledFlags, MetersFlag); /// /// Records a parse request event. diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs index f38dfa3..e384d09 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs @@ -21,6 +21,68 @@ public sealed class HttpUserAgentParserMemoryCacheTelemetryPathTests : IDisposab public void Dispose() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); + [Fact] + public void Cached_Result_Expires_When_Robot_Rules_Change() + { + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + HttpUserAgentParserMemoryCachedProvider.RobotRulesChangeToken change = new(HttpUserAgentStatics.Robots); + Assert.False(change.ActiveChangeCallbacks); + Assert.False(change.HasChanged); + using IDisposable registration = change.RegisterChangeCallback(static _ => Assert.Fail("A passive token must not invoke callbacks."), null); + try + { + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + HttpUserAgentStatics.SetRobots([("Chrome", "Custom")]); + Assert.True(change.HasChanged); + Assert.Equal("Custom", provider.Parse(UserAgent).Name); + HttpUserAgentStatics.SetRobots([]); + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + } + finally + { + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); + } + } + + [Fact] + public void Rule_Change_During_A_Miss_Cannot_Leave_A_Stale_Cache_Hit() + { + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + using Meter meter = new("robots.memorycache"); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter == meter && string.Equals(instrument.Name, "cache.miss", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + int misses = 0; + listener.SetMeasurementEventCallback((_, _, _, _) => + { + if (++misses == 1) + { + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + HttpUserAgentStatics.SetRobots([("Chrome", "New robot")]); + Assert.Equal("New robot", provider.Parse(UserAgent).Name); + } + }); + listener.Start(); + try + { + HttpUserAgentParserMemoryCacheTelemetry.EnableMeters(meter); + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + Assert.Equal("New robot", provider.Parse(UserAgent).Name); + Assert.Equal(2, misses); + } + finally + { + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); + } + } + [Fact] public void Disabled_Telemetry_Parses_And_Caches() { diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs index 61576a1..7e2555c 100644 --- a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs @@ -92,6 +92,14 @@ void Check(bool condition, string description) provider.GetRequiredService().HttpContext = context; Check(provider.GetRequiredService().Get() is { Name: "Safari" }, "ASP.NET Core accessor (IHttpContextAccessor)"); + + HttpUserAgentParserCachedProvider cached = new(); + _ = cached.Parse(Chrome); + HttpUserAgentStatics.SetRobots([("Chrome/", "Custom robot")]); + Check(cached.Parse(Chrome) is { Type: HttpUserAgentType.Robot, Name: "Custom robot" }, "updated robot rules in dictionary cache"); + Check(parser.Parse(Chrome) is { Type: HttpUserAgentType.Robot, Name: "Custom robot" }, "updated robot rules in memory cache"); + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); + Check(parser.Parse(Chrome) is { Type: HttpUserAgentType.Browser }, "restored robot rules"); } foreach (string instrument in (string[])["parse.requests", "parse.duration", "cache.miss", "cache.hit", "user_agent.present"]) diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 4fa78b4..7bcbda1 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -314,6 +314,10 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() // A version token inside another word belongs to another product [InlineData("Opera/9.80 VendorVersion/120.0", "Opera", "9.80")] // A version token only counts after the browser token + [InlineData("OperaHelper/1 Version/17.0 Safari/604.1", "Safari", "17.0")] + [InlineData("TridentSpider/3.1 rv:99 Trident/7.0 rv:11", "Internet Explorer", "11")] + [InlineData("Opera 9.50 Version/", "Opera", "9.50")] + [InlineData("Trident/7.0 rv:", "Internet Explorer", "7.0")] [InlineData("Version/99.0 Opera/9.80 Version/12.16", "Opera", "12.16")] [InlineData("rv:99.0; Trident/7.0; rv:11.0", "Internet Explorer", "11.0")] [InlineData("Mozilla/5.0 Version/ XVersion/1.0 Version/17.0 Safari/604.1", "Safari", "17.0")] @@ -352,6 +356,7 @@ public void GetBrowser_Reads_The_Version_Of_Its_Own_Product_Token(string userAge [InlineData("Mozilla/5.0 Chrome/ Chrome")] [InlineData("Checklinks/1.3 (pywikipedia robot; http://toolserver.org/~dispenser/view/Checklinks)")] [InlineData("Mozilla/5.0 (compatible; TridentSpider/3.1)")] + [InlineData("TridentSpider/3.1 (rv:12.0)")] [InlineData("Mozilla/5.0 Opera")] [InlineData("Mozilla/4.0 (compatible; MSIE ")] public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userAgent) @@ -390,6 +395,9 @@ public void GetBrowser_ExtractsAsciiVersion(string userAgent, string expectedVer [Theory] [InlineData("Microsoft Office/16.0 (Macintosh; Mac OS X 10.15.7; Microsoft Outlook 16.80.23121017; Pro)", "Mac OS X")] [InlineData("Microsoft-CryptoAPI/10.0", null)] + [InlineData("Mozilla/5.0+(Windows+Phone+10.0;+Android+6.0)", "Windows Phone")] + [InlineData("Mozilla/5.0+(Windows+NT+10.0)", "Windows 10")] + [InlineData("Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X)", "Mac OS X")] [InlineData("Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "ChromeOS")] [InlineData("Mozilla/5.0+(X11;+CrOS+x86_64+14541.0.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/120.0.0.0+Safari/537.36", "ChromeOS")] [InlineData("Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15063", "Windows Phone")] @@ -398,6 +406,38 @@ public void GetPlatform_Detects_ChromeOS_And_Windows_Phone_Only_By_Their_Own_Tok Assert.Equal(expectedPlatform, HttpUserAgentParser.GetPlatform(userAgent)?.Name); } + [Fact] + public void Iis_Spaces_Inside_Product_Names_Are_Decoded_Only_For_Detection() + { + const string ua = "Mozilla/5.0+(Nintendo+DSi;+Windows+NT+10.0)+Brave+Chrome/99"; + HttpUserAgentInformation parsed = HttpUserAgentParser.Parse(ua); + Assert.Equal(ua, parsed.UserAgent); + Assert.Equal("Brave", parsed.Name); + Assert.Equal(("Brave", "99"), HttpUserAgentParser.GetBrowser(ua)); + Assert.Equal("Nintendo DSi", parsed.MobileDeviceType); + Assert.Equal("Nintendo DSi", HttpUserAgentParser.GetMobileDevice(ua)); + Assert.Equal("Windows 10", parsed.Platform?.Name); + } + + [Fact] + public void GetPlatform_Decodes_Long_Iis_Headers() + { + Assert.Equal("Windows Phone", HttpUserAgentParser.GetPlatform(new string('x', 512) + "+Windows+Phone")?.Name); + } + + [Theory] + [InlineData("X11; HP-UX B.11.31", "HP-UX", HttpUserAgentPlatformType.Unix)] + [InlineData("X11; FreeBSD ppc", "FreeBSD", HttpUserAgentPlatformType.Unix)] + [InlineData("X11; Unix; HP-UX", "HP-UX", HttpUserAgentPlatformType.Unix)] + [InlineData("X11; Unix; NetBSD ppc", "NetBSD", HttpUserAgentPlatformType.Unix)] + [InlineData("Macintosh; U; PPC", "Macintosh", HttpUserAgentPlatformType.MacOS)] + public void Parse_Reports_The_Platform_Family(string comment, string expectedName, HttpUserAgentPlatformType expectedType) + { + HttpUserAgentPlatformInformation? platform = HttpUserAgentParser.Parse($"Mozilla/5.0 ({comment})").Platform; + Assert.Equal(expectedName, platform?.Name); + Assert.Equal(expectedType, platform?.PlatformType); + } + [Fact] public void GetRobot_Tells_YouBot_And_ShowyouBot_Apart() { diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs index a6bcdab..84235ab 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -1,5 +1,9 @@ // Copyright © https://myCSharp.de - all rights reserved +using System.Collections; +using System.Diagnostics.Metrics; +using MyCSharp.HttpUserAgentParser.Providers; +using MyCSharp.HttpUserAgentParser.Telemetry; using MyCSharp.HttpUserAgentParser.TestHelpers; using MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; using Xunit; @@ -25,6 +29,62 @@ public void Robots_Are_The_Defaults_And_Read_Only() Assert.Equal(HttpUserAgentRules.DefaultRobots, HttpUserAgentStatics.Robots); Assert.IsNotType<(string Key, string Value)[]>(HttpUserAgentStatics.Robots, exactMatch: false); Assert.Throws(() => ((IList<(string Key, string Value)>)HttpUserAgentStatics.Robots)[0] = ("x", "y")); + Assert.Same(HttpUserAgentStatics.Robots, ((ICollection)HttpUserAgentStatics.Robots).SyncRoot); + } + + [Fact] + public void Cached_Provider_Uses_The_Current_Robot_Rules() + { + HttpUserAgentParserCachedProvider provider = new(); + Assert.Equal(HttpUserAgentType.Browser, provider.Parse(Chrome).Type); + + HttpUserAgentStatics.SetRobots([("Chrome", "Custom")]); + Assert.False(provider.HasCacheEntry(Chrome)); + Assert.Equal(0, provider.CacheEntryCount); + Assert.Equal("Custom", provider.Parse(Chrome).Name); + + HttpUserAgentStatics.SetRobots([]); + Assert.Equal(HttpUserAgentType.Browser, provider.Parse(Chrome).Type); + Assert.Equal(1, provider.CacheEntryCount); + } + + [Fact] + public void Rule_Change_During_A_Cache_Miss_Keeps_The_Two_Generations_Separate() + { + HttpUserAgentParserCachedProvider provider = new(); + using Meter meter = new("robots.concurrent"); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter == meter && string.Equals(instrument.Name, "parse.requests", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + int requests = 0; + listener.SetMeasurementEventCallback((_, _, _, _) => + { + if (++requests == 1) + { + HttpUserAgentStatics.SetRobots([("Chrome", "New robot")]); + Assert.Equal("New robot", provider.Parse(Chrome).Name); + } + }); + listener.Start(); + + try + { + HttpUserAgentParserTelemetry.EnableMeters(meter); + Assert.Equal("Chrome", provider.Parse(Chrome).Name); + Assert.Equal("New robot", provider.Parse(Chrome).Name); + Assert.Equal(2, requests); + } + finally + { + HttpUserAgentParserTelemetry.ResetForTests(); + } } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index 0dd584f..9139552 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -44,19 +44,19 @@ private static readonly (string Token, string Name, HttpUserAgentPlatformType Ty ("cros", "ChromeOS", HttpUserAgentPlatformType.ChromeOS), ("os x", "Mac OS X", HttpUserAgentPlatformType.MacOS), ("ppc mac", "Power PC Mac", HttpUserAgentPlatformType.MacOS), - ("freebsd", "FreeBSD", HttpUserAgentPlatformType.Linux), - ("ppc", "Macintosh", HttpUserAgentPlatformType.Linux), + ("freebsd", "FreeBSD", HttpUserAgentPlatformType.Unix), + ("ppc", "Macintosh", HttpUserAgentPlatformType.MacOS), ("linux", "Linux", HttpUserAgentPlatformType.Linux), ("debian", "Debian", HttpUserAgentPlatformType.Linux), - ("sunos", "Sun Solaris", HttpUserAgentPlatformType.Generic), + ("sunos", "Sun Solaris", HttpUserAgentPlatformType.Unix), ("beos", "BeOS", HttpUserAgentPlatformType.Generic), ("apachebench", "ApacheBench", HttpUserAgentPlatformType.Generic), - ("aix", "AIX", HttpUserAgentPlatformType.Generic), - ("irix", "Irix", HttpUserAgentPlatformType.Generic), - ("osf", "DEC OSF", HttpUserAgentPlatformType.Generic), - ("hp-ux", "HP-UX", HttpUserAgentPlatformType.Windows), - ("netbsd", "NetBSD", HttpUserAgentPlatformType.Generic), - ("bsdi", "BSDi", HttpUserAgentPlatformType.Generic), + ("aix", "AIX", HttpUserAgentPlatformType.Unix), + ("irix", "Irix", HttpUserAgentPlatformType.Unix), + ("osf", "DEC OSF", HttpUserAgentPlatformType.Unix), + ("hp-ux", "HP-UX", HttpUserAgentPlatformType.Unix), + ("netbsd", "NetBSD", HttpUserAgentPlatformType.Unix), + ("bsdi", "BSDi", HttpUserAgentPlatformType.Unix), ("openbsd", "OpenBSD", HttpUserAgentPlatformType.Unix), ("gnu", "GNU/Linux", HttpUserAgentPlatformType.Linux), ("unix", "Unknown Unix OS", HttpUserAgentPlatformType.Unix), @@ -151,6 +151,7 @@ public void DefaultRobots_Are_The_Robots_Of_The_Library() { Assert.Equal(HttpUserAgentRules.DefaultRobots, HttpUserAgentStatics.DefaultRobots); Assert.Contains(("googlebot", "Googlebot"), HttpUserAgentStatics.DefaultRobots); + Assert.Distinct(HttpUserAgentStatics.DefaultRobots.Select(static robot => robot.Key), StringComparer.OrdinalIgnoreCase); } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index 700f8a4..65335f2 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -301,6 +301,52 @@ public void WithMeterTelemetry_Rejects_The_Meter_Of_The_MemoryCache_Package() HttpUserAgentParserCacheMeterGuard.ResetMemoryCacheForTests(); } + [Fact] + public void Retrying_After_A_Counter_Listener_Throws_Reuses_The_Published_Instance() + { + using Meter meter = new("retry.counter"); + _ = meter.CreateCounter("parse.requests", "other", "Other definition"); + using (MeterListener failing = new() + { + InstrumentPublished = (instrument, _) => + { + if (ReferenceEquals(instrument.Meter, meter) && string.Equals(instrument.Unit, "{call}", StringComparison.Ordinal)) + { + HttpUserAgentParserTelemetry.EnableMeters(meter); + throw new InvalidOperationException("listener failure"); + } + }, + }) + { + failing.Start(); + Assert.Throws(() => HttpUserAgentParserMeters.Enable(meter)); + Assert.False(HttpUserAgentParserTelemetry.IsEnabled); + } + + HttpUserAgentParserMeters.Enable(meter); + Assert.Equal((1, 6), CountLiveMeters(meter.Name)); // five parser instruments and the unrelated counter + } + + [Fact] + public void Reentrant_Registration_Publishes_Each_Instrument_Once() + { + const string name = "reentrant.core"; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, name, StringComparison.Ordinal)) + { + HttpUserAgentParserMeters.Enable(instrument.Meter); + HttpUserAgentParserMeters.EnableOwnedMeter(name); + } + }, + }; + listener.Start(); + HttpUserAgentParserMeters.EnableOwnedMeter(name); + Assert.Equal((1, 5), CountLiveMeters(name)); + } + [Fact] public void A_Nested_Registration_Of_Another_Own_Meter_Leaves_No_Meter_Behind() { diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs index e578add..6b9e0be 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -52,6 +52,35 @@ public void Meters_Without_Duration_Listener_Do_Not_Measure_Duration() AssertParsesAndCaches(); } + [Fact] + public void Cache_Miss_Listener_Can_Read_The_New_Entry() + { + using Meter meter = new("test.cache.miss"); + HttpUserAgentParserCachedProvider provider = new(); + using MeterListener listener = new() + { + InstrumentPublished = (instrument, target) => + { + if (instrument.Meter == meter && string.Equals(instrument.Name, "cache.miss", StringComparison.Ordinal)) + { + target.EnableMeasurementEvents(instrument); + } + }, + }; + int misses = 0; + listener.SetMeasurementEventCallback((_, _, _, _) => + { + if (++misses == 1) + { + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + } + }); + listener.Start(); + HttpUserAgentParserTelemetry.EnableMeters(meter); + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + Assert.Equal(1, misses); + } + [Fact] public void Cache_Size_Includes_Entries_Cached_Before_Telemetry_Was_Enabled() { @@ -156,6 +185,8 @@ public void Registering_The_Same_Meter_Again_Keeps_The_Instruments() public async Task Concurrent_Registration_Returns_After_All_Instruments_Exist() { CancellationToken cancellationToken = TestContext.Current.CancellationToken; + using Meter earlier = new("test.earlier"); + ExecutionContext? captured = null; using Meter meter = new("test.race"); using ManualResetEventSlim creating = new(); using ManualResetEventSlim release = new(); @@ -163,6 +194,11 @@ public async Task Concurrent_Registration_Returns_After_All_Instruments_Exist() { InstrumentPublished = (instrument, target) => { + if (instrument.Meter == earlier) + { + captured = ExecutionContext.Capture(); + } + if (instrument.Meter != meter) { return; @@ -180,9 +216,11 @@ public async Task Concurrent_Registration_Returns_After_All_Instruments_Exist() }; listener.Start(); + HttpUserAgentParserTelemetry.EnableMeters(earlier); + Assert.NotNull(captured); Task first = Task.Run(() => HttpUserAgentParserTelemetry.EnableMeters(meter), cancellationToken); Assert.True(creating.Wait(TimeSpan.FromSeconds(10), cancellationToken)); - Task second = Task.Run(() => HttpUserAgentParserTelemetry.EnableMeters(meter), cancellationToken); + Task second = Task.Run(() => ExecutionContext.Run(captured, _ => HttpUserAgentParserTelemetry.EnableMeters(meter), null), cancellationToken); // The second registration must not return while the instruments of the first one are incomplete. Assert.NotSame(second, await Task.WhenAny(second, Task.Delay(200, cancellationToken))); From 1126feda122dd5f6f9e2310c194cb8e660c1dec2 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 22:03:02 +0100 Subject: [PATCH 12/41] refactor(tests): remove unused telemetry test listeners feat(tests): add EventCounterTestListener and MeterTestListener refactor(tests): update HttpUserAgentParserMemoryCachedProvider tests fix(tests): improve assertions in HttpUserAgentInformationExtensionsTests chore(tests): clean up UserAgentCatalogTests and related tests --- .github/release-drafter.yml | 68 ++++++------ .github/workflows/build-and-test.yml | 20 ++-- .github/workflows/main-build.yml | 101 +++++++----------- .github/workflows/release-publish.yml | 24 ++--- Directory.Build.props | 11 +- Directory.Packages.props | 1 - Justfile | 14 +-- .../HttpUserAgentParserBenchmarks.cs | 18 ++++ .../HttpUserAgentParser.cs | 51 ++++----- .../HttpUserAgentPlatformInformation.cs | 8 +- src/HttpUserAgentParser/HttpUserAgentRules.cs | 35 +++--- .../HttpUserAgentStatics.cs | 46 +------- .../HttpContextExtensionsTests.cs | 2 +- ...serAgentParser.AspNetCore.UnitTests.csproj | 13 ++- ...entParserAspNetCoreMetersTelemetryTests.cs | 1 + ...ParserAspNetCoreTelemetryInternalsTests.cs | 1 + ...UserAgentParserAspNetCoreTelemetryTests.cs | 1 + .../Telemetry/MeterTestListener.cs | 39 ------- ...erAgentParser.MemoryCache.UnitTests.csproj | 7 +- ...rserMemoryCachedProviderAdditionalTests.cs | 49 +++------ ...tParserMemoryCachedProviderOptionsTests.cs | 4 +- .../Telemetry/EventCounterTestListener.cs | 61 ----------- ...ntParserMemoryCacheMetersTelemetryTests.cs | 1 + ...arserMemoryCacheTelemetryInternalsTests.cs | 1 + ...serAgentParserMemoryCacheTelemetryTests.cs | 3 +- .../Telemetry/MeterTestListener.cs | 41 ------- .../EventCounterTestListener.cs | 31 ++---- .../MeterTestListener.cs | 10 +- ...erAgentParserDependencyInjectionOptions.cs | 21 ---- ...tParserServiceCollectionExtensionsTests.cs | 6 +- ...HttpUserAgentInformationExtensionsTests.cs | 37 +------ .../HttpUserAgentParser.UnitTests.csproj | 6 -- .../HttpUserAgentParserTests.cs | 32 +++--- .../HttpUserAgentPlatformTypeTests.cs | 3 +- ...pUserAgentStaticsRobotsReplacementTests.cs | 12 +-- .../HttpUserAgentStaticsTests.cs | 29 ++++- .../HttpUserAgentTypeTests.cs | 2 +- .../Telemetry/EventCounterTestListener.cs | 48 --------- ...HttpUserAgentParserMetersTelemetryTests.cs | 1 + ...pUserAgentParserTelemetryInternalsTests.cs | 1 + .../HttpUserAgentParserTelemetryPathTests.cs | 1 + .../HttpUserAgentParserTelemetryTests.cs | 1 + .../UserAgentCatalogTests.cs | 23 ---- 43 files changed, 274 insertions(+), 611 deletions(-) delete mode 100644 tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/MeterTestListener.cs delete mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/EventCounterTestListener.cs delete mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/MeterTestListener.cs rename tests/{HttpUserAgentParser.AspNetCore.UnitTests/Telemetry => HttpUserAgentParser.TestHelpers}/EventCounterTestListener.cs (58%) rename tests/{HttpUserAgentParser.UnitTests/Telemetry => HttpUserAgentParser.TestHelpers}/MeterTestListener.cs (73%) delete mode 100644 tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs delete mode 100644 tests/HttpUserAgentParser.UnitTests/Telemetry/EventCounterTestListener.cs diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 6d2420b..5976723 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -7,34 +7,38 @@ tag-template: 'v$RESOLVED_VERSION' # Categories for organizing release notes categories: - title: '🚀 Features' - labels: - - 'feature' - - 'enhancement' + when: + labels: + - 'feature' + - 'enhancement' - title: '🐛 Bug Fixes' - labels: - - 'bug' - - 'fix' + when: + labels: + - 'bug' + - 'fix' - title: '🔧 Maintenance' - labels: - - 'maintenance' - - 'chore' - - 'refactor' - - 'dependencies' + when: + labels: + - 'maintenance' + - 'chore' + - 'refactor' + - 'dependencies' - title: '📚 Documentation' - labels: - - 'documentation' - - 'docs' + when: + labels: + - 'documentation' + - 'docs' - title: '⚡ Performance' - labels: - - 'performance' + when: + labels: + - 'performance' - title: '🔒 Security' - labels: - - 'security' - -# Exclude certain labels from release notes -exclude-labels: - - 'skip-changelog' - - 'wip' + when: + labels: + - 'security' + - type: pre-exclude + when: + labels: ['skip-changelog', 'wip'] # Change template (how each PR is listed) change-template: '- $TITLE @$AUTHOR (#$NUMBER)' @@ -72,39 +76,35 @@ template: | # Automatically label PRs based on modified files autolabeler: - - label: 'documentation' + - labels: ['documentation'] files: - '*.md' - 'docs/**/*' - - label: 'bug' + - labels: ['bug'] branch: - '/fix\/.+/' title: - '/fix/i' - - label: 'feature' + - labels: ['feature'] branch: - '/feature\/.+/' title: - '/feature/i' - - label: 'dependencies' + - labels: ['dependencies'] files: - '**/packages.lock.json' - '**/*.csproj' - 'Directory.Packages.props' - 'Directory.Build.props' - - label: 'github-actions' + - labels: ['github-actions'] files: - '.github/workflows/**/*' - - label: 'tests' + - labels: ['tests'] files: - 'tests/**/*' - '**/*Tests.cs' - '**/*Test.cs' - - label: 'performance' + - labels: ['performance'] files: - 'perf/**/*' - '**/*Benchmark*.cs' - -# Version resolver (uses version from workflow input) -version-resolver: - default: patch diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 850cda5..f10a581 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -27,6 +27,8 @@ jobs: build: name: Build and Test runs-on: ubuntu-latest + env: + CONFIGURATION: ${{ inputs.configuration }} outputs: version: ${{ steps.nbgv.outputs.SemVer2 }} @@ -52,29 +54,31 @@ jobs: with: setAllVars: true - - name: Version Info - run: | - echo "Calculated version: ${{ steps.nbgv.outputs.SemVer2 }}" - - name: Restore dependencies run: dotnet restore - name: Build - run: dotnet build --configuration ${{ inputs.configuration }} --no-restore /p:Version=${{ steps.nbgv.outputs.SemVer2 }} + env: + PACKAGE_VERSION: ${{ steps.nbgv.outputs.SemVer2 }} + run: dotnet build --configuration "$CONFIGURATION" --no-restore "-p:Version=$PACKAGE_VERSION" - name: Test - run: dotnet test --configuration ${{ inputs.configuration }} --no-build --verbosity normal --logger "trx;LogFilePrefix=test-results" + run: dotnet test --configuration "$CONFIGURATION" --no-build --verbosity normal --logger "trx;LogFilePrefix=test-results" - name: Upload test results if: always() && inputs.upload-test-results uses: actions/upload-artifact@v6 with: name: test-results - path: '**/TestResults/**/*.trx' + path: | + **/TestResults/**/*.trx + TestResults/coverage/**/*.cobertura.xml - name: Pack NuGet packages if: inputs.create-pack - run: dotnet pack --configuration ${{ inputs.configuration }} --no-build --output ./artifacts /p:PackageVersion=${{ steps.nbgv.outputs.SemVer2 }} + env: + PACKAGE_VERSION: ${{ steps.nbgv.outputs.SemVer2 }} + run: dotnet pack --configuration "$CONFIGURATION" --no-build --output ./artifacts "-p:PackageVersion=$PACKAGE_VERSION" - name: Upload NuGet packages if: inputs.create-pack diff --git a/.github/workflows/main-build.yml b/.github/workflows/main-build.yml index 4c810f0..9c52366 100644 --- a/.github/workflows/main-build.yml +++ b/.github/workflows/main-build.yml @@ -6,8 +6,7 @@ on: - main permissions: - contents: write - packages: write + contents: read jobs: build-and-test: @@ -20,12 +19,18 @@ jobs: name: Create Draft Release needs: build-and-test runs-on: ubuntu-latest + concurrency: draft-release-${{ needs.build-and-test.outputs.version }} + env: + TAG: v${{ needs.build-and-test.outputs.version }} permissions: contents: write + pull-requests: read steps: - name: Checkout code uses: actions/checkout@v6 + with: + fetch-depth: 0 - name: Download NuGet packages uses: actions/download-artifact@v4 @@ -33,72 +38,44 @@ jobs: name: nuget-packages path: ./artifacts - - name: Check if tag exists - id: check-tag + - name: Find release for the package version + id: release + shell: bash + env: + GH_TOKEN: ${{ github.token }} run: | - TAG="v${{ needs.build-and-test.outputs.version }}" - if git rev-parse "$TAG" >/dev/null 2>&1; then - echo "exists=true" >> $GITHUB_OUTPUT - echo "⚠️ Tag $TAG already exists" + draft=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" | jq -r --arg tag "$TAG" '.[] | select(.tag_name == $tag) | .draft') + if [[ "$draft" == true ]]; then + state=draft + elif [[ "$draft" == false ]] || git show-ref --verify --quiet "refs/tags/$TAG"; then + state=published else - echo "exists=false" >> $GITHUB_OUTPUT - echo "✅ Tag $TAG does not exist yet" + state=new fi + echo "state=$state" >> "$GITHUB_OUTPUT" - - name: Delete existing draft releases - if: steps.check-tag.outputs.exists == 'false' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - echo "Checking for existing draft releases..." - gh release list --json isDraft,tagName --jq '.[] | select(.isDraft) | .tagName' | while read -r tag_name; do - echo "Deleting existing draft release: $tag_name" - gh release delete "$tag_name" --yes --cleanup-tag || echo "Failed to delete release $tag_name" - done - - - name: Create Draft Release - if: steps.check-tag.outputs.exists == 'false' - uses: release-drafter/release-drafter@v6 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Generate release notes + id: notes + if: steps.release.outputs.state == 'new' + uses: release-drafter/release-drafter@v7 with: - config-name: release-drafter.yml - version: v${{ needs.build-and-test.outputs.version }} - tag: v${{ needs.build-and-test.outputs.version }} - name: Version ${{ needs.build-and-test.outputs.version }} - publish: false - prerelease: false + version: ${{ needs.build-and-test.outputs.version }} + tag: ${{ env.TAG }} + commitish: ${{ github.sha }} + dry-run: true - - name: Upload packages to draft release - if: steps.check-tag.outputs.exists == 'false' + - name: Create versioned draft with its packages + if: steps.release.outputs.state == 'new' env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} + RELEASE_NOTES: ${{ steps.notes.outputs.body }} run: | - TAG="v${{ needs.build-and-test.outputs.version }}" - # Wait a moment for the release to be created - sleep 2 + printf '%s\n' "$RELEASE_NOTES" > "$RUNNER_TEMP/release-notes.md" + gh release create "$TAG" ./artifacts/*.nupkg --draft --target "$GITHUB_SHA" \ + --title "Version ${TAG#v}" --notes-file "$RUNNER_TEMP/release-notes.md" - # Upload new artifacts to the draft release - echo "📦 Uploading new NuGet packages..." - for file in ./artifacts/*.nupkg; do - gh release upload "$TAG" "$file" --clobber - done - echo "✅ Uploaded NuGet packages to draft release" - - - name: Summary - if: steps.check-tag.outputs.exists == 'false' - run: | - echo "✅ Draft release created/updated" >> $GITHUB_STEP_SUMMARY - echo "Version: v${{ needs.build-and-test.outputs.version }}" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Next steps:" >> $GITHUB_STEP_SUMMARY - echo "1. Go to [Releases](../../releases)" >> $GITHUB_STEP_SUMMARY - echo "2. Review the draft release" >> $GITHUB_STEP_SUMMARY - echo "3. Edit release notes if needed" >> $GITHUB_STEP_SUMMARY - echo "4. Publish release to trigger production deployment" >> $GITHUB_STEP_SUMMARY - - - name: Release already exists - if: steps.check-tag.outputs.exists == 'true' - run: | - echo "ℹ️ Release v${{ needs.build-and-test.outputs.version }} already exists" >> $GITHUB_STEP_SUMMARY - echo "No action taken" >> $GITHUB_STEP_SUMMARY + - name: Refresh packages on a rerun of the same draft + if: steps.release.outputs.state == 'draft' + env: + GH_TOKEN: ${{ github.token }} + run: gh release upload "$TAG" ./artifacts/*.nupkg --clobber diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 4c7db78..60f94cc 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -6,7 +6,6 @@ on: permissions: contents: read - packages: write jobs: publish-nuget: @@ -17,11 +16,12 @@ jobs: - name: Download release assets env: GH_TOKEN: ${{ github.token }} + TAG: ${{ github.event.release.tag_name }} run: | - gh release download "${{ github.event.release.tag_name }}" \ + gh release download "$TAG" \ --pattern "*.nupkg" \ --dir ./artifacts \ - --repo "${{ github.repository }}" + --repo "$GITHUB_REPOSITORY" - name: Setup .NET uses: actions/setup-dotnet@v5 @@ -29,18 +29,14 @@ jobs: dotnet-version: '11.0.x' - name: Verify packages + env: + TAG: ${{ github.event.release.tag_name }} run: | - echo "Packages to be published:" - ls -la ./artifacts/*.nupkg - - # Verify package count - PACKAGE_COUNT=$(ls ./artifacts/*.nupkg | wc -l) - if [ "$PACKAGE_COUNT" -eq 0 ]; then - echo "Error: No packages found!" - exit 1 - fi - - echo "Found $PACKAGE_COUNT package(s) to publish" + packages=(./artifacts/*.nupkg) + [[ ${#packages[@]} -eq 3 ]] + for id in MyCSharp.HttpUserAgentParser{,.AspNetCore,.MemoryCache}; do + test -f "./artifacts/$id.${TAG#v}.nupkg" + done - name: Publish to NuGet.org env: diff --git a/Directory.Build.props b/Directory.Build.props index ba04fed..f853268 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -91,8 +91,7 @@ true lcov,opencover,cobertura $(MSBuildThisFileDirectory)TestResults/coverage/$(TargetFramework)/$(MSBuildProjectName). - GeneratedCodeAttribute,CompilerGeneratedAttribute,ExcludeFromCodeCoverageAttribute - **/*Program.cs;**/*Startup.cs;**/*GlobalUsings.cs + GeneratedCodeAttribute true 100 @@ -101,14 +100,8 @@ - + - - - - all - runtime; build; native; contentfiles; analyzers - diff --git a/Directory.Packages.props b/Directory.Packages.props index 44be207..8a95110 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -34,7 +34,6 @@ - all diff --git a/Justfile b/Justfile index d19cce4..6b4e250 100644 --- a/Justfile +++ b/Justfile @@ -32,8 +32,8 @@ rebuild *ARGS: clean: dotnet clean --configuration "{{CONFIG}}" --nologo -run *ARGS: - dotnet run --project --framework "{{TFM}}" --configuration "{{CONFIG}}" --no-launch-profile {{ARGS}} +run PROJECT *ARGS: + dotnet run --project "{{PROJECT}}" --framework "{{TFM}}" --configuration "{{CONFIG}}" --no-launch-profile {{ARGS}} # ===== Quality / Tests ===== format: @@ -46,7 +46,7 @@ test *ARGS: dotnet test --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal {{ARGS}} test-cov: - dotnet test --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura,lcov,opencover" /p:CoverletOutput="./TestResults/coverage/coverage" + dotnet test --configuration "{{CONFIG}}" --nologo --verbosity minimal -p:CollectCoverage=true test-filter QUERY: @@ -56,11 +56,11 @@ test-filter QUERY: pack *ARGS: dotnet pack --configuration "{{CONFIG}}" --nologo --verbosity minimal -o "./artifacts/packages" {{ARGS}} -publish *ARGS: - dotnet publish --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}" {{ARGS}} +publish PROJECT *ARGS: + dotnet publish "{{PROJECT}}" --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}" {{ARGS}} -publish-sc RID *ARGS: - dotnet publish --configuration "{{CONFIG}}" --framework "{{TFM}}" --runtime "{{RID}}" --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=false --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}-{{RID}}" {{ARGS}} +publish-sc RID PROJECT *ARGS: + dotnet publish "{{PROJECT}}" --configuration "{{CONFIG}}" --framework "{{TFM}}" --runtime "{{RID}}" --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=false --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}-{{RID}}" {{ARGS}} # ===== Benchmarks ===== bench *ARGS: diff --git a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs index 342ceb5..b269699 100644 --- a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs +++ b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs @@ -39,3 +39,21 @@ public static IEnumerable GetTestUserAgents() public string ParseBaseline() => Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(Data.UserAgent).Name; #endif } + +[MemoryDiagnoser] +public class RepeatedBrowserTokenBenchmarks +{ + [Params("Chrome/a", "Chrome/a ", "Version/a", "Version/a ", "MSIE ", "Opera+a ")] + public string Token { get; set; } + + [Params(1_000, 10_000, 100_000)] + public int Repetitions { get; set; } + + private string _userAgent; + + [GlobalSetup] + public void Setup() => _userAgent = string.Concat(Enumerable.Repeat(Token, Repetitions)); + + [Benchmark] + public (string Name, string Version)? GetBrowser() => Parser.GetBrowser(_userAgent); +} diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index d6c6854..6412690 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -131,10 +131,29 @@ private static T DetectProducts(string userAgent, ProductDetector detect) // (Measured with a mixed real-world workload, this beats vectorized token groups here.) foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { - if (ContainsIgnoreCase(ua, token)) + int index = ua.IndexOf(token, StringComparison.OrdinalIgnoreCase); + if (index < 0) + { + continue; + } + + // Short names can occur inside other words ("Microsoft", "Magnum", "CrOS x86"). + if (platform.RegexId is not (HttpUserAgentPlatformRegexId.CrOS or HttpUserAgentPlatformRegexId.Gnu or HttpUserAgentPlatformRegexId.OsX)) { return platform; } + + do + { + int end = index + token.Length; + if (IsTokenStart(ua, index) && IsProductNameEnd(ua, end)) + { + return platform; + } + + index = IndexOfTokenStart(ua, token, end); + } + while (index >= 0); } return null; @@ -164,22 +183,12 @@ private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua { foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) { - // Fast path: most rules do not match at all, and a match usually starts a token. - int detectIndex = ua.IndexOf(detectToken, StringComparison.OrdinalIgnoreCase); + int detectIndex = IndexOfTokenStart(ua, detectToken, 0); if (detectIndex < 0) { continue; } - if (!IsTokenStart(ua, detectIndex)) - { - detectIndex = IndexOfTokenStart(ua, detectToken, detectIndex + 1); - if (detectIndex < 0) - { - continue; - } - } - if (TryReadBrowserVersion(ua, detectToken, detectIndex, versionToken, out Range version)) { return (name, ua[version].ToString()); @@ -211,7 +220,7 @@ private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectTo while (detectIndex >= 0) { int end = detectIndex + detectToken.Length; - if (end == ua.Length || ua[end] == '/' || s_productTokenDelimiters.Contains(ua[end])) + if (IsProductNameEnd(ua, end)) { int versionIndex = IndexOfTokenStart(ua, versionToken, end); if (versionIndex >= 0 && TryReadVersion(ua, versionToken, versionIndex, allowSpace: true, out version)) @@ -294,6 +303,9 @@ private static bool TryReadVersion(ReadOnlySpan ua, string token, int inde private static bool IsTokenStart(ReadOnlySpan ua, int index) => index == 0 || s_productTokenDelimiters.Contains(ua[index - 1]); + private static bool IsProductNameEnd(ReadOnlySpan ua, int end) + => end == ua.Length || ua[end] == '/' || s_productTokenDelimiters.Contains(ua[end]); + /// /// Returns whether separates a product name from its version in Token 1.2 /// (+ stands for a space in URL-encoded logs). @@ -342,7 +354,7 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri private static string? GetRobot(string userAgent, HttpUserAgentRobotSet robots) { // The first robot (Googlebot in the default list, by far the most common robot) is checked on its own. - if (robots.FirstKey is { } firstKey && ContainsIgnoreCase(userAgent, firstKey)) + if (robots.FirstKey is { } firstKey && userAgent.AsSpan().Contains(firstKey, StringComparison.OrdinalIgnoreCase)) { return robots.FirstValue; } @@ -395,17 +407,6 @@ public static bool TryGetMobileDevice(string userAgent, [NotNullWhen(true)] out return device is not null; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool ContainsIgnoreCase(ReadOnlySpan haystack, ReadOnlySpan needle) - => TryIndexOf(haystack, needle, out _); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool TryIndexOf(ReadOnlySpan haystack, ReadOnlySpan needle, out int index) - { - index = haystack.IndexOf(needle, StringComparison.OrdinalIgnoreCase); - return index >= 0; - } - /// /// Finds the first ASCII digit and reads subsequent digits and dots within the current product token. /// diff --git a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs index f417208..022bcad 100644 --- a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs @@ -10,7 +10,7 @@ namespace MyCSharp.HttpUserAgentParser; public readonly struct HttpUserAgentPlatformInformation : IEquatable { private readonly Regex? _regex; - private readonly HttpUserAgentPlatformRegexId _regexId; + internal HttpUserAgentPlatformRegexId RegexId { get; } /// /// Creates a new instance of @@ -27,7 +27,7 @@ public HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentP /// internal HttpUserAgentPlatformInformation(HttpUserAgentPlatformRegexId regexId, string name, HttpUserAgentPlatformType platformType) { - _regexId = regexId; + RegexId = regexId; Name = name; PlatformType = platformType; } @@ -39,7 +39,7 @@ internal HttpUserAgentPlatformInformation(HttpUserAgentPlatformRegexId regexId, /// The built-in platforms use source-generated regular expressions that are created on first access. /// The parser does not use this regex; it is provided for consumers that want to match the platform themselves. /// - public Regex Regex => _regex ?? HttpUserAgentRegexes.GetPlatformRegex(_regexId)!; + public Regex Regex => _regex ?? HttpUserAgentRegexes.GetPlatformRegex(RegexId)!; /// /// Name of the platform @@ -57,7 +57,7 @@ internal HttpUserAgentPlatformInformation(HttpUserAgentPlatformRegexId regexId, public bool Equals(HttpUserAgentPlatformInformation other) => PlatformType == other.PlatformType && string.Equals(Name, other.Name, StringComparison.Ordinal) - && ReferenceEquals(Regex, other.Regex); + && (_regex is null && other._regex is null ? RegexId == other.RegexId : ReferenceEquals(Regex, other.Regex)); /// public override bool Equals(object? obj) => obj is HttpUserAgentPlatformInformation other && Equals(other); diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index edb9193..9a3e2c2 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -25,27 +25,28 @@ internal static class HttpUserAgentRules /// /// Platform rules, sorted by frequency (most common platforms first, specific versions before generic tokens). /// - internal static readonly (string Token, HttpUserAgentPlatformInformation Platform)[] Platforms = + internal static (string Token, HttpUserAgentPlatformInformation Platform)[] Platforms { get; } = [ + // Compatibility tokens on Windows Phone can identify both desktop Windows and Android. + ("windows phone", new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows)), // Most common: Windows (specific versions before generic) ("windows nt 10.0", new(HttpUserAgentPlatformRegexId.WindowsNt100, "Windows 10", HttpUserAgentPlatformType.Windows)), ("windows nt 6.1", new(HttpUserAgentPlatformRegexId.WindowsNt61, "Windows 7", HttpUserAgentPlatformType.Windows)), ("windows nt 6.3", new(HttpUserAgentPlatformRegexId.WindowsNt63, "Windows 8.1", HttpUserAgentPlatformType.Windows)), ("windows nt 6.2", new(HttpUserAgentPlatformRegexId.WindowsNt62, "Windows 8", HttpUserAgentPlatformType.Windows)), ("windows nt 6.0", new(HttpUserAgentPlatformRegexId.WindowsNt60, "Windows Vista", HttpUserAgentPlatformType.Windows)), - // Windows Phone 8.1 and 10 user agents contain "Android" (and "iPhone"), so this comes first - ("windows phone", new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows)), // Android (very common on mobile) ("android", new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android)), // iOS devices (very common) ("iphone", new(HttpUserAgentPlatformRegexId.IPhone, "iOS", HttpUserAgentPlatformType.IOS)), ("ipad", new(HttpUserAgentPlatformRegexId.IPad, "iOS", HttpUserAgentPlatformType.IOS)), ("ipod", new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS)), - // ChromeOS ("CrOS x86_64"), before "os x", which "CrOS x86_64" contains; with the space, "Microsoft" does not match - ("cros ", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), + ("cros", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), // Mac OS (common) ("os x", new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS)), - // Linux (common) + // A distribution can also identify itself as GNU/Linux. + ("debian", new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux)), + ("gnu", new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux)), ("linux", new(HttpUserAgentPlatformRegexId.Linux, "Linux", HttpUserAgentPlatformType.Linux)), // Other Windows versions ("windows nt 5.2", new(HttpUserAgentPlatformRegexId.WindowsNt52, "Windows 2003", HttpUserAgentPlatformType.Windows)), @@ -63,9 +64,7 @@ internal static readonly (string Token, HttpUserAgentPlatformInformation Platfor // Less common platforms ("blackberry", new(HttpUserAgentPlatformRegexId.BlackBerry, "BlackBerry", HttpUserAgentPlatformType.BlackBerry)), ("ppc mac", new(HttpUserAgentPlatformRegexId.PpcMac, "Power PC Mac", HttpUserAgentPlatformType.MacOS)), - ("debian", new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux)), ("freebsd", new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Unix)), - ("gnu", new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux)), ("openbsd", new(HttpUserAgentPlatformRegexId.OpenBsd, "OpenBSD", HttpUserAgentPlatformType.Unix)), ("symbian", new(HttpUserAgentPlatformRegexId.Symbian, "Symbian OS", HttpUserAgentPlatformType.Symbian)), ("sunos", new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Unix)), @@ -86,7 +85,7 @@ internal static readonly (string Token, HttpUserAgentPlatformInformation Platfor /// Sorted by specificity first, then frequency - more specific tokens must come before generic ones /// (e.g., Edge/Opera before Chrome, since Edge/Opera UAs contain "Chrome"). /// - internal static readonly (string Name, string DetectToken, string? VersionToken)[] Browsers = + internal static (string Name, string DetectToken, string? VersionToken)[] Browsers { get; } = [ // Most specific browsers first (contain Chrome/Mozilla in their UA) ("Opera", "OPR", null), @@ -103,10 +102,11 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) ("Yandex Browser", "YaBrowser", null), ("UC Browser", "UCBrowser", null), ("UC Browser", "UCMobile", null), + ("Maxthon", "Maxthon", null), // Common browsers ("Chrome", "Chrome", null), ("Chrome", "CriOS", null), - ("Safari", "Version/", "Version/"), + ("Netscape", "Netscape", null), ("Firefox", "Firefox", null), ("Firefox", "FxiOS", null), // Internet Explorer (legacy but still in use - MSIE before Trident to avoid false matches) @@ -114,8 +114,6 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) ("Internet Explorer", "Trident", "rv:"), ("Internet Explorer", "Internet Explorer", null), // Less common browsers - ("Maxthon", "Maxthon", null), - ("Netscape", "Netscape", null), ("Konqueror", "Konqueror", null), ("OmniWeb", "OmniWeb", null), ("Shiira", "Shiira", null), @@ -132,14 +130,15 @@ internal static readonly (string Name, string DetectToken, string? VersionToken) ("IBrowse", "IBrowse", null), ("Apple iPod", "ipod touch", null), ("Ubuntu Web Browser", "Ubuntu", null), - // Headless Chrome (automation): last, it costs other browsers nothing there + // The generic Version/ token only identifies Safari when no specific browser matched. ("Chrome", "HeadlessChrome", null), + ("Safari", "Version/", "Version/"), ]; /// /// The default robots in priority order (); never changed. /// - internal static readonly (string Key, string Value)[] DefaultRobots = + internal static (string Key, string Value)[] DefaultRobots { get; } = [ ( "googlebot", "Googlebot" ), ( "meta-externalagent", "meta-externalagent" ), @@ -245,7 +244,7 @@ internal static readonly (string Key, string Value)[] DefaultRobots = /// so a user agent without any anchor cannot match a default key. The few anchors need far fewer searches /// than all keys, which makes the common case (a browser) cheap. /// - internal static readonly string[] CuratedRobotAnchors = + internal static string[] CuratedRobotAnchors { get; } = [ "bot", "spider", "crawl", "google", "-user", "external", "slurp", "yahoo", "jeeves", "infoseek", "lycos", "yandex", "curious", "archiver", "turnitin", "jobboerse", @@ -256,7 +255,7 @@ internal static readonly (string Key, string Value)[] DefaultRobots = /// /// The default robots with their matchers. /// - internal static readonly HttpUserAgentRobotSet DefaultRobotSet = new(DefaultRobots); + internal static HttpUserAgentRobotSet DefaultRobotSet { get; } = new(DefaultRobots); private static HttpUserAgentRobotSet s_robotSet = DefaultRobotSet; @@ -304,7 +303,7 @@ internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAncho /// "SymbianOS" before "symbian"). /// The order is explicit on purpose: the enumeration order of a (frozen) dictionary is unspecified and must not decide the priority. /// - internal static readonly (string Key, string Value)[] Mobiles = + internal static (string Key, string Value)[] Mobiles { get; } = [ // Legacy ("mobileexplorer", "Mobile Explorer"), @@ -392,7 +391,7 @@ internal static readonly (string Key, string Value)[] Mobiles = /// /// Mobile token matcher. /// - internal static readonly PriorityTokenMatcher MobileMatcher = new(Array.ConvertAll(Mobiles, static rule => rule.Key)); + internal static PriorityTokenMatcher MobileMatcher { get; } = new(Array.ConvertAll(Mobiles, static rule => rule.Key)); /// /// Creates the public, case-insensitive lookup of . diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index 5bb6bf1..2ee7772 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -22,51 +22,7 @@ public static class HttpUserAgentStatics /// The of each entry is created on first access. /// public static readonly HashSet Platforms = - [ - new(HttpUserAgentPlatformRegexId.WindowsNt100, "Windows 10", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt63, "Windows 8.1", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt62, "Windows 8", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt61, "Windows 7", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt60, "Windows Vista", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt52, "Windows 2003", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt51, "Windows XP", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt50, "Windows 2000", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsNt40, "Windows NT 4.0", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WinNt40, "Windows NT 4.0", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WinNtSpace40, "Windows NT", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WinNt, "Windows NT", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.Windows98, "Windows 98", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.Win98, "Windows 98", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.Windows95, "Windows 95", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.Win95, "Windows 95", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.Windows, "Unknown Windows OS", HttpUserAgentPlatformType.Windows), - new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android), - new(HttpUserAgentPlatformRegexId.BlackBerry, "BlackBerry", HttpUserAgentPlatformType.BlackBerry), - new(HttpUserAgentPlatformRegexId.IPhone, "iOS", HttpUserAgentPlatformType.IOS), - new(HttpUserAgentPlatformRegexId.IPad, "iOS", HttpUserAgentPlatformType.IOS), - new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS), - new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS), - new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS), - new(HttpUserAgentPlatformRegexId.PpcMac, "Power PC Mac", HttpUserAgentPlatformType.MacOS), - new(HttpUserAgentPlatformRegexId.FreeBsd, "FreeBSD", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.MacOS), - new(HttpUserAgentPlatformRegexId.Linux, "Linux", HttpUserAgentPlatformType.Linux), - new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux), - new(HttpUserAgentPlatformRegexId.SunOs, "Sun Solaris", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.BeOs, "BeOS", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.ApacheBench, "ApacheBench", HttpUserAgentPlatformType.Generic), - new(HttpUserAgentPlatformRegexId.Aix, "AIX", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.Irix, "Irix", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.Osf, "DEC OSF", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.HpUx, "HP-UX", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.NetBsd, "NetBSD", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.OpenBsd, "OpenBSD", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.Gnu, "GNU/Linux", HttpUserAgentPlatformType.Linux), - new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix), - new(HttpUserAgentPlatformRegexId.Symbian, "Symbian OS", HttpUserAgentPlatformType.Symbian), - ]; + [.. HttpUserAgentRules.Platforms.Select(static rule => rule.Platform).OrderBy(static platform => platform.RegexId)]; /// /// Browsers diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs index 065cfb7..8a2b5c4 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs @@ -27,7 +27,7 @@ public void GetUserAgentString_Returns_Null_When_Absent() [Fact] public void Accessor_Get_Returns_Null_When_Header_Missing() { - var provider = Substitute.For(); + IHttpUserAgentParserProvider provider = Substitute.For(); HttpUserAgentParserAccessor accessor = new(provider); DefaultHttpContext ctx = new(); diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParser.AspNetCore.UnitTests.csproj b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParser.AspNetCore.UnitTests.csproj index f24713d..83f311a 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParser.AspNetCore.UnitTests.csproj +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParser.AspNetCore.UnitTests.csproj @@ -5,19 +5,18 @@ + + + all + runtime; build; native; contentfiles; analyzers + - + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs index 43c49c5..9d30907 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs @@ -6,6 +6,7 @@ using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; using MyCSharp.HttpUserAgentParser.DependencyInjection; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs index d2f3a38..c0889fc 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryInternalsTests.cs @@ -2,6 +2,7 @@ using System.Diagnostics.Metrics; using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs index 646840c..27b6b5c 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreTelemetryTests.cs @@ -5,6 +5,7 @@ using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; using MyCSharp.HttpUserAgentParser.DependencyInjection; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/MeterTestListener.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/MeterTestListener.cs deleted file mode 100644 index dd5a09b..0000000 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/MeterTestListener.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright © https://myCSharp.de - all rights reserved - -using System.Collections.Concurrent; -using System.Diagnostics.Metrics; - -namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; - -internal sealed class MeterTestListener : IDisposable -{ - private readonly string _meterName; - private readonly MeterListener _listener; - - public ConcurrentBag InstrumentNames { get; } = []; - - public MeterTestListener(string meterName) - { - _meterName = meterName; - _listener = new MeterListener(); - - _listener.InstrumentPublished = (instrument, listener) => - { - if (!string.Equals(instrument.Meter.Name, _meterName, StringComparison.Ordinal)) - { - return; - } - - listener.EnableMeasurementEvents(instrument); - }; - - _listener.SetMeasurementEventCallback((instrument, _, _, _) => - { - InstrumentNames.Add(instrument.Name); - }); - - _listener.Start(); - } - - public void Dispose() => _listener.Dispose(); -} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParser.MemoryCache.UnitTests.csproj b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParser.MemoryCache.UnitTests.csproj index 4c330fe..241906d 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParser.MemoryCache.UnitTests.csproj +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParser.MemoryCache.UnitTests.csproj @@ -10,14 +10,9 @@ + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs index 93bfdb4..5abd22a 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderAdditionalTests.cs @@ -13,49 +13,28 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; public class HttpUserAgentParserMemoryCachedProviderAdditionalTests { [Fact] - public void Options_Defaults_Are_Set() + public async Task Entries_Of_One_Thread_Are_Hits_On_Another_Thread() { - HttpUserAgentParserMemoryCachedProviderOptions options = new(); - Assert.NotNull(options.CacheOptions); - Assert.NotNull(options.CacheEntryOptions); - Assert.True(options.CacheOptions.SizeLimit is null || options.CacheOptions.SizeLimit >= 0); - Assert.NotEqual(default, options.CacheEntryOptions.SlidingExpiration); - } - - [Fact] - public void Provider_Caches_Entries_And_Resolves_Twice() - { - HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions(new MemoryCacheOptions { SizeLimit = 10 })); - string ua = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36"; - HttpUserAgentInformation a = provider.Parse(ua); - HttpUserAgentInformation b = provider.Parse(ua); - - Assert.Equal(a.Name, b.Name); - Assert.Equal(a.Version, b.Version); - } - - [Fact] - public void Entries_Of_One_Thread_Are_Hits_On_Another_Thread() - { - HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); - RunOnNewThread(() => + HttpUserAgentInformation first = await OnDedicatedThread(() => { - provider.Parse("Chrome/17"); - provider.Parse("Firefox/12"); // must not change the key of the cached Chrome entry + HttpUserAgentInformation chrome = provider.Parse("Chrome/17"); + _ = provider.Parse("Firefox/12"); + return chrome; }); - HttpUserAgentInformation chrome = default; - RunOnNewThread(() => chrome = provider.Parse("Chrome/17")); + HttpUserAgentInformation hit = await OnDedicatedThread(() => provider.Parse("Chrome/17")); Assert.Equal(2, provider.CacheEntryCount); - Assert.Equal(("Chrome", "17"), (chrome.Name, chrome.Version)); + Assert.Equal(("Chrome", "17"), (hit.Name, hit.Version)); + Assert.Same(first.Version, hit.Version); } [Fact] public void Keys_Are_Case_Sensitive() { - HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); // The result contains the original user agent, so a differently cased user agent is a different entry. Assert.Equal("Chrome/17", provider.Parse("Chrome/17").UserAgent); @@ -127,10 +106,6 @@ public void The_Container_Disposes_The_Provider() Assert.Throws(() => provider.Parse("Chrome/17")); } - private static void RunOnNewThread(Action action) - { - Thread thread = new(() => action()); - thread.Start(); - thread.Join(); - } + private static Task OnDedicatedThread(Func action) + => Task.Factory.StartNew(action, TestContext.Current.CancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs index 4bf1ac6..d00919f 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs @@ -46,7 +46,7 @@ public void Ctor_Empty() { HttpUserAgentParserMemoryCachedProviderOptions options = new(); - Assert.NotNull(options.CacheOptions); - Assert.NotNull(options.CacheEntryOptions); + Assert.Equal(256, options.CacheOptions.SizeLimit); + Assert.Equal(TimeSpan.FromDays(1), options.CacheEntryOptions.SlidingExpiration); } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/EventCounterTestListener.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/EventCounterTestListener.cs deleted file mode 100644 index 760c7c6..0000000 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/EventCounterTestListener.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright © https://myCSharp.de - all rights reserved - -using System.Diagnostics.Tracing; - -namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; - -internal sealed class EventCounterTestListener(string eventSourceName) : EventListener -{ - private readonly string _eventSourceName = eventSourceName; - private volatile bool _sawEventCounters; - private volatile bool _enabled; - - protected override void OnEventSourceCreated(EventSource eventSource) - { - if (!string.Equals(eventSource.Name, _eventSourceName, StringComparison.Ordinal)) - { - return; - } - - EnableEvents( - eventSource, - EventLevel.LogAlways, - EventKeywords.All, - new Dictionary(StringComparer.Ordinal) - { - ["EventCounterIntervalSec"] = "0.1" - }); - - _enabled = true; - } - - protected override void OnEventWritten(EventWrittenEventArgs eventData) - { - if (string.Equals(eventData.EventName, "EventCounters", StringComparison.Ordinal)) - { - _sawEventCounters = true; - } - } - - public bool WaitForCounters(TimeSpan timeout) - { - DateTimeOffset start = DateTimeOffset.UtcNow; - while (!_sawEventCounters && DateTimeOffset.UtcNow - start < timeout) - { - Thread.Sleep(10); - } - - return _sawEventCounters; - } - - public bool WaitUntilEnabled(TimeSpan timeout) - { - DateTimeOffset start = DateTimeOffset.UtcNow; - while (!_enabled && DateTimeOffset.UtcNow - start < timeout) - { - Thread.Sleep(10); - } - - return _enabled; - } -} diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index 2012830..30dcfd8 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -5,6 +5,7 @@ using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs index 5223f25..210419b 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryInternalsTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics.Metrics; using Microsoft.Extensions.Caching.Memory; using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs index 3b93e3f..2c34586 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryTests.cs @@ -1,10 +1,11 @@ // Copyright © https://myCSharp.de - all rights reserved -using Xunit; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; +using Xunit; namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/MeterTestListener.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/MeterTestListener.cs deleted file mode 100644 index 47a07d1..0000000 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/MeterTestListener.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © https://myCSharp.de - all rights reserved - -using System.Collections.Concurrent; -using System.Diagnostics.Metrics; - -namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.Telemetry; - -internal sealed class MeterTestListener : IDisposable -{ - private readonly string _meterName; - private readonly MeterListener _listener; - - public ConcurrentBag InstrumentNames { get; } = []; - - public MeterTestListener(string meterName) - { - _meterName = meterName; - _listener = new MeterListener(); - - _listener.InstrumentPublished = (instrument, listener) => - { - if (!string.Equals(instrument.Meter.Name, _meterName, StringComparison.Ordinal)) - { - return; - } - - listener.EnableMeasurementEvents(instrument); - }; - - _listener.SetMeasurementEventCallback((instrument, _, _, _) => - { - InstrumentNames.Add(instrument.Name); - }); - - _listener.Start(); - } - - public void RecordObservableInstruments() => _listener.RecordObservableInstruments(); - - public void Dispose() => _listener.Dispose(); -} diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/EventCounterTestListener.cs b/tests/HttpUserAgentParser.TestHelpers/EventCounterTestListener.cs similarity index 58% rename from tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/EventCounterTestListener.cs rename to tests/HttpUserAgentParser.TestHelpers/EventCounterTestListener.cs index b405d3b..6fe9fee 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/EventCounterTestListener.cs +++ b/tests/HttpUserAgentParser.TestHelpers/EventCounterTestListener.cs @@ -2,14 +2,16 @@ using System.Diagnostics.Tracing; -namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.Telemetry; +namespace MyCSharp.HttpUserAgentParser.TestHelpers; -internal sealed class EventCounterTestListener(string eventSourceName) : EventListener +/// Records telemetry from the selected event source during a test. +public sealed class EventCounterTestListener(string eventSourceName) : EventListener { private readonly string _eventSourceName = eventSourceName; private volatile bool _sawEventCounters; private volatile bool _enabled; + /// protected override void OnEventSourceCreated(EventSource eventSource) { if (!string.Equals(eventSource.Name, _eventSourceName, StringComparison.Ordinal)) @@ -29,6 +31,7 @@ protected override void OnEventSourceCreated(EventSource eventSource) _enabled = true; } + /// protected override void OnEventWritten(EventWrittenEventArgs eventData) { if (string.Equals(eventData.EventName, "EventCounters", StringComparison.Ordinal)) @@ -37,25 +40,9 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData) } } - public bool WaitForCounters(TimeSpan timeout) - { - DateTimeOffset start = DateTimeOffset.UtcNow; - while (!_sawEventCounters && DateTimeOffset.UtcNow - start < timeout) - { - Thread.Sleep(10); - } - - return _sawEventCounters; - } + /// Waits for the first counter event. + public bool WaitForCounters(TimeSpan timeout) => SpinWait.SpinUntil(() => _sawEventCounters, timeout); - public bool WaitUntilEnabled(TimeSpan timeout) - { - DateTimeOffset start = DateTimeOffset.UtcNow; - while (!_enabled && DateTimeOffset.UtcNow - start < timeout) - { - Thread.Sleep(10); - } - - return _enabled; - } + /// Waits for the listener to enable the event source. + public bool WaitUntilEnabled(TimeSpan timeout) => SpinWait.SpinUntil(() => _enabled, timeout); } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/MeterTestListener.cs b/tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs similarity index 73% rename from tests/HttpUserAgentParser.UnitTests/Telemetry/MeterTestListener.cs rename to tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs index 666e9b5..6b26d20 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/MeterTestListener.cs +++ b/tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs @@ -3,16 +3,20 @@ using System.Collections.Concurrent; using System.Diagnostics.Metrics; -namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; +namespace MyCSharp.HttpUserAgentParser.TestHelpers; -internal sealed class MeterTestListener : IDisposable +/// Records telemetry from the selected meter during a test. +public sealed class MeterTestListener : IDisposable { private readonly string _meterName; private readonly MeterListener _listener; + /// Names of the instruments that emitted a measurement. public ConcurrentBag InstrumentNames { get; } = []; + /// Units of the published instruments. public ConcurrentDictionary InstrumentUnits { get; } = new(StringComparer.Ordinal); + /// Starts listening to the named meter. public MeterTestListener(string meterName) { _meterName = meterName; @@ -42,7 +46,9 @@ public MeterTestListener(string meterName) _listener.Start(); } + /// Collects the current observable measurements. public void RecordObservableInstruments() => _listener.RecordObservableInstruments(); + /// public void Dispose() => _listener.Dispose(); } diff --git a/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs b/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs deleted file mode 100644 index 4bb1b34..0000000 --- a/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright © https://myCSharp.de - all rights reserved - -using Microsoft.Extensions.DependencyInjection; -using MyCSharp.HttpUserAgentParser.DependencyInjection; -using NSubstitute; -using Xunit; - -namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection; - -public class UserAgentParserDependencyInjectionOptionsTests -{ - private readonly IServiceCollection _scMock = Substitute.For(); - - [Fact] - public void Ctor_Should_Set_Property() - { - HttpUserAgentParserDependencyInjectionOptions options = new(_scMock); - - Assert.Equal(_scMock, options.Services); - } -} diff --git a/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index 0461545..c74c657 100644 --- a/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -7,7 +7,7 @@ namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection; -public class HttpUserAgentParserMemoryCacheServiceCollectionExtensions +public class HttpUserAgentParserServiceCollectionExtensionsTests { public class TestHttpUserAgentParserProvider : IHttpUserAgentParserProvider { @@ -19,7 +19,9 @@ public void AddHttpUserAgentParser() { ServiceCollection services = new(); - services.AddHttpUserAgentParser(); + HttpUserAgentParserDependencyInjectionOptions options = services.AddHttpUserAgentParser(); + + Assert.Same(services, options.Services); Assert.Single(services); Assert.Equal(typeof(IHttpUserAgentParserProvider), services[0].ServiceType); diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs index e3b3e8a..f7fb155 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs @@ -10,43 +10,16 @@ public class HttpUserAgentInformationExtensionsTests [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155", HttpUserAgentType.Browser, true)] [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62", HttpUserAgentType.Browser, false)] [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML,like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", HttpUserAgentType.Robot, false)] - [InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", HttpUserAgentType.Robot, false)] - [InlineData("WhatsApp/2.22.20.72 A", HttpUserAgentType.Robot, false)] - [InlineData("WhatsApp/2.22.19.78 I", HttpUserAgentType.Robot, false)] - [InlineData("WhatsApp/2.2236.3 N", HttpUserAgentType.Robot, false)] [InlineData("Invalid user agent", HttpUserAgentType.Unknown, false)] public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobile) { HttpUserAgentInformation info = HttpUserAgentInformation.Parse(userAgent); - if (expectedType == HttpUserAgentType.Browser) - { - Assert.True(info.IsType(HttpUserAgentType.Browser)); - Assert.False(info.IsType(HttpUserAgentType.Robot)); - Assert.False(info.IsType(HttpUserAgentType.Unknown)); - - Assert.True(info.IsBrowser()); - Assert.False(info.IsRobot()); - } - else if (expectedType == HttpUserAgentType.Robot) - { - Assert.False(info.IsType(HttpUserAgentType.Browser)); - Assert.True(info.IsType(HttpUserAgentType.Robot)); - Assert.False(info.IsType(HttpUserAgentType.Unknown)); - - Assert.False(info.IsBrowser()); - Assert.True(info.IsRobot()); - } - else if (expectedType == HttpUserAgentType.Unknown) - { - Assert.False(info.IsType(HttpUserAgentType.Browser)); - Assert.False(info.IsType(HttpUserAgentType.Robot)); - Assert.True(info.IsType(HttpUserAgentType.Unknown)); - - Assert.False(info.IsBrowser()); - Assert.False(info.IsRobot()); - } - + Assert.Equal(expectedType == HttpUserAgentType.Browser, info.IsType(HttpUserAgentType.Browser)); + Assert.Equal(expectedType == HttpUserAgentType.Robot, info.IsType(HttpUserAgentType.Robot)); + Assert.Equal(expectedType == HttpUserAgentType.Unknown, info.IsType(HttpUserAgentType.Unknown)); + Assert.Equal(expectedType == HttpUserAgentType.Browser, info.IsBrowser()); + Assert.Equal(expectedType == HttpUserAgentType.Robot, info.IsRobot()); Assert.Equal(isMobile, info.IsMobile()); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj index e03e095..eadbbb3 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParser.UnitTests.csproj @@ -13,11 +13,5 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 7bcbda1..41b4cf7 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -1,6 +1,5 @@ // Copyright © https://myCSharp.de - all rights reserved -using System.Diagnostics; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests; @@ -306,6 +305,10 @@ public void GetBrowser_LongToken_NoDigits_Within_Window_Does_Not_Parse_Version() [Theory] [InlineData("SamsungBrowser/ Chrome/131.0.0.0 Safari/537.36", "Chrome", "131.0.0.0")] + [InlineData("Chrome/109.0 Safari/537.36 Maxthon/7.0", "Maxthon", "7.0")] + [InlineData("Firefox/2.0 Netscape/9.0", "Netscape", "9.0")] + [InlineData("Version/4.0 Safari/531.3 OmniWeb/622", "OmniWeb", "622")] + [InlineData("Chrome/109.0 Maxthon/", "Chrome", "109.0")] [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)", "Internet Explorer", "8.0")] [InlineData("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0")] // A later occurrence of the same token carries the version @@ -364,25 +367,6 @@ public void GetBrowser_Does_Not_Take_The_Version_Of_Another_Product(string userA Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); } - [Theory] - [InlineData("Chrome/a")] // one product token without delimiter - [InlineData("Chrome/a ")] // many product tokens - [InlineData("Version/a")] - [InlineData("Version/a ")] - [InlineData("MSIE ")] - [InlineData("Opera+a ")] - public void GetBrowser_Time_Grows_Linearly_With_Repeated_Tokens(string repeated) - { - // A search that rescans the rest of the user agent for every occurrence needs seconds for 1,000,000 characters. - string userAgent = string.Concat(Enumerable.Repeat(repeated, 1_000_000 / repeated.Length)); - - long start = Stopwatch.GetTimestamp(); - Assert.Null(HttpUserAgentParser.GetBrowser(userAgent)); - TimeSpan elapsed = Stopwatch.GetElapsedTime(start); - - Assert.True(elapsed < TimeSpan.FromSeconds(1), $"GetBrowser took {elapsed.TotalMilliseconds:F0} ms"); - } - [Theory] [InlineData("Chrome/ı1.2é3", "1.2")] [InlineData("Chrome/1.2ı3 followed by a long suffix", "1.2")] @@ -395,6 +379,11 @@ public void GetBrowser_ExtractsAsciiVersion(string userAgent, string expectedVer [Theory] [InlineData("Microsoft Office/16.0 (Macintosh; Mac OS X 10.15.7; Microsoft Outlook 16.80.23121017; Pro)", "Mac OS X")] [InlineData("Microsoft-CryptoAPI/10.0", null)] + [InlineData("CrOS", "ChromeOS")] + [InlineData("Crosstalk/2 (X11; CrOS)", "ChromeOS")] + [InlineData("Microsoft Office (Macros x86)", null)] + [InlineData("X11; Magnum; Linux x86_64", "Linux")] + [InlineData("X11; CrOS\tarmv7l", "ChromeOS")] [InlineData("Mozilla/5.0+(Windows+Phone+10.0;+Android+6.0)", "Windows Phone")] [InlineData("Mozilla/5.0+(Windows+NT+10.0)", "Windows 10")] [InlineData("Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X)", "Mac OS X")] @@ -427,6 +416,9 @@ public void GetPlatform_Decodes_Long_Iis_Headers() [Theory] [InlineData("X11; HP-UX B.11.31", "HP-UX", HttpUserAgentPlatformType.Unix)] + [InlineData("Windows Phone 10.0; Windows NT 10.0; Android 6.0", "Windows Phone", HttpUserAgentPlatformType.Windows)] + [InlineData("X11; Debian GNU/Linux", "Debian", HttpUserAgentPlatformType.Linux)] + [InlineData("X11; GNU/Linux", "GNU/Linux", HttpUserAgentPlatformType.Linux)] [InlineData("X11; FreeBSD ppc", "FreeBSD", HttpUserAgentPlatformType.Unix)] [InlineData("X11; Unix; HP-UX", "HP-UX", HttpUserAgentPlatformType.Unix)] [InlineData("X11; Unix; NetBSD ppc", "NetBSD", HttpUserAgentPlatformType.Unix)] diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs index 08cb3cc..4811840 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs @@ -17,8 +17,9 @@ public class HttpUserAgentPlatformTypeTests [InlineData(HttpUserAgentPlatformType.BlackBerry, 7)] [InlineData(HttpUserAgentPlatformType.Android, 8)] [InlineData(HttpUserAgentPlatformType.Symbian, 9)] + [InlineData(HttpUserAgentPlatformType.ChromeOS, 10)] public void TestValue(HttpUserAgentPlatformType type, byte value) { - Assert.True((byte)type == value); + Assert.Equal(value, (byte)type); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs index 84235ab..ed4ab8a 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -138,16 +138,12 @@ public void SetRobots_Keeps_No_Reference_To_The_Input() [Fact] public void SetRobots_With_The_Defaults_Detects_Like_The_Defaults() { + string?[] expected = [.. UserAgentCatalog.All.Select(HttpUserAgentParser.GetRobot)]; + HttpUserAgentStatics.SetRobots([]); + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); - Assert.NotSame(HttpUserAgentRules.DefaultRobotSet, HttpUserAgentRules.RobotSet); - foreach (string userAgent in UserAgentCatalog.All) - { - HttpUserAgentRules.SetRobotSet(HttpUserAgentRules.DefaultRobotSet); - string? expected = HttpUserAgentParser.GetRobot(userAgent); - HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); - Assert.Equal(expected, HttpUserAgentParser.GetRobot(userAgent)); - } + Assert.Equal(expected, UserAgentCatalog.All.Select(HttpUserAgentParser.GetRobot), StringComparer.Ordinal); } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index 9139552..f279b94 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -143,6 +143,7 @@ public void Mobiles_Contain_All_Rules() { Assert.Equal(value, HttpUserAgentStatics.Mobiles[key]); Assert.Equal(value, HttpUserAgentStatics.Mobiles[key.ToUpperInvariant()]); + Assert.Equal(value, HttpUserAgentParser.GetMobileDevice(key.ToUpperInvariant())); } } @@ -152,6 +153,10 @@ public void DefaultRobots_Are_The_Robots_Of_The_Library() Assert.Equal(HttpUserAgentRules.DefaultRobots, HttpUserAgentStatics.DefaultRobots); Assert.Contains(("googlebot", "Googlebot"), HttpUserAgentStatics.DefaultRobots); Assert.Distinct(HttpUserAgentStatics.DefaultRobots.Select(static robot => robot.Key), StringComparer.OrdinalIgnoreCase); + foreach ((string key, string name) in HttpUserAgentStatics.DefaultRobots) + { + Assert.Equal(name, HttpUserAgentParser.GetRobot(key.ToUpperInvariant())); + } } [Fact] @@ -165,10 +170,28 @@ public void Parser_Platform_Rules_Resolve_The_Regex_Of_Their_Token() { foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { - // The public pattern is the token; the parser token "cros " ends with a space, so "Microsoft" is no ChromeOS. - Assert.Equal(Regex.Escape(token.TrimEnd(' ', '+')), platform.Regex.ToString()); - Assert.Matches(platform.Regex, token.TrimEnd(' ', '+')); + Assert.Equal(Regex.Escape(token), platform.Regex.ToString()); + Assert.Matches(platform.Regex, token); Assert.Contains(platform, HttpUserAgentStatics.Platforms); + Assert.Equal(platform, HttpUserAgentParser.GetPlatform(token)); + } + } + + [Fact] + public void Each_Browser_Rule_Can_Be_Reached_Through_Parse() + { + foreach ((string name, string product, string? versionToken) in HttpUserAgentRules.Browsers) + { + string ua = product.TrimEnd('/') + "/2.3"; + string expectedVersion = "2.3"; + if (versionToken is not null && !string.Equals(product, versionToken, StringComparison.Ordinal)) + { + ua += " " + versionToken + "4.5"; + expectedVersion = "4.5"; + } + + HttpUserAgentInformation result = HttpUserAgentParser.Parse(ua); + Assert.Equal((HttpUserAgentType.Browser, name, expectedVersion), (result.Type, result.Name, result.Version)); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs index b58b990..1f2f2df 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs @@ -12,6 +12,6 @@ public class HttpUserAgentTypeTests [InlineData(HttpUserAgentType.Robot, 2)] public void TestValue(HttpUserAgentType type, byte value) { - Assert.True((byte)type == value); + Assert.Equal(value, (byte)type); } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/EventCounterTestListener.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/EventCounterTestListener.cs deleted file mode 100644 index 91f0e9b..0000000 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/EventCounterTestListener.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © https://myCSharp.de - all rights reserved - -using System.Diagnostics.Tracing; - -namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; - -internal sealed class EventCounterTestListener(string eventSourceName) : EventListener -{ - private readonly string _eventSourceName = eventSourceName; - private volatile bool _sawEventCounters; - - protected override void OnEventSourceCreated(EventSource eventSource) - { - if (!string.Equals(eventSource.Name, _eventSourceName, StringComparison.Ordinal)) - { - return; - } - - EnableEvents( - eventSource, - EventLevel.LogAlways, - EventKeywords.All, - new Dictionary(StringComparer.Ordinal) - { - // Make the test responsive while keeping runtime short. - ["EventCounterIntervalSec"] = "0.1" - }); - } - - protected override void OnEventWritten(EventWrittenEventArgs eventData) - { - if (string.Equals(eventData.EventName, "EventCounters", StringComparison.Ordinal)) - { - _sawEventCounters = true; - } - } - - public bool WaitForCounters(TimeSpan timeout) - { - DateTimeOffset start = DateTimeOffset.UtcNow; - while (!_sawEventCounters && DateTimeOffset.UtcNow - start < timeout) - { - Thread.Sleep(10); - } - - return _sawEventCounters; - } -} diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index 65335f2..8133a48 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -5,6 +5,7 @@ using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; using MyCSharp.HttpUserAgentParser.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs index 85e179a..b9d0b4a 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryInternalsTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics.Metrics; using MyCSharp.HttpUserAgentParser.Providers; using MyCSharp.HttpUserAgentParser.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs index 6b9e0be..ba29372 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -5,6 +5,7 @@ using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; using MyCSharp.HttpUserAgentParser.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs index 209bc30..d7766ea 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryTests.cs @@ -4,6 +4,7 @@ using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; using MyCSharp.HttpUserAgentParser.Telemetry; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Xunit; namespace MyCSharp.HttpUserAgentParser.UnitTests.Telemetry; diff --git a/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs b/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs index 03759e5..62ebc65 100644 --- a/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs @@ -60,27 +60,4 @@ public void Unknown(string userAgent) Assert.Null(info.Name); Assert.Null(info.Version); } - - [Fact] - public void Catalog_Covers_All_Crawler_Categories() - { - Assert.Contains(UserAgentCatalog.Robots, ua => string.Equals(ua.Category, UserAgentCatalog.SearchCrawler, StringComparison.Ordinal)); - Assert.Contains(UserAgentCatalog.Robots, ua => string.Equals(ua.Category, UserAgentCatalog.SeoCrawler, StringComparison.Ordinal)); - Assert.Contains(UserAgentCatalog.Robots, ua => string.Equals(ua.Category, UserAgentCatalog.AiCrawler, StringComparison.Ordinal)); - } - - [Fact] - public void Catalog_Labels_Are_Unique() - { - Assert.Equal(UserAgentCatalog.Browsers.Count, UserAgentCatalog.Browsers.Select(ua => ua.Label).Distinct(StringComparer.Ordinal).Count()); - Assert.Equal(UserAgentCatalog.Robots.Count, UserAgentCatalog.Robots.Select(ua => ua.Label).Distinct(StringComparer.Ordinal).Count()); - Assert.Equal(UserAgentCatalog.Browsers.Count + UserAgentCatalog.Robots.Count + UserAgentCatalog.Unknown.Count, UserAgentCatalog.All.Count); - } - - [Fact] - public void Catalog_Entries_Display_Their_Label() - { - Assert.Equal("Chrome 158 Windows", UserAgentCatalog.Browsers[0].ToString()); - Assert.Equal("Googlebot Smartphone", UserAgentCatalog.Robots[0].ToString()); - } } From 5b604cc61ec3346da9153b5c8b31299f44b41380 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 22:20:33 +0100 Subject: [PATCH 13/41] test(user-agent-parser): add tests for robot key order and user agents --- .github/workflows/release-publish.yml | 25 ++- README.md | 10 +- .../HttpUserAgentParserBenchmarks.cs | 7 + ...HttpUserAgentParserMemoryCachedProvider.cs | 6 +- .../HttpUserAgentParser.cs | 91 ++++------ .../HttpUserAgentRegexes.cs | 1 + .../HttpUserAgentRobotSet.cs | 50 ++++-- src/HttpUserAgentParser/HttpUserAgentRules.cs | 6 + .../HttpUserAgentStatics.cs | 2 + .../PriorityTokenMatcher.cs | 19 +-- .../HttpUserAgentParserMeterRegistration.cs | 8 + ...entParserAspNetCoreMetersTelemetryTests.cs | 127 ++++---------- ...ntParserMemoryCacheMetersTelemetryTests.cs | 133 ++++----------- ...gentParserMemoryCacheTelemetryPathTests.cs | 44 ++++- .../MeterTestListener.cs | 20 +++ .../UserAgentsMeSnapshot.cs | 142 ++++++++++++++++ .../HttpUserAgentParserTests.cs | 15 +- ...pUserAgentStaticsRobotsReplacementTests.cs | 11 ++ .../HttpUserAgentStaticsTests.cs | 2 +- .../PriorityTokenMatcherTests.cs | 91 +++------- ...HttpUserAgentParserMetersTelemetryTests.cs | 158 +++++------------- .../UserAgentCatalogTests.cs | 16 ++ 22 files changed, 493 insertions(+), 491 deletions(-) create mode 100644 tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 60f94cc..73f9639 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -31,12 +31,27 @@ jobs: - name: Verify packages env: TAG: ${{ github.event.release.tag_name }} + shell: python run: | - packages=(./artifacts/*.nupkg) - [[ ${#packages[@]} -eq 3 ]] - for id in MyCSharp.HttpUserAgentParser{,.AspNetCore,.MemoryCache}; do - test -f "./artifacts/$id.${TAG#v}.nupkg" - done + import os + from pathlib import Path + from xml.etree import ElementTree + from zipfile import ZipFile + + version = os.environ["TAG"].removeprefix("v") + ids = ["MyCSharp.HttpUserAgentParser" + suffix for suffix in ("", ".AspNetCore", ".MemoryCache")] + packages = {Path("artifacts", f"{id_}.{version}.nupkg"): id_ for id_ in ids} + if set(Path("artifacts").glob("*.nupkg")) != packages.keys(): + raise SystemExit(f"Expected the three release packages for version {version}") + for path, package_id in packages.items(): + with ZipFile(path) as archive: + manifests = [name for name in archive.namelist() if "/" not in name and name.endswith(".nuspec")] + if len(manifests) != 1: + raise SystemExit(f"{path} must contain a single root .nuspec") + manifest = ElementTree.fromstring(archive.read(manifests[0])) + identity = (manifest.findtext("{*}metadata/{*}id"), manifest.findtext("{*}metadata/{*}version")) + if identity != (package_id, version): + raise SystemExit(f"{path} declares {identity}, expected {(package_id, version)}") - name: Publish to NuGet.org env: diff --git a/README.md b/README.md index 11106a2..1c57d4a 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ If you only need the raw header value, use `httpContext.GetUserAgentString()`. 1. **Robots**: search engine crawlers (e.g. Googlebot, Bingbot, Applebot, DuckDuckBot, YandexBot), SEO crawlers (e.g. AhrefsBot, SemrushBot, Screaming Frog) and AI crawlers and AI user agents (e.g. GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, PerplexityBot, Amazonbot, Bytespider, CCBot) 2. **Platform**: Windows, macOS, iOS, Android, ChromeOS, Linux and others 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) -4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Yandex Browser, UC Browser and others +4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Amazon Silk, Yandex Browser, UC Browser and others In every list the first matching entry wins. Browser and version tokens only count at the start of a token: at the beginning of the user agent or after a space, tab, `+`, `;`, `(`, `)` or `,`, so `Knowledge/1.0` is no Edge and `VendorVersion/1.0` no version token. The version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next of these characters; Opera and Internet Explorer also accept `Opera 9.50` and `MSIE 6.0`; their separate version tokens (`Version/`, `rv:`) only count after the browser token. If a token has no version, later occurrences of the token are checked, then the next rule. `+` stands for a space as in URL-encoded logs (IIS); decode other encodings such as `%20` before parsing, e.g. with `WebUtility.UrlDecode`. @@ -152,7 +152,7 @@ The patterns use `RegexOptions.IgnoreCase` with culture-invariant case mapping, ### Custom robots -`HttpUserAgentStatics.Robots` lists the robots in priority order. The first key found in the user agent wins, ignoring case. `SetRobots` replaces the list for the entire process, including existing instances of both built-in cache providers. A parse already in progress can finish with its previous rules. To extend the defaults at startup, pass the default entries followed by your own. +`HttpUserAgentStatics.Robots` lists the robots in priority order. The first key found in the user agent wins, ignoring case. Spaces in a key also match IIS-encoded plus signs, while a key containing a literal plus sign is matched against the original header. `SetRobots` replaces the list for the entire process, including existing instances of both built-in cache providers. A parse already in progress can finish with its previous rules. To extend the defaults at startup, pass the default entries followed by your own. ```csharp HttpUserAgentStatics.SetRobots([.. HttpUserAgentStatics.DefaultRobots, ("MyCrawler", "My Crawler")]); @@ -292,7 +292,7 @@ public void ConfigureServices(IServiceCollection services) } ``` -Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another meter replaces it; a measurement that runs exactly during that switch may be lost. Meters you pass in are never disposed. The core and the MemoryCache package need separate meters, because both create the instruments `cache.hit`, `cache.miss` and `cache.size`, and a meter keeps its instruments until it is disposed: a meter that one of them has used is rejected by the other with an `ArgumentException`, also after a switch. The ASP.NET Core package may share a meter with either. +Each package records to one meter at a time. Without an argument, the package creates its meter once. Pass your own `Meter` to `WithMeterTelemetry(meter)`, `WithMemoryCacheMeterTelemetry(meter)` or `WithAspNetCoreMeterTelemetry(meter)` to record to it instead. A later registration with another meter (including `WithMeterTelemetryPrefix`) replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments. The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another meter replaces it; a measurement that runs exactly during that switch may be lost. Registering that disposed meter again with the same package throws an `ObjectDisposedException`. Meters supplied by callers remain the caller’s responsibility to dispose. The core and the MemoryCache package need separate meters, because both create the instruments `cache.hit`, `cache.miss` and `cache.size`, and a meter keeps its instruments until it is disposed: a meter that one of them has used is rejected by the other with an `ArgumentException`, also after a switch. The ASP.NET Core package may share a meter with either. ### Meter names and instruments @@ -446,7 +446,7 @@ Notes: Run the parser benchmarks with the .NET 11 runtime (use `-f net8.0`, `net9.0` or `net10.0` for the other runtimes). ```shell -# 7 typical user agents +# individual cases, including the useragents.me snapshot dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks*" # mixed real-world workload (closest to production) dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*MixedWorkloadBenchmarks*" @@ -454,7 +454,7 @@ dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 - dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*BrowserUserAgentBenchmarks*" "*RobotUserAgentBenchmarks*" ``` -The user agents come from `tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs`, which the unit tests use as well. +The individual benchmarks include a fixed sample of desktop, phone, tablet, crawler and HTTP client headers from November 15–22, 2026. The parser tests validate each captured header in `UserAgentsMeSnapshot.cs`. The browser, crawler and mixed workload benchmarks use the separate `UserAgentCatalog.cs` corpus. Both datasets run offline. [Snapshot source](https://useragents.me/api) ### Parser performance diff --git a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs index b269699..ec5bff6 100644 --- a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs +++ b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs @@ -5,6 +5,7 @@ #endif using BenchmarkDotNet.Attributes; +using MyCSharp.HttpUserAgentParser.TestHelpers; using Parser = MyCSharp.HttpUserAgentParser.HttpUserAgentParser; namespace HttpUserAgentParser.Benchmarks; @@ -29,6 +30,12 @@ public static IEnumerable GetTestUserAgents() yield return new("Googlebot", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"); yield return new("Applebot", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15 (Applebot/0.1; +http://www.apple.com/go/applebot)"); yield return new("Unknown", "custom-client/1.0 (+https://example.org/client)"); + yield return new("IIS encoded crawler", "Mozilla/5.0+(compatible;+Screaming+Frog+SEO+Spider/22.0)+Chrome/131"); + + foreach (ObservedUserAgent sample in UserAgentsMeSnapshot.Cases) + { + yield return new TestData(sample.Label, sample.UserAgent); + } } [Benchmark] diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index c63d613..96cc00e 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -19,9 +19,9 @@ public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvi { // MemoryCache checks passive expiration tokens on every lookup, also when a miss from an // older generation finishes after SetRobots. The cache key and callback value stay public types. - internal sealed class RobotRulesChangeToken(IReadOnlyList<(string Key, string Value)> entries) : IChangeToken + internal sealed class RobotRulesChangeToken(object generation) : IChangeToken { - public bool HasChanged => !ReferenceEquals(entries, HttpUserAgentRules.RobotSet.ReadOnlyEntries); + public bool HasChanged => !ReferenceEquals(generation, HttpUserAgentRules.RobotSet.CacheGeneration); public bool ActiveChangeCallbacks => false; public IDisposable RegisterChangeCallback(Action callback, object? state) => CancellationToken.None.Register(callback, state); @@ -103,7 +103,7 @@ private HttpUserAgentInformation ParseAndCache(string userAgent) using (ICacheEntry entry = _memoryCache.CreateEntry(userAgent)) { entry.SetOptions(entryOptions); - entry.ExpirationTokens.Add(s_changeTokens.GetValue(robots, static rules => new RobotRulesChangeToken(rules.ReadOnlyEntries))); + entry.ExpirationTokens.Add(s_changeTokens.GetValue(robots, static rules => new RobotRulesChangeToken(rules.CacheGeneration))); entry.Size = entryOptions.Size ?? 1; entry.Value = information; } diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 6412690..6381c76 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -56,21 +56,15 @@ internal static HttpUserAgentInformation Parse(string userAgent, HttpUserAgentRo } private static HttpUserAgentInformation ParseInternal(string userAgent, HttpUserAgentRobotSet robots) - { - // prepare - userAgent = Cleanup(userAgent); + => Detect(Cleanup(userAgent), robots, AnalyzeUserAgent); - // analyze - if (GetRobot(userAgent, robots) is { } robotName) + private static HttpUserAgentInformation AnalyzeUserAgent(string userAgent, ReadOnlySpan ua, HttpUserAgentRobotSet robots) + { + if (robots.Match(userAgent, ua) is { } robotName) { return HttpUserAgentInformation.CreateForRobot(userAgent, robotName); } - return DetectProducts(userAgent, AnalyzeProducts); - } - - private static HttpUserAgentInformation AnalyzeProducts(string userAgent, ReadOnlySpan ua) - { HttpUserAgentPlatformInformation? platform = FindPlatform(ua); string? mobileDeviceType = FindMobileDevice(ua); @@ -82,23 +76,27 @@ private static HttpUserAgentInformation AnalyzeProducts(string userAgent, ReadOn return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType); } - private delegate T ProductDetector(string original, ReadOnlySpan products); + private delegate T Detector(string original, ReadOnlySpan decoded, TState state); + private delegate T ProductDetector(ReadOnlySpan products); + + private static T DetectProduct(string userAgent, ProductDetector detector) + => Detect(userAgent, detector, static (_, ua, detect) => detect(ua)); // IIS logs use '+' for spaces, including spaces inside product names. Keep the original - // string in the result and use the decoded span for all three product detectors. - private static T DetectProducts(string userAgent, ProductDetector detect) + // string in the result and share the decoded span across all detectors. + private static T Detect(string userAgent, TState state, Detector detect) { ReadOnlySpan ua = userAgent.AsSpan(); if (!ua.Contains('+')) { - return detect(userAgent, ua); + return detect(userAgent, ua, state); } if (ua.Length <= 512) { Span decoded = stackalloc char[ua.Length]; ua.Replace(decoded, '+', ' '); - return detect(userAgent, decoded); + return detect(userAgent, decoded, state); } char[] buffer = ArrayPool.Shared.Rent(ua.Length); @@ -106,7 +104,7 @@ private static T DetectProducts(string userAgent, ProductDetector detect) { Span decoded = buffer.AsSpan(0, ua.Length); ua.Replace(decoded, '+', ' '); - return detect(userAgent, decoded); + return detect(userAgent, decoded, state); } finally { @@ -123,7 +121,7 @@ private static T DetectProducts(string userAgent, ProductDetector detect) /// returns the platform or null /// public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent) - => DetectProducts(userAgent, static (_, ua) => FindPlatform(ua)); + => DetectProduct(userAgent, FindPlatform); private static HttpUserAgentPlatformInformation? FindPlatform(ReadOnlySpan ua) { @@ -132,28 +130,25 @@ private static T DetectProducts(string userAgent, ProductDetector detect) foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) { int index = ua.IndexOf(token, StringComparison.OrdinalIgnoreCase); - if (index < 0) - { - continue; - } - - // Short names can occur inside other words ("Microsoft", "Magnum", "CrOS x86"). - if (platform.RegexId is not (HttpUserAgentPlatformRegexId.CrOS or HttpUserAgentPlatformRegexId.Gnu or HttpUserAgentPlatformRegexId.OsX)) - { - return platform; - } - - do + while (index >= 0) { int end = index + token.Length; - if (IsTokenStart(ua, index) && IsProductNameEnd(ua, end)) + bool matches = platform.RegexId switch + { + // Short names can occur inside other words such as "Microsoft" or "Magnum". + HttpUserAgentPlatformRegexId.CrOS or HttpUserAgentPlatformRegexId.Gnu or HttpUserAgentPlatformRegexId.OsX + => IsTokenStart(ua, index) && IsProductNameEnd(ua, end), + // NT 6.1.7601 is Windows 7, while NT 6.10 is a different version. + _ when char.IsAsciiDigit(token[^1]) => end == ua.Length || !char.IsAsciiDigit(ua[end]), + _ => true, + }; + if (matches) { return platform; } index = IndexOfTokenStart(ua, token, end); } - while (index >= 0); } return null; @@ -177,7 +172,7 @@ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out Http /// or after a space, tab, +, ;, (, ) or ,. /// public static (string Name, string? Version)? GetBrowser(string userAgent) - => DetectProducts(userAgent, static (_, ua) => FindBrowser(ua)); + => DetectProduct(userAgent, FindBrowser); private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua) { @@ -349,33 +344,7 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri /// returns the robot or null /// public static string? GetRobot(string userAgent) - => GetRobot(userAgent, HttpUserAgentRules.RobotSet); - - private static string? GetRobot(string userAgent, HttpUserAgentRobotSet robots) - { - // The first robot (Googlebot in the default list, by far the most common robot) is checked on its own. - if (robots.FirstKey is { } firstKey && userAgent.AsSpan().Contains(firstKey, StringComparison.OrdinalIgnoreCase)) - { - return robots.FirstValue; - } - - return FindRobot(userAgent, robots); - } - - /// - /// Finds the first robot after the first one; separate from , so its check of the first robot stays small. - /// - private static string? FindRobot(ReadOnlySpan ua, HttpUserAgentRobotSet robots) - { - // The few anchors rule out most user agents (browsers) before the full key search. - if (!robots.AnchorMatcher.ContainsAny(ua)) - { - return null; - } - - int index = robots.Matcher.Find(ua, 1, out _); - return index >= 0 ? robots.Entries[index].Value : null; - } + => Detect(userAgent, HttpUserAgentRules.RobotSet, static (original, decoded, robots) => robots.Match(original, decoded)); /// /// returns true if robot was found @@ -390,11 +359,11 @@ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? /// returns the device or null /// public static string? GetMobileDevice(string userAgent) - => DetectProducts(userAgent, static (_, ua) => FindMobileDevice(ua)); + => DetectProduct(userAgent, FindMobileDevice); private static string? FindMobileDevice(ReadOnlySpan ua) { - int index = HttpUserAgentRules.MobileMatcher.Find(ua, 0, out _); + int index = HttpUserAgentRules.MobileMatcher.Find(ua, 0); return index >= 0 ? HttpUserAgentRules.Mobiles[index].Value : null; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs index 18169ff..9622bb6 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs @@ -175,6 +175,7 @@ internal static partial class HttpUserAgentRegexes // The numbered group is public behavior: consumers read the version from Groups[1], so ExplicitCapture must not be used. #pragma warning disable MA0023 // Use RegexOptions.ExplicitCapture or named groups [GeneratedRegex(@"OPR.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserOpr(); + [GeneratedRegex(@"Silk.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserSilk(); [GeneratedRegex(@"Flock.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserFlock(); [GeneratedRegex(@"Edge.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserEdge(); [GeneratedRegex(@"EdgA.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserEdgA(); diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs index 399c370..0d51097 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -11,40 +11,60 @@ namespace MyCSharp.HttpUserAgentParser; /// internal sealed class HttpUserAgentRobotSet { + private readonly int[] _literalPlusRules; + /// /// Creates the set for in priority order; the array must not be changed afterwards. /// public HttpUserAgentRobotSet((string Key, string Value)[] robots) { - Entries = robots; ReadOnlyEntries = [.. robots]; Keys = Array.ConvertAll(robots, static robot => robot.Key); - // Without robots there is no first robot. - (FirstKey, FirstValue) = robots.Length > 0 ? robots[0] : (null, null); + _literalPlusRules = [.. Enumerable.Range(0, robots.Length).Where(i => robots[i].Key.Contains('+'))]; // The first robot is checked on its own (Googlebot in the default list, by far the most common robot): own group. - Matcher = Keys.Length > 1 - ? new PriorityTokenMatcher(Keys, 1) - : new PriorityTokenMatcher(Keys); + Matcher = new PriorityTokenMatcher(Keys, 1); AnchorMatcher = new PriorityTokenMatcher( HttpUserAgentRules.CreateRobotAnchors(Keys, HttpUserAgentRules.CuratedRobotAnchors)); } /// - /// Gets the key of the first robot, or without robots. + /// Matches both IIS-encoded names and literal plus signs in custom keys, in configured priority order. /// - public string? FirstKey { get; } + public string? Match(string original, ReadOnlySpan decoded) + { + int index = Find(decoded); + foreach (int literal in _literalPlusRules) + { + if (index >= 0 && literal >= index) + { + break; + } - /// - /// Gets the name of the first robot. - /// - public string? FirstValue { get; } + if (original.AsSpan().Contains(Keys[literal], StringComparison.OrdinalIgnoreCase)) + { + return ReadOnlyEntries[literal].Value; + } + } + + return index >= 0 ? ReadOnlyEntries[index].Value : null; + } + + private int Find(ReadOnlySpan input) + { + if (Keys.Length > 0 && input.Contains(Keys[0], StringComparison.OrdinalIgnoreCase)) + { + return 0; + } + + return Keys.Length > 1 && AnchorMatcher.ContainsAny(input) ? Matcher.Find(input, 1) : -1; + } /// - /// Gets the robots in priority order. + /// Opaque identity for cache entries. Expired entries can retain this object without retaining the rules. /// - public (string Key, string Value)[] Entries { get; } + public object CacheGeneration { get; } = new(); /// /// Gets the robots as read-only list for . @@ -52,7 +72,7 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) public IReadOnlyList<(string Key, string Value)> ReadOnlyEntries { get; } /// - /// Gets the keys of . + /// Gets the keys in priority order. /// public string[] Keys { get; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 9a3e2c2..9b97bfe 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -98,6 +98,7 @@ internal static class HttpUserAgentRules ("Vivaldi", "Vivaldi", null), ("Flock", "Flock", null), // Chromium based browsers with their own token (their UAs contain "Chrome/" as well) + ("Amazon Silk", "Silk", null), ("Samsung Internet", "SamsungBrowser", null), ("Yandex Browser", "YaBrowser", null), ("UC Browser", "UCBrowser", null), @@ -210,6 +211,7 @@ internal static class HttpUserAgentRules ( "Google-InspectionTool", "Google-InspectionTool" ), ( "GoogleOther", "GoogleOther" ), ( "Google-CloudVertexBot", "Google-CloudVertexBot" ), + ( "Bravebot/", "Bravebot" ), ( "DuckDuckBot", "DuckDuckBot" ), ( "SeznamBot", "SeznamBot" ), ( "Sogou web spider", "Sogou" ), // "Sogou" alone would match the Sogou browser @@ -224,6 +226,10 @@ internal static class HttpUserAgentRules ( "serpstatbot", "serpstatbot" ), // AI crawlers and AI user agents (Claude-SearchBot and Claude-User contain "claudebot@anthropic.com") ( "ChatGPT-User", "ChatGPT-User" ), + ( "KimiBot/", "KimiBot" ), + ( "DeepSeekBot/", "DeepSeekBot" ), + ( "ChatGLM-Spider/", "ChatGLM-Spider" ), + ( "OAI-AdsBot/", "OAI-AdsBot" ), ( "Claude-SearchBot", "Claude-SearchBot" ), ( "Claude-User", "Claude-User" ), ( "ClaudeBot", "ClaudeBot" ), diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index 2ee7772..5bb8722 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -33,6 +33,7 @@ public static class HttpUserAgentStatics public static readonly FrozenDictionary Browsers = new Dictionary() { { HttpUserAgentRegexes.BrowserOpr(), "Opera" }, + { HttpUserAgentRegexes.BrowserSilk(), "Amazon Silk" }, { HttpUserAgentRegexes.BrowserFlock(), "Flock" }, { HttpUserAgentRegexes.BrowserEdge(), "Edge" }, { HttpUserAgentRegexes.BrowserEdgA(), "Edge" }, @@ -94,6 +95,7 @@ public static class HttpUserAgentStatics /// /// The list applies to all following parses in the process; it is replaced atomically, so a parse running at the same /// time uses either the previous or the new list. Both built-in cache providers honor the change on the next call. + /// Spaces in a key also match IIS-encoded plus signs. A plus sign in the key matches the original header literally. /// To extend the defaults, pass e.g. /// [.. HttpUserAgentStatics.DefaultRobots, ("MyCrawler", "My Crawler")]; restores them. /// Building the matchers takes a moment, so set the list once at startup rather than per request. diff --git a/src/HttpUserAgentParser/PriorityTokenMatcher.cs b/src/HttpUserAgentParser/PriorityTokenMatcher.cs index 061da2f..97c3809 100644 --- a/src/HttpUserAgentParser/PriorityTokenMatcher.cs +++ b/src/HttpUserAgentParser/PriorityTokenMatcher.cs @@ -2,6 +2,7 @@ #if NET9_0_OR_GREATER using System.Buffers; +using System.Runtime.InteropServices; #endif namespace MyCSharp.HttpUserAgentParser; @@ -94,8 +95,7 @@ public bool ContainsAny(ReadOnlySpan input) /// /// The text to search. /// The first token index to consider. - /// The position of the first occurrence of the returned token in , otherwise -1. - public int Find(ReadOnlySpan input, int startIndex, out int position) + public int Find(ReadOnlySpan input, int startIndex) { string[] tokens = _tokens; #if NET9_0_OR_GREATER @@ -108,8 +108,7 @@ public int Find(ReadOnlySpan input, int startIndex, out int position) for (int i = Math.Max(group.Start, startIndex); i < group.End; i++) { - position = input.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase); - if (position >= 0) + if (input.Contains(tokens[i], StringComparison.OrdinalIgnoreCase)) { return i; } @@ -118,15 +117,13 @@ public int Find(ReadOnlySpan input, int startIndex, out int position) #else for (int i = startIndex; i < tokens.Length; i++) { - position = input.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase); - if (position >= 0) + if (input.Contains(tokens[i], StringComparison.OrdinalIgnoreCase)) { return i; } } #endif - position = -1; return -1; } } @@ -151,8 +148,7 @@ private PriorityTokenGroup(int start, int end, List values, List { Start = start; End = end; - FilterValues = [.. values]; - Values = values.Count > 0 ? SearchValues.Create(FilterValues, StringComparison.OrdinalIgnoreCase) : null; + Values = values.Count > 0 ? SearchValues.Create(CollectionsMarshal.AsSpan(values), StringComparison.OrdinalIgnoreCase) : null; ShortTokens = [.. shortTokens]; } @@ -166,11 +162,6 @@ private PriorityTokenGroup(int start, int end, List values, List /// public int End { get; } - /// - /// The tokens used for the vectorized group filter (after removing redundant tokens). - /// - public string[] FilterValues { get; } - /// /// The vectorized group filter, if the group only has short tokens. /// diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs index 42be360..18e5248 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs @@ -50,6 +50,10 @@ public void Dispose() /// public Meter Meter { get; } = meter; + // An owned meter lives for one registration. Its instruments stay discoverable from + // listener-held references after replacement, even though they no longer emit measurements. + public bool IsOwned { get; set; } + /// /// Creates the instruments that do not exist yet. /// @@ -170,6 +174,10 @@ public void Use(Meter? meter, string ownedMeterName) { reserve(target); TInstruments instruments = (TInstruments)_instrumentsByMeter.GetValue(target, _createInstruments); + // Use() already returned for the current meter and serialized publication on this target. + // Any other previously owned target has been retired, including a failed first publication. + ObjectDisposedException.ThrowIf(instruments.IsOwned, target); + instruments.IsOwned = own; instruments.CreateMissingInstruments(); lock (_lock) diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs index 9d30907..d483458 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/Telemetry/HttpUserAgentParserAspNetCoreMetersTelemetryTests.cs @@ -18,79 +18,34 @@ public sealed class HttpUserAgentParserAspNetCoreMetersTelemetryTests : IDisposa public void Dispose() => HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); - [Fact] - public void Meters_Emit_WhenEnabled() - { - HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); - - using MeterTestListener listener = new("mycsharp.http_user_agent_parser.aspnetcore"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithAspNetCoreMeterTelemetry(); - - DefaultHttpContext ctx = new(); - - // present - ctx.Request.Headers.UserAgent = "UA"; - Assert.NotNull(ctx.GetUserAgentString()); - - // missing - ctx.Request.Headers.Remove("User-Agent"); - Assert.Null(ctx.GetUserAgentString()); - - Assert.Contains("user_agent.present", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("user_agent.missing", listener.InstrumentNames, StringComparer.Ordinal); - } - - [Fact] - public void Meters_Emit_WhenEnabled_WithCustomPrefix() - { - HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); - - const string prefix = "acme."; - using MeterTestListener listener = new("acme.http_user_agent_parser.aspnetcore"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithAspNetCoreMeterTelemetryPrefix(prefix); - - DefaultHttpContext ctx = new(); - - // present - ctx.Request.Headers.UserAgent = "UA"; - Assert.NotNull(ctx.GetUserAgentString()); - - // missing - ctx.Request.Headers.Remove("User-Agent"); - Assert.Null(ctx.GetUserAgentString()); - - Assert.Contains("user_agent.present", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("user_agent.missing", listener.InstrumentNames, StringComparer.Ordinal); - } - - [Fact] - public void Meters_Emit_WhenEnabled_WithEmptyPrefix() + [Theory] + [InlineData(null, "mycsharp.http_user_agent_parser.aspnetcore")] + [InlineData("acme.", "acme.http_user_agent_parser.aspnetcore")] + [InlineData("", "http_user_agent_parser.aspnetcore")] + public void Configured_Meter_Emits_Expected_Measurements(string? prefix, string meterName) { - HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); - - using MeterTestListener listener = new("http_user_agent_parser.aspnetcore"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithAspNetCoreMeterTelemetryPrefix(string.Empty); - - DefaultHttpContext ctx = new(); + using MeterTestListener listener = new(meterName); + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + if (prefix is null) + { + options.WithAspNetCoreMeterTelemetry(); + } + else + { + options.WithAspNetCoreMeterTelemetryPrefix(prefix); + } - // present - ctx.Request.Headers.UserAgent = "UA"; - Assert.NotNull(ctx.GetUserAgentString()); + DefaultHttpContext context = new(); + Assert.Null(context.GetUserAgentString()); + context.Request.Headers.UserAgent = "Chrome/17"; + Assert.Equal("Chrome/17", context.GetUserAgentString()); - Assert.Contains("user_agent.present", listener.InstrumentNames, StringComparer.Ordinal); + Assert.Equal(new[] { "user_agent.missing", "user_agent.present" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); } [Fact] public void WithAspNetCoreMeterTelemetryPrefix_Throws_WhenInvalid() { - HttpUserAgentParserAspNetCoreTelemetry.ResetForTests(); - HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); Assert.Throws(() => options.WithAspNetCoreMeterTelemetryPrefix("acme")); @@ -108,7 +63,7 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() options.WithAspNetCoreMeterTelemetryPrefix("repeated."); } - Assert.Equal((1, 2), CountLiveMeters("repeated.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), MeterTestListener.CountLiveMeters("repeated.http_user_agent_parser.aspnetcore")); } [Fact] @@ -119,18 +74,18 @@ public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() options.WithAspNetCoreMeterTelemetryPrefix("first."); options.WithAspNetCoreMeterTelemetryPrefix("first."); // the meter in use: kept - Assert.Equal((1, 2), CountLiveMeters("first.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), MeterTestListener.CountLiveMeters("first.http_user_agent_parser.aspnetcore")); options.WithAspNetCoreMeterTelemetryPrefix("second."); - Assert.Equal((0, 0), CountLiveMeters("first.http_user_agent_parser.aspnetcore")); - Assert.Equal((1, 2), CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("first.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), MeterTestListener.CountLiveMeters("second.http_user_agent_parser.aspnetcore")); options.WithAspNetCoreMeterTelemetry(callerMeter); - Assert.Equal((0, 0), CountLiveMeters("second.http_user_agent_parser.aspnetcore")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("second.http_user_agent_parser.aspnetcore")); options.WithAspNetCoreMeterTelemetry(); // the default meter replaces the meter of the caller - Assert.Equal((1, 2), CountLiveMeters("caller.http_user_agent_parser.aspnetcore")); - Assert.Equal((1, 2), CountLiveMeters("mycsharp.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), MeterTestListener.CountLiveMeters("caller.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), MeterTestListener.CountLiveMeters("mycsharp.http_user_agent_parser.aspnetcore")); } [Fact] @@ -145,10 +100,10 @@ public void Changing_Prefixes_Keep_Only_The_Meter_In_Use() for (int i = 0; i < 31; i++) { - Assert.Equal((0, 0), CountLiveMeters($"changing{i}.http_user_agent_parser.aspnetcore")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters($"changing{i}.http_user_agent_parser.aspnetcore")); } - Assert.Equal((1, 2), CountLiveMeters("changing31.http_user_agent_parser.aspnetcore")); + Assert.Equal((1, 2), MeterTestListener.CountLiveMeters("changing31.http_user_agent_parser.aspnetcore")); } [Fact] @@ -171,7 +126,7 @@ public void A_Throwing_Listener_Keeps_The_Meter_In_Use() HttpUserAgentParserAspNetCoreMeters.Enable(first); Assert.Throws(() => HttpUserAgentParserAspNetCoreMeters.Enable(second)); Assert.Throws(() => HttpUserAgentParserAspNetCoreMeters.EnableOwnedMeter("throwing.own")); - Assert.Equal((0, 0), CountLiveMeters("throwing.own")); // the new own meter is disposed again + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("throwing.own")); // the new own meter is disposed again using MeterTestListener recorder = new("throwing.first"); HttpUserAgentParserAspNetCoreMeters.UserAgentPresent(); @@ -221,26 +176,4 @@ public async Task No_Measurement_Is_Lost_While_Meters_Of_The_Caller_Are_Switched await switcher; Assert.Equal(measurements, Interlocked.Read(ref recorded)); } - - /// - /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. - /// - private static (int Meters, int Instruments) CountLiveMeters(string meterName) - { - HashSet meters = []; - int instruments = 0; - using MeterListener listener = new() - { - InstrumentPublished = (instrument, _) => - { - if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) - { - meters.Add(instrument.Meter); - instruments++; - } - }, - }; - listener.Start(); - return (meters.Count, instruments); - } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs index 30dcfd8..5265e87 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheMetersTelemetryTests.cs @@ -17,86 +17,35 @@ public sealed class HttpUserAgentParserMemoryCacheMetersTelemetryTests : IDispos public void Dispose() => HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); - [Fact] - public void Meters_Emit_WhenEnabled() - { - HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); - - using MeterTestListener listener = new("mycsharp.http_user_agent_parser.memorycache"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithMemoryCacheMeterTelemetry(); - - HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); - - const string ua1 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; - const string ua2 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/88.0"; - - _ = provider.Parse(ua1); // miss - _ = provider.Parse(ua1); // hit - _ = provider.Parse(ua2); // miss - - listener.RecordObservableInstruments(); - - Assert.Contains("cache.hit", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.miss", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.size", listener.InstrumentNames, StringComparer.Ordinal); - } - - [Fact] - public void Meters_Emit_WhenEnabled_WithCustomPrefix() - { - HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); - - const string prefix = "acme."; - using MeterTestListener listener = new("acme.http_user_agent_parser.memorycache"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithMemoryCacheMeterTelemetryPrefix(prefix); - - HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); - - const string ua1 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; - const string ua2 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/88.0"; - - _ = provider.Parse(ua1); // miss - _ = provider.Parse(ua1); // hit - _ = provider.Parse(ua2); // miss - - listener.RecordObservableInstruments(); - - Assert.Contains("cache.hit", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.miss", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.size", listener.InstrumentNames, StringComparer.Ordinal); - } - - [Fact] - public void Meters_Emit_WhenEnabled_WithEmptyPrefix() + [Theory] + [InlineData(null, "mycsharp.http_user_agent_parser.memorycache")] + [InlineData("acme.", "acme.http_user_agent_parser.memorycache")] + [InlineData("", "http_user_agent_parser.memorycache")] + public void Configured_Meter_Emits_Expected_Measurements(string? prefix, string meterName) { - HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); - - using MeterTestListener listener = new("http_user_agent_parser.memorycache"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithMemoryCacheMeterTelemetryPrefix(string.Empty); - - HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); - - const string ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; - - _ = provider.Parse(ua); // miss + using MeterTestListener listener = new(meterName); + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + if (prefix is null) + { + options.WithMemoryCacheMeterTelemetry(); + } + else + { + options.WithMemoryCacheMeterTelemetryPrefix(prefix); + } + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Firefox/12"); listener.RecordObservableInstruments(); - Assert.Contains("cache.miss", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.size", listener.InstrumentNames, StringComparer.Ordinal); + Assert.Equal(new[] { "cache.hit", "cache.miss", "cache.miss", "cache.size" }, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); } [Fact] public void WithMemoryCacheMeterTelemetryPrefix_Throws_WhenInvalid() { - HttpUserAgentParserMemoryCacheTelemetry.ResetForTests(); - HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); Assert.Throws(() => options.WithMemoryCacheMeterTelemetryPrefix("acme")); @@ -114,7 +63,7 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() options.WithMemoryCacheMeterTelemetryPrefix("repeated."); } - Assert.Equal((1, 3), CountLiveMeters("repeated.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), MeterTestListener.CountLiveMeters("repeated.http_user_agent_parser.memorycache")); } [Fact] @@ -125,18 +74,18 @@ public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() options.WithMemoryCacheMeterTelemetryPrefix("first."); options.WithMemoryCacheMeterTelemetryPrefix("first."); // the meter in use: kept - Assert.Equal((1, 3), CountLiveMeters("first.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), MeterTestListener.CountLiveMeters("first.http_user_agent_parser.memorycache")); options.WithMemoryCacheMeterTelemetryPrefix("second."); - Assert.Equal((0, 0), CountLiveMeters("first.http_user_agent_parser.memorycache")); - Assert.Equal((1, 3), CountLiveMeters("second.http_user_agent_parser.memorycache")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("first.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), MeterTestListener.CountLiveMeters("second.http_user_agent_parser.memorycache")); options.WithMemoryCacheMeterTelemetry(callerMeter); - Assert.Equal((0, 0), CountLiveMeters("second.http_user_agent_parser.memorycache")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("second.http_user_agent_parser.memorycache")); options.WithMemoryCacheMeterTelemetry(); // the default meter replaces the meter of the caller - Assert.Equal((1, 3), CountLiveMeters("caller.http_user_agent_parser.memorycache")); - Assert.Equal((1, 3), CountLiveMeters("mycsharp.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), MeterTestListener.CountLiveMeters("caller.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), MeterTestListener.CountLiveMeters("mycsharp.http_user_agent_parser.memorycache")); } [Fact] @@ -151,10 +100,10 @@ public void Changing_Prefixes_Keep_Only_The_Meter_In_Use() for (int i = 0; i < 31; i++) { - Assert.Equal((0, 0), CountLiveMeters($"changing{i}.http_user_agent_parser.memorycache")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters($"changing{i}.http_user_agent_parser.memorycache")); } - Assert.Equal((1, 3), CountLiveMeters("changing31.http_user_agent_parser.memorycache")); + Assert.Equal((1, 3), MeterTestListener.CountLiveMeters("changing31.http_user_agent_parser.memorycache")); } [Fact] @@ -177,7 +126,7 @@ public void A_Throwing_Listener_Keeps_The_Meter_In_Use() HttpUserAgentParserMemoryCacheMeters.Enable(first); Assert.Throws(() => HttpUserAgentParserMemoryCacheMeters.Enable(second)); Assert.Throws(() => HttpUserAgentParserMemoryCacheMeters.EnableOwnedMeter("throwing.own")); - Assert.Equal((0, 0), CountLiveMeters("throwing.own")); // the new own meter is disposed again + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("throwing.own")); // the new own meter is disposed again using MeterTestListener recorder = new("throwing.first"); HttpUserAgentParserMemoryCacheMeters.CacheHit(); @@ -228,28 +177,6 @@ public async Task No_Measurement_Is_Lost_While_Meters_Of_The_Caller_Are_Switched Assert.Equal(measurements, Interlocked.Read(ref recorded)); } - /// - /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. - /// - private static (int Meters, int Instruments) CountLiveMeters(string meterName) - { - HashSet meters = []; - int instruments = 0; - using MeterListener listener = new() - { - InstrumentPublished = (instrument, _) => - { - if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) - { - meters.Add(instrument.Meter); - instruments++; - } - }, - }; - listener.Start(); - return (meters.Count, instruments); - } - [Fact] public void A_Meter_Of_The_Core_Package_Is_Rejected_Also_After_A_Switch() { diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs index e384d09..8ac0142 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs @@ -1,6 +1,7 @@ // Copyright © https://myCSharp.de - all rights reserved using System.Diagnostics.Metrics; +using System.Runtime.CompilerServices; using Microsoft.Extensions.DependencyInjection; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; @@ -25,15 +26,10 @@ public sealed class HttpUserAgentParserMemoryCacheTelemetryPathTests : IDisposab public void Cached_Result_Expires_When_Robot_Rules_Change() { using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); - HttpUserAgentParserMemoryCachedProvider.RobotRulesChangeToken change = new(HttpUserAgentStatics.Robots); - Assert.False(change.ActiveChangeCallbacks); - Assert.False(change.HasChanged); - using IDisposable registration = change.RegisterChangeCallback(static _ => Assert.Fail("A passive token must not invoke callbacks."), null); try { Assert.Equal("Chrome", provider.Parse(UserAgent).Name); HttpUserAgentStatics.SetRobots([("Chrome", "Custom")]); - Assert.True(change.HasChanged); Assert.Equal("Custom", provider.Parse(UserAgent).Name); HttpUserAgentStatics.SetRobots([]); Assert.Equal("Chrome", provider.Parse(UserAgent).Name); @@ -45,7 +41,43 @@ public void Cached_Result_Expires_When_Robot_Rules_Change() } [Fact] - public void Rule_Change_During_A_Miss_Cannot_Leave_A_Stale_Cache_Hit() + public void Cached_Entry_Releases_The_Old_Rule_List_Before_Its_Next_Lookup() + { + using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); + try + { + WeakReference oldRules = CacheWithTemporaryRules(provider); + HttpUserAgentStatics.SetRobots([]); + GC.Collect(); + + Assert.False(oldRules.IsAlive); + Assert.Equal("Chrome", provider.Parse(UserAgent).Name); + } + finally + { + HttpUserAgentStatics.SetRobots(HttpUserAgentStatics.DefaultRobots); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static WeakReference CacheWithTemporaryRules(HttpUserAgentParserMemoryCachedProvider provider) + { + HttpUserAgentStatics.SetRobots([("Chrome", "Temporary")]); + Assert.Equal("Temporary", provider.Parse(UserAgent).Name); + return new WeakReference(HttpUserAgentStatics.Robots); + } + + [Fact] + public void Expired_Rule_Token_Is_Passive() + { + HttpUserAgentParserMemoryCachedProvider.RobotRulesChangeToken expired = new(new object()); + Assert.True(expired.HasChanged); + Assert.False(expired.ActiveChangeCallbacks); + using IDisposable registration = expired.RegisterChangeCallback(static _ => Assert.Fail("Passive token invoked a callback."), null); + } + + [Fact] + public void Miss_Listener_Can_Read_The_Published_Entry_And_Replace_The_Rules() { using HttpUserAgentParserMemoryCachedProvider provider = new(new HttpUserAgentParserMemoryCachedProviderOptions()); using Meter meter = new("robots.memorycache"); diff --git a/tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs b/tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs index 6b26d20..4ae1999 100644 --- a/tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs +++ b/tests/HttpUserAgentParser.TestHelpers/MeterTestListener.cs @@ -46,6 +46,26 @@ public MeterTestListener(string meterName) _listener.Start(); } + /// Counts active meters with the specified name and their instruments. + public static (int Meters, int Instruments) CountLiveMeters(string meterName) + { + HashSet meters = []; + int instruments = 0; + using MeterListener listener = new() + { + InstrumentPublished = (instrument, _) => + { + if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) + { + meters.Add(instrument.Meter); + instruments++; + } + }, + }; + listener.Start(); + return (meters.Count, instruments); + } + /// Collects the current observable measurements. public void RecordObservableInstruments() => _listener.RecordObservableInstruments(); diff --git a/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs b/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs new file mode 100644 index 0000000..40fc087 --- /dev/null +++ b/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs @@ -0,0 +1,142 @@ +// Copyright © https://myCSharp.de - all rights reserved + +namespace MyCSharp.HttpUserAgentParser.TestHelpers; + +/// A captured header and the expected fields in the parser's public result. +public sealed record ObservedUserAgent(string Label, string UserAgent, HttpUserAgentType Type, string? Name, string? Version, string? Platform, string? Device); + +/// Representative headers from https://useragents.me/api for November 15–22, 2026. +public static class UserAgentsMeSnapshot +{ + /// Fixed inputs from the common and latest sections, shared by tests and benchmarks. + public static IReadOnlyList Cases { get; } = + [ + // Desktop browsers and incomplete headers + new("Chrome 152 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "152.0.0.0", "Windows 10", null), + new("Chrome 131 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "131.0.0.0", "Mac OS X", null), + new("Safari 17 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15", + HttpUserAgentType.Browser, "Safari", "17.6", "Mac OS X", null), + new("Chrome 39 WOW64", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95", + HttpUserAgentType.Browser, "Chrome", "39.0.2171.95", "Windows 7", null), + new("Opera 9 Windows XP", "Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50", + HttpUserAgentType.Browser, "Opera", "9.50", "Windows XP", null), + new("Firefox 34 Windows 7", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0", + HttpUserAgentType.Browser, "Firefox", "34.0", "Windows 7", null), + new("Edge 157 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Edg/157.0.0.0", + HttpUserAgentType.Browser, "Edge", "157.0.0.0", "Windows 10", null), + new("WebKit only Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + HttpUserAgentType.Unknown, null, null, "Windows 10", null), + new("Edge 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Edg/158.0.4370.33", + HttpUserAgentType.Browser, "Edge", "158.0.4370.33", "Windows 10", null), + new("Vivaldi WOW64", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Vivaldi/8.1.4087.61", + HttpUserAgentType.Browser, "Vivaldi", "8.1.4087.61", "Windows 10", null), + new("Opera WOW64", "Mozilla/5.0 (Windows NT 10.0; WOW64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/141.0.0.0", + HttpUserAgentType.Browser, "Opera", "141.0.0.0", "Windows 10", null), + new("Safari 27 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_8_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Safari/605.1.15", + HttpUserAgentType.Browser, "Safari", "27.0", "Mac OS X", null), + new("Yandex macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 YaBrowser/26.11.0.2030 Yowser/2.5 Safari/537.36", + HttpUserAgentType.Browser, "Yandex Browser", "26.11.0.2030", "Mac OS X", null), + new("Firefox 160 Linux i686", "Mozilla/5.0 (X11; Linux i686; rv:160.0) Gecko/20100101 Firefox/160.0", + HttpUserAgentType.Browser, "Firefox", "160.0", "Linux", null), + new("Firefox 153 Linux x64", "Mozilla/5.0 (Linux x86_64; rv:153.0) Gecko/20100101 Firefox/153.0", + HttpUserAgentType.Browser, "Firefox", "153.0", "Linux", null), + + // Phones and embedded browsers + new("Safari 13 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Safari", "13.0.3", "iOS", "Apple iPhone"), + new("Safari 26 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6.1 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Safari", "26.6.1", "iOS", "Apple iPhone"), + new("Reduced Chrome Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Mobile Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "152.0.0.0", "Android", "Android"), + new("Misspelled WebView", "Mozlila/5.0 (Linux; Android 7.0; SM-G892A Bulid/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Moblie Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "60.0.3112.107", "Android", "Android"), + new("Edge Galaxy Core Max", "Mozilla/5.0 (Linux; Android 11; SM-G5108; Build/RQ1D.180114.135) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.3124.85 Mobile Safari/537.36 EdgA/134.0.3124.85", + HttpUserAgentType.Browser, "Edge", "134.0.3124.85", "Android", "Android"), + new("Chrome Galaxy J7", "Mozilla/5.0 (Linux; Android 7.0; SM-G610F Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "62.0.3202.84", "Android", "Android"), + new("Chrome iPod", "Mozilla/5.0 (iPod; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/158.0.8127.35 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Chrome", "158.0.8127.35", "iOS", "Apple iPod"), + new("Edge iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 EdgiOS/157.4341.57 Mobile/15E148 Safari/605.1.15", + HttpUserAgentType.Browser, "Edge", "157.4341.57", "iOS", "Apple iPhone"), + new("Firefox iPod touch", "Mozilla/5.0 (iPod touch; CPU iPhone OS 15_8_3 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) FxiOS/160.0 Mobile/15E148 Safari/605.1.15", + HttpUserAgentType.Browser, "Firefox", "160.0", "iOS", "Apple iPod"), + new("Safari iPod touch", "Mozilla/5.0 (iPod touch; CPU iPhone 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Safari", "27.0", "iOS", "Apple iPod"), + new("Yandex iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 YaBrowser/26.11.2.1177 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Yandex Browser", "26.11.2.1177", "iOS", "Apple iPhone"), + new("Edge Pixel 3 XL", "Mozilla/5.0 (Linux; Android 10; Pixel 3 XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.8127.43 Mobile Safari/537.36 EdgA/157.0.4341.53", + HttpUserAgentType.Browser, "Edge", "157.0.4341.53", "Android", "Android"), + new("Firefox LG", "Mozilla/5.0 (Android 17; Mobile; LG-M255; rv:160.0) Gecko/160.0 Firefox/160.0", + HttpUserAgentType.Browser, "Firefox", "160.0", "Android", "LG"), + new("Opera Android", "Mozilla/5.0 (Linux; Android 10; VOG-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.8127.43 Mobile Safari/537.36 OPR/76.2.4027.73374", + HttpUserAgentType.Browser, "Opera", "76.2.4027.73374", "Android", "Android"), + new("Yandex Android ARM64", "Mozilla/5.0 (Linux; arm_64; Android 17; SM-G965F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.8127.43 YaBrowser/26.11.0.315 Mobile Safari/537.36", + HttpUserAgentType.Browser, "Yandex Browser", "26.11.0.315", "Android", "Android"), + + // Tablets + new("Firefox Android tablet", "Mozilla/5.0 (Android 5.1.1; Tablet; rv:57.0) Gecko/57.0 Firefox/57.0", + HttpUserAgentType.Browser, "Firefox", "57.0", "Android", "Android"), + new("Reduced Chrome tablet", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "157.0.0.0", "Android", "Android"), + new("Silk Fire tablet", "Mozilla/5.0 (Linux; Android 11; KFTUWI) AppleWebKit/537.36 (KHTML, like Gecko) Silk/156.2.22 like Chrome/156.0.8078.96 Safari/537.36", + HttpUserAgentType.Browser, "Amazon Silk", "156.2.22", "Android", "Android"), + new("Chrome Android tablet 3G", "Mozilla/5.0 (Linux; Android 7.0; T500 3G Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.193 Mobile Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "119.0.6045.193", "Android", "Android"), + new("Chrome Galaxy Tab", "Mozilla/5.0 (Linux; Android 9; SM-T590) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36", + HttpUserAgentType.Browser, "Chrome", "81.0.4044.138", "Android", "Android"), + new("Safari 7 iPad", "Mozilla/5.0 (iPad; CPU OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML like Gecko) Mobile/12A405 Version/7.0 Safari/9537.53", + HttpUserAgentType.Browser, "Safari", "7.0", "iOS", "Apple iPad"), + new("Safari 9 iPad", "Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1", + HttpUserAgentType.Browser, "Safari", "9.0", "iOS", "Apple iPad"), + new("Firefox ESR tablet", "Mozilla/5.0 (Android 14; Mobile; SM-T590; rv:156.0esr) Gecko/156.0esr Firefox/156.0esr", + HttpUserAgentType.Browser, "Firefox", "156.0", "Android", "Android"), + new("Safari comma version", "Mozilla/5.0 (iPad; CPU OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6,2 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Safari", "15.6", "iOS", "Apple iPad"), + new("Chrome 76 iPad", "Mozilla/5.0 (iPad; CPU OS 12_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/76.0.3809.81 Mobile/15E148 Safari/605.1", + HttpUserAgentType.Browser, "Chrome", "76.0.3809.81", "iOS", "Apple iPad"), + new("Chrome iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/158.0.8127.35 Mobile/15E148 Safari/604.1", + HttpUserAgentType.Browser, "Chrome", "158.0.8127.35", "iOS", "Apple iPad"), + new("Firefox iPad", "Mozilla/5.0 (iPad; CPU OS 15_8_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/160.0 Mobile/15E148 Safari/605.1.15", + HttpUserAgentType.Browser, "Firefox", "160.0", "iOS", "Apple iPad"), + new("Yandex iPad", "Mozilla/5.0 (iPad; CPU OS 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 YaBrowser/26.11.2.1177 Mobile/15E148 Safari/605.1", + HttpUserAgentType.Browser, "Yandex Browser", "26.11.2.1177", "iOS", "Apple iPad"), + new("Versionless iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Safari", + HttpUserAgentType.Unknown, null, null, "iOS", "Apple iPad"), + new("Dalvik Android", "Dalvik/2.1.0 (Linux; U; Android 14; 100146663 Build/UP1A.231005.007)", + HttpUserAgentType.Unknown, null, null, "Android", "Android"), + + // HTTP clients and crawlers + new("Python requests", "python-requests/2.34.2", + HttpUserAgentType.Unknown, null, null, null, null), + new("Python aiohttp", "Python/3.14 aiohttp/3.13.2", + HttpUserAgentType.Unknown, null, null, null, null), + new("curl", "curl/8.23.0", + HttpUserAgentType.Unknown, null, null, null, null), + new("Guzzle", "GuzzleHttp/7", + HttpUserAgentType.Unknown, null, null, null, null), + new("axios", "axios/1.20.0", + HttpUserAgentType.Unknown, null, null, null, null), + new("QQDownload MSIE", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)", + HttpUserAgentType.Browser, "Internet Explorer", "6.0", "Windows XP", null), + new("Bravebot", "Mozilla/5.0 (compatible; Bravebot/1.0; +https://brave.com/search/)", + HttpUserAgentType.Robot, "Bravebot", null, null, null), + new("KimiBot", "Mozilla/5.0 (compatible; KimiBot/1.0; +https://kimi.ai/)", + HttpUserAgentType.Robot, "KimiBot", null, null, null), + new("meta-externalfetcher", "Mozilla/5.0 (compatible; Meta-ExternalFetcher/1.0; +https://developers.facebook.com/docs/sharing/webmasters/crawler)", + HttpUserAgentType.Robot, "meta-externalfetcher", null, null, null), + new("DeepSeekBot", "Mozilla/5.0 (compatible; DeepSeekBot/1.0; +https://www.deepseek.com/)", + HttpUserAgentType.Robot, "DeepSeekBot", null, null, null), + new("ChatGLM-Spider", "Mozilla/5.0 (compatible; ChatGLM-Spider/1.0; +https://zhipuai.cn/)", + HttpUserAgentType.Robot, "ChatGLM-Spider", null, null, null), + new("OAI-AdsBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-AdsBot/1.0; +https://openai.com/adsbot", + HttpUserAgentType.Robot, "OAI-AdsBot", null, null, null), + new("DuckAssistBot", "DuckAssistBot/1.1 (https://duckduckgo.com/duckassistbot)", + HttpUserAgentType.Robot, "DuckAssistBot", null, null, null), + new("OAI-SearchBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-SearchBot/1.0; +https://openai.com/searchbot", + HttpUserAgentType.Robot, "OAI-SearchBot", null, null, null), + new("meta-externalagent", "Mozilla/5.0 (compatible; Meta-ExternalAgent/1.0; +https://developers.facebook.com/docs/sharing/webmasters/crawler)", + HttpUserAgentType.Robot, "meta-externalagent", null, null, null), + ]; +} diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 41b4cf7..aa48a7d 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -379,6 +379,8 @@ public void GetBrowser_ExtractsAsciiVersion(string userAgent, string expectedVer [Theory] [InlineData("Microsoft Office/16.0 (Macintosh; Mac OS X 10.15.7; Microsoft Outlook 16.80.23121017; Pro)", "Mac OS X")] [InlineData("Microsoft-CryptoAPI/10.0", null)] + [InlineData("Windows NT 6.10", "Unknown Windows OS")] + [InlineData("Windows NT 6.10; Windows NT 6.1.7601", "Windows 7")] [InlineData("CrOS", "ChromeOS")] [InlineData("Crosstalk/2 (X11; CrOS)", "ChromeOS")] [InlineData("Microsoft Office (Macros x86)", null)] @@ -390,11 +392,22 @@ public void GetBrowser_ExtractsAsciiVersion(string userAgent, string expectedVer [InlineData("Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "ChromeOS")] [InlineData("Mozilla/5.0+(X11;+CrOS+x86_64+14541.0.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/120.0.0.0+Safari/537.36", "ChromeOS")] [InlineData("Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15063", "Windows Phone")] - public void GetPlatform_Detects_ChromeOS_And_Windows_Phone_Only_By_Their_Own_Tokens(string userAgent, string? expectedPlatform) + public void GetPlatform_Respects_Token_Boundaries_And_Compatibility_Tokens(string userAgent, string? expectedPlatform) { Assert.Equal(expectedPlatform, HttpUserAgentParser.GetPlatform(userAgent)?.Name); } + [Fact] + public void Iis_Encoded_Crawler_Is_Recognized_Before_The_Browser() + { + const string ua = "Mozilla/5.0+(compatible;+Screaming+Frog SEO+Spider/22.0)+Chrome/131"; + HttpUserAgentInformation result = HttpUserAgentParser.Parse(ua); + + Assert.Equal((HttpUserAgentType.Robot, "Screaming Frog SEO Spider", ua), (result.Type, result.Name, result.UserAgent)); + Assert.True(HttpUserAgentParser.TryGetRobot(ua, out string? name)); + Assert.Equal(result.Name, name); + } + [Fact] public void Iis_Spaces_Inside_Product_Names_Are_Decoded_Only_For_Detection() { diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs index ed4ab8a..4fbe793 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -110,6 +110,17 @@ public void SetRobots_Replaces_Keys_And_Names() Assert.Null(HttpUserAgentParser.GetRobot(Chrome)); } + [Fact] + public void Literal_And_Iis_Encoded_Robot_Keys_Respect_Their_Configured_Order() + { + HttpUserAgentStatics.SetRobots([("C++Bot", "Literal"), ("SEO Spider", "Encoded"), ("SEO+Spider", "Literal fallback")]); + + Assert.Equal("Literal", HttpUserAgentParser.GetRobot("seo+spider C++Bot")); + Assert.Equal("Encoded", HttpUserAgentParser.GetRobot("seo+spider")); + Assert.Equal("Literal", HttpUserAgentParser.GetRobot("c++bot")); + Assert.Null(HttpUserAgentParser.GetRobot("C Bot")); + } + [Fact] public void SetRobots_Accepts_A_Single_Robot_And_No_Robots() { diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index f279b94..76d4a51 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -68,7 +68,7 @@ private static readonly (string Token, string Name, HttpUserAgentPlatformType Ty /// private static readonly (string Token, string Name)[] s_expectedBrowsers = [ - ("OPR", "Opera"), ("Flock", "Flock"), ("Edge", "Edge"), ("EdgA", "Edge"), ("Edg", "Edge"), ("Vivaldi", "Vivaldi"), + ("OPR", "Opera"), ("Silk", "Amazon Silk"), ("Flock", "Flock"), ("Edge", "Edge"), ("EdgA", "Edge"), ("Edg", "Edge"), ("Vivaldi", "Vivaldi"), ("Brave Chrome", "Brave"), ("Chrome", "Chrome"), ("CriOS", "Chrome"), ("Opera.*?Version", "Opera"), ("Opera", "Opera"), ("MSIE", "Internet Explorer"), ("Internet Explorer", "Internet Explorer"), ("Trident.* rv", "Internet Explorer"), ("Shiira", "Shiira"), ("Firefox", "Firefox"), ("FxiOS", "Firefox"), ("Chimera", "Chimera"), ("Phoenix", "Phoenix"), diff --git a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs index d91df08..3a8b0ee 100644 --- a/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/PriorityTokenMatcherTests.cs @@ -16,8 +16,7 @@ public void Find_Returns_First_Token_In_Priority_Order_Not_Leftmost_Occurrence() { PriorityTokenMatcher matcher = Create(["beta", "alpha"]); - Assert.Equal(0, matcher.Find("alpha beta", 0, out int position)); - Assert.Equal(6, position); + Assert.Equal(0, matcher.Find("alpha beta", 0)); Assert.Equal(2, matcher.Count); } @@ -26,8 +25,7 @@ public void Find_Starts_At_StartIndex() { PriorityTokenMatcher matcher = Create(["beta", "alpha"]); - Assert.Equal(1, matcher.Find("alpha beta", 1, out int position)); - Assert.Equal(0, position); + Assert.Equal(1, matcher.Find("alpha beta", 1)); } [Fact] @@ -35,8 +33,7 @@ public void Find_Is_Case_Insensitive() { PriorityTokenMatcher matcher = Create(["iphone"]); - Assert.Equal(0, matcher.Find("(IPHONE; CPU)", 0, out int position)); - Assert.Equal(1, position); + Assert.Equal(0, matcher.Find("(IPHONE; CPU)", 0)); } [Fact] @@ -44,8 +41,7 @@ public void Find_Returns_Minus_One_Without_Match() { PriorityTokenMatcher matcher = Create(["alpha", "beta", "lg"]); - Assert.Equal(-1, matcher.Find("gamma", 0, out int position)); - Assert.Equal(-1, position); + Assert.Equal(-1, matcher.Find("gamma", 0)); } [Fact] @@ -53,7 +49,7 @@ public void Find_Without_Tokens_Returns_Minus_One() { PriorityTokenMatcher matcher = Create([]); - Assert.Equal(-1, matcher.Find("anything", 0, out _)); + Assert.Equal(-1, matcher.Find("anything", 0)); } [Fact] @@ -62,8 +58,8 @@ public void Find_Skips_Token_After_Covered_Token_When_StartIndex_Is_Inside_Group // "edg" is the group filter for "edge"; starting at "edge" with only "edg" present must not match. PriorityTokenMatcher matcher = Create(["edg", "edge", "other"]); - Assert.Equal(-1, matcher.Find("edgx", 1, out _)); - Assert.Equal(0, matcher.Find("edgx", 0, out _)); + Assert.Equal(-1, matcher.Find("edgx", 1)); + Assert.Equal(0, matcher.Find("edgx", 0)); } [Fact] @@ -71,10 +67,9 @@ public void Find_Matches_Short_Tokens() { PriorityTokenMatcher matcher = Create(["lg", "o2", "longer"]); - Assert.Equal(1, matcher.Find("Model O2 phone", 0, out int position)); - Assert.Equal(6, position); - Assert.Equal(0, matcher.Find("LG-L160L longer", 0, out _)); - Assert.Equal(2, matcher.Find("a longer text", 0, out _)); + Assert.Equal(1, matcher.Find("Model O2 phone", 0)); + Assert.Equal(0, matcher.Find("LG-L160L longer", 0)); + Assert.Equal(2, matcher.Find("a longer text", 0)); } [Fact] @@ -82,10 +77,9 @@ public void Find_Honors_Forced_Single_Token_Group() { PriorityTokenMatcher matcher = Create(["windows nt 10.0", "windows nt 6.1", "android"], 1); - Assert.Equal(0, matcher.Find("(Windows NT 10.0; Win64)", 0, out int position)); - Assert.Equal(1, position); - Assert.Equal(2, matcher.Find("(Linux; Android 15)", 0, out _)); - Assert.Equal(-1, matcher.Find("(Linux; Android 15)", 3, out _)); + Assert.Equal(0, matcher.Find("(Windows NT 10.0; Win64)", 0)); + Assert.Equal(2, matcher.Find("(Linux; Android 15)", 0)); + Assert.Equal(-1, matcher.Find("(Linux; Android 15)", 3)); } #if NET9_0_OR_GREATER @@ -95,7 +89,7 @@ public void Groups_Extract_Short_Tokens() PriorityTokenMatcher matcher = Create(["lg", "longer", "o2"]); PriorityTokenGroup group = Assert.Single(matcher.Groups.ToArray()); - Assert.Equal(new[] { "longer" }, group.FilterValues); + Assert.True(group.Values!.Contains("longer")); Assert.Equal(new[] { "lg", "o2" }, group.ShortTokens); } @@ -106,8 +100,8 @@ public void Groups_With_Short_Tokens_Only_Have_No_Vectorized_Filter() PriorityTokenGroup group = Assert.Single(matcher.Groups.ToArray()); Assert.Null(group.Values); - Assert.Equal(0, matcher.Find("LG-L160L", 0, out _)); - Assert.Equal(-1, matcher.Find("Pixel", 0, out _)); + Assert.Equal(0, matcher.Find("LG-L160L", 0)); + Assert.Equal(-1, matcher.Find("Pixel", 0)); } [Fact] @@ -116,8 +110,8 @@ public void Groups_Drop_Tokens_Covered_By_Shorter_Tokens() PriorityTokenMatcher covered = Create(["Edg", "Edge", "EdgA", "EdgiOS"]); PriorityTokenMatcher replaced = Create(["Edge", "EdgA", "Edg"]); - Assert.Equal(new[] { "Edg" }, Assert.Single(covered.Groups.ToArray()).FilterValues); - Assert.Equal(new[] { "Edg" }, Assert.Single(replaced.Groups.ToArray()).FilterValues); + Assert.False(Assert.Single(covered.Groups.ToArray()).Values!.Contains("Edge")); + Assert.False(Assert.Single(replaced.Groups.ToArray()).Values!.Contains("Edge")); } [Fact] @@ -127,9 +121,9 @@ public void Groups_Hold_At_Most_Eight_Values() PriorityTokenGroup[] groups = matcher.Groups.ToArray(); Assert.Equal(2, groups.Length); - Assert.Equal(PriorityTokenGroup.MaxValuesPerGroup, groups[0].FilterValues.Length); + Assert.Equal((0, PriorityTokenGroup.MaxValuesPerGroup), (groups[0].Start, groups[0].End)); Assert.Equal((8, 9), (groups[1].Start, groups[1].End)); - Assert.Equal(8, matcher.Find("iii", 0, out _)); + Assert.Equal(8, matcher.Find("iii", 0)); } [Fact] @@ -139,7 +133,8 @@ public void Groups_Accept_A_Token_That_Replaces_Existing_Values() PriorityTokenMatcher matcher = Create(["aaa1", "aaa2", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "aaa"]); PriorityTokenGroup group = Assert.Single(matcher.Groups.ToArray()); - Assert.Equal(new[] { "bbb", "ccc", "ddd", "eee", "fff", "ggg", "aaa" }, group.FilterValues); + Assert.True(group.Values!.Contains("aaa")); + Assert.False(group.Values.Contains("aaa1")); } [Fact] @@ -151,15 +146,6 @@ public void Groups_Start_At_Requested_Indices() Assert.Equal(new[] { (0, 1), (1, 3), (3, 4) }, groups.Select(static g => (g.Start, g.End))); } - [Fact] - public void Built_In_Matchers_Use_Small_Vectorized_Groups() - { - Assert.All(HttpUserAgentRules.DefaultRobotSet.Matcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); - Assert.All(HttpUserAgentRules.MobileMatcher.Groups.ToArray(), static g => Assert.InRange(g.FilterValues.Length, 1, PriorityTokenGroup.MaxValuesPerGroup)); - - // Googlebot, by far the most common robot, is checked on its own. - Assert.Equal((0, 1), (HttpUserAgentRules.DefaultRobotSet.Matcher.Groups[0].Start, HttpUserAgentRules.DefaultRobotSet.Matcher.Groups[0].End)); - } #endif [Fact] @@ -188,32 +174,6 @@ public void Curated_Robot_Anchors_Cover_All_Default_Robot_Keys() Assert.Equal(HttpUserAgentRules.CuratedRobotAnchors.Length, HttpUserAgentRules.DefaultRobotSet.AnchorMatcher.Count); } - public static TheoryData CatalogBrowserUserAgents => [.. UserAgentCatalog.Browsers.Select(static ua => ua.UserAgent)]; - - [Theory] - [MemberData(nameof(CatalogBrowserUserAgents))] - public void Robot_Anchors_Do_Not_Occur_In_Browser_User_Agents(string userAgent) - { - Assert.False(HttpUserAgentRules.DefaultRobotSet.AnchorMatcher.ContainsAny(userAgent)); - } - - [Theory] - [MemberData(nameof(CatalogUserAgents))] - public void GetRobot_Equals_Sequential_Scan(string userAgent) - { - string? expected = null; - foreach ((string key, string value) in HttpUserAgentStatics.Robots) - { - if (userAgent.Contains(key, StringComparison.OrdinalIgnoreCase)) - { - expected = value; - break; - } - } - - Assert.Equal(expected, HttpUserAgentParser.GetRobot(userAgent)); - } - public static TheoryData CatalogUserAgents => [.. UserAgentCatalog.All]; [Theory] @@ -230,19 +190,16 @@ private static void AssertEqualsSequentialScan(PriorityTokenMatcher matche for (int start = 0; start <= tokens.Length; start++) { int expected = -1; - int expectedPosition = -1; for (int i = start; i < tokens.Length; i++) { - expectedPosition = input.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase); - if (expectedPosition >= 0) + if (input.Contains(tokens[i], StringComparison.OrdinalIgnoreCase)) { expected = i; break; } } - Assert.Equal(expected, matcher.Find(input, start, out int position)); - Assert.Equal(expected >= 0 ? expectedPosition : -1, position); + Assert.Equal(expected, matcher.Find(input, start)); } } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs index 8133a48..b0ddd8e 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMetersTelemetryTests.cs @@ -20,9 +20,7 @@ public sealed class HttpUserAgentParserMetersTelemetryTests : IDisposable [Fact] public void Meters_DoNotEmit_WhenDisabled() { - HttpUserAgentParserTelemetry.ResetForTests(); - - using MeterTestListener listener = new(MyCSharp.HttpUserAgentParser.Telemetry.HttpUserAgentParserMeters.MeterName); + using MeterTestListener listener = new(HttpUserAgentParserMeters.MeterName); const string ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; _ = HttpUserAgentInformation.Parse(ua); @@ -30,88 +28,37 @@ public void Meters_DoNotEmit_WhenDisabled() Assert.Empty(listener.InstrumentNames); } - [Fact] - public void Meters_Emit_WhenEnabled() + [Theory] + [InlineData(null, "mycsharp.http_user_agent_parser")] + [InlineData("acme.", "acme.http_user_agent_parser")] + [InlineData("", "http_user_agent_parser")] + public void Configured_Meter_Emits_Expected_Measurements(string? prefix, string meterName) { - HttpUserAgentParserTelemetry.ResetForTests(); - - using MeterTestListener listener = new("mycsharp.http_user_agent_parser"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithMeterTelemetry(); - - const string ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; - - _ = HttpUserAgentInformation.Parse(ua); + using MeterTestListener listener = new(meterName); + HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); + if (prefix is null) + { + options.WithMeterTelemetry(); + } + else + { + options.WithMeterTelemetryPrefix(prefix); + } HttpUserAgentParserCachedProvider provider = new(); - _ = provider.Parse(ua); // miss - _ = provider.Parse(ua); // hit - + _ = HttpUserAgentInformation.Parse("Firefox/12"); + _ = provider.Parse("Chrome/17"); + _ = provider.Parse("Chrome/17"); listener.RecordObservableInstruments(); - Assert.Contains("parse.requests", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("parse.duration", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.hit", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.miss", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.size", listener.InstrumentNames, StringComparer.Ordinal); - + string[] expected = ["cache.hit", "cache.miss", "cache.size", "parse.duration", "parse.duration", "parse.requests", "parse.requests"]; + Assert.Equal(expected, listener.InstrumentNames.Order(StringComparer.Ordinal), StringComparer.Ordinal); Assert.Equal("s", listener.InstrumentUnits["parse.duration"]); } - [Fact] - public void Meters_Emit_WhenEnabled_WithCustomPrefix() - { - HttpUserAgentParserTelemetry.ResetForTests(); - - const string prefix = "acme."; - using MeterTestListener listener = new("acme.http_user_agent_parser"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithMeterTelemetryPrefix(prefix); - - const string ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; - - _ = HttpUserAgentInformation.Parse(ua); - - HttpUserAgentParserCachedProvider provider = new(); - _ = provider.Parse(ua); // miss - _ = provider.Parse(ua); // hit - - listener.RecordObservableInstruments(); - - Assert.Contains("parse.requests", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("parse.duration", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.hit", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.miss", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("cache.size", listener.InstrumentNames, StringComparer.Ordinal); - } - - [Fact] - public void Meters_Emit_WhenEnabled_WithEmptyPrefix() - { - HttpUserAgentParserTelemetry.ResetForTests(); - - using MeterTestListener listener = new("http_user_agent_parser"); - - new HttpUserAgentParserDependencyInjectionOptions(new ServiceCollection()) - .WithMeterTelemetryPrefix(string.Empty); - - const string ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"; - - _ = HttpUserAgentInformation.Parse(ua); - - listener.RecordObservableInstruments(); - - Assert.Contains("parse.requests", listener.InstrumentNames, StringComparer.Ordinal); - Assert.Contains("parse.duration", listener.InstrumentNames, StringComparer.Ordinal); - } - [Fact] public void WithMeterTelemetryPrefix_Throws_WhenInvalid() { - HttpUserAgentParserTelemetry.ResetForTests(); - HttpUserAgentParserDependencyInjectionOptions options = new(new ServiceCollection()); Assert.Throws(() => options.WithMeterTelemetryPrefix("acme")); @@ -132,7 +79,7 @@ public void Repeated_Prefix_Registrations_Keep_One_Meter() options.WithMeterTelemetryPrefix("repeated."); } - Assert.Equal((1, 5), CountLiveMeters("repeated.http_user_agent_parser")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("repeated.http_user_agent_parser")); } [Fact] @@ -143,18 +90,18 @@ public void A_Replaced_Own_Meter_Is_Disposed_But_A_Meter_Of_The_Caller_Is_Not() options.WithMeterTelemetryPrefix("first."); options.WithMeterTelemetryPrefix("first."); // the meter in use: kept - Assert.Equal((1, 5), CountLiveMeters("first.http_user_agent_parser")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("first.http_user_agent_parser")); options.WithMeterTelemetryPrefix("second."); - Assert.Equal((0, 0), CountLiveMeters("first.http_user_agent_parser")); - Assert.Equal((1, 5), CountLiveMeters("second.http_user_agent_parser")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("first.http_user_agent_parser")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("second.http_user_agent_parser")); options.WithMeterTelemetry(callerMeter); - Assert.Equal((0, 0), CountLiveMeters("second.http_user_agent_parser")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("second.http_user_agent_parser")); options.WithMeterTelemetry(); // the default meter replaces the meter of the caller - Assert.Equal((1, 5), CountLiveMeters("caller.http_user_agent_parser")); - Assert.Equal((1, 5), CountLiveMeters("mycsharp.http_user_agent_parser")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("caller.http_user_agent_parser")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("mycsharp.http_user_agent_parser")); } [Fact] @@ -169,10 +116,10 @@ public void Changing_Prefixes_Keep_Only_The_Meter_In_Use() for (int i = 0; i < 31; i++) { - Assert.Equal((0, 0), CountLiveMeters($"changing{i}.http_user_agent_parser")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters($"changing{i}.http_user_agent_parser")); } - Assert.Equal((1, 5), CountLiveMeters("changing31.http_user_agent_parser")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("changing31.http_user_agent_parser")); } [Fact] @@ -195,7 +142,7 @@ public void A_Throwing_Listener_Keeps_The_Meter_In_Use() HttpUserAgentParserMeters.Enable(first); Assert.Throws(() => HttpUserAgentParserMeters.Enable(second)); Assert.Throws(() => HttpUserAgentParserMeters.EnableOwnedMeter("throwing.own")); - Assert.Equal((0, 0), CountLiveMeters("throwing.own")); // the new own meter is disposed again + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("throwing.own")); // the new own meter is disposed again using MeterTestListener recorder = new("throwing.first"); HttpUserAgentParserMeters.ParseRequest(); @@ -246,28 +193,6 @@ public async Task No_Measurement_Is_Lost_While_Meters_Of_The_Caller_Are_Switched Assert.Equal(measurements, Interlocked.Read(ref recorded)); } - /// - /// Counts the meters with instruments that a new listener sees, i.e. the meters that are not disposed. - /// - private static (int Meters, int Instruments) CountLiveMeters(string meterName) - { - HashSet meters = []; - int instruments = 0; - using MeterListener listener = new() - { - InstrumentPublished = (instrument, _) => - { - if (string.Equals(instrument.Meter.Name, meterName, StringComparison.Ordinal)) - { - meters.Add(instrument.Meter); - instruments++; - } - }, - }; - listener.Start(); - return (meters.Count, instruments); - } - [Fact] public void Core_And_MemoryCache_Cannot_Share_A_Meter() { @@ -325,7 +250,7 @@ public void Retrying_After_A_Counter_Listener_Throws_Reuses_The_Published_Instan } HttpUserAgentParserMeters.Enable(meter); - Assert.Equal((1, 6), CountLiveMeters(meter.Name)); // five parser instruments and the unrelated counter + Assert.Equal((1, 6), MeterTestListener.CountLiveMeters(meter.Name)); // five parser instruments and the unrelated counter } [Fact] @@ -345,7 +270,7 @@ public void Reentrant_Registration_Publishes_Each_Instrument_Once() }; listener.Start(); HttpUserAgentParserMeters.EnableOwnedMeter(name); - Assert.Equal((1, 5), CountLiveMeters(name)); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters(name)); } [Fact] @@ -366,15 +291,15 @@ public void A_Nested_Registration_Of_Another_Own_Meter_Leaves_No_Meter_Behind() listener.Start(); HttpUserAgentParserMeters.EnableOwnedMeter("nested.a"); // registers nested.b while its instruments are created - Assert.Equal((1, 5), CountLiveMeters("nested.a")); - Assert.Equal((0, 0), CountLiveMeters("nested.b")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("nested.a")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("nested.b")); HttpUserAgentParserMeters.Enable(callerMeter); - Assert.Equal((0, 0), CountLiveMeters("nested.a")); + Assert.Equal((0, 0), MeterTestListener.CountLiveMeters("nested.a")); } [Fact] - public void Passing_The_Own_Meter_In_Use_Keeps_It() + public void Package_Owned_Meter_Can_Be_Reused_Until_Replaced() { HttpUserAgentParserMeters.EnableOwnedMeter("own.inuse"); Meter? ownMeter = null; @@ -394,10 +319,17 @@ public void Passing_The_Own_Meter_In_Use_Keeps_It() HttpUserAgentParserMeters.Enable(ownMeter!); - Assert.Equal((1, 5), CountLiveMeters("own.inuse")); + Assert.Equal((1, 5), MeterTestListener.CountLiveMeters("own.inuse")); using MeterTestListener recorder = new("own.inuse"); HttpUserAgentParserMeters.ParseRequest(); Assert.Equal(new[] { "parse.requests" }, recorder.InstrumentNames, StringComparer.Ordinal); + + using Meter replacement = new("replacement.inuse"); + using MeterTestListener active = new(replacement.Name); + HttpUserAgentParserMeters.Enable(replacement); + Assert.Throws(() => HttpUserAgentParserMeters.Enable(ownMeter!)); + HttpUserAgentParserMeters.ParseRequest(); + Assert.Equal(new[] { "parse.requests" }, active.InstrumentNames, StringComparer.Ordinal); } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs b/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs index 62ebc65..3053257 100644 --- a/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/UserAgentCatalogTests.cs @@ -16,6 +16,22 @@ public class UserAgentCatalogTests public static TheoryData UnknownUserAgents => [.. UserAgentCatalog.Unknown]; + public static TheoryData ObservedLabels => [.. UserAgentsMeSnapshot.Cases.Select(static sample => sample.Label)]; + + [Theory] + [MemberData(nameof(ObservedLabels))] + public void Observed_User_Agent(string label) + { + ObservedUserAgent expected = UserAgentsMeSnapshot.Cases.Single(sample => string.Equals(sample.Label, label, StringComparison.Ordinal)); + HttpUserAgentInformation info = HttpUserAgentParser.Parse(expected.UserAgent); + + Assert.Equal(expected.Type, info.Type); + Assert.Equal(expected.Name, info.Name); + Assert.Equal(expected.Version, info.Version); + Assert.Equal(expected.Platform, info.Platform?.Name); + Assert.Equal(expected.Device, info.MobileDeviceType); + } + [Theory] [MemberData(nameof(BrowserLabels))] public void Browser(string label) From 1fc5d9c446494ea2139db2d5f3ca0fa5ef6301bb Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 22:23:20 +0100 Subject: [PATCH 14/41] refactor(telemetry): clarify null parameter usage --- .../HttpUserAgentParserAspNetCoreMeters.cs | 2 +- ...rAgentParserMemoryCachedProviderOptions.cs | 4 +- .../HttpUserAgentParserMemoryCacheMeters.cs | 2 +- ...serAgentParserMemoryCacheTelemetryState.cs | 2 +- .../HttpUserAgentParserCacheMeterGuard.cs | 2 +- .../Telemetry/HttpUserAgentParserMeters.cs | 2 +- .../HttpUserAgentParserTelemetryState.cs | 2 +- ...gentParserMemoryCacheTelemetryPathTests.cs | 2 +- .../UserAgentCatalog.cs | 42 ++++++------ .../UserAgentsMeSnapshot.cs | 64 +++++++++---------- .../HttpUserAgentInformationTests.cs | 4 +- ...HttpUserAgentParserMeterNameHelperTests.cs | 2 +- .../HttpUserAgentParserTelemetryPathTests.cs | 2 +- 13 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 48d3b22..1c0f7d7 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -50,7 +50,7 @@ public static string GetMeterName(string? meterPrefix) /// /// Creates the metric instruments on a meter named that this class creates and owns. /// - public static void EnableOwnedMeter(string meterName) => s_registration.Use(null, meterName); + public static void EnableOwnedMeter(string meterName) => s_registration.Use(meter: null, meterName); /// /// Records a metric indicating that a User-Agent header was present. diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs index d9afb4a..b790b5e 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs @@ -27,13 +27,13 @@ public class HttpUserAgentParserMemoryCachedProviderOptions /// Creates a new instance of /// public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions cacheOptions) - : this(cacheOptions, null) { } + : this(cacheOptions, cacheEntryOptions: null) { } /// /// Creates a new instance of /// public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheEntryOptions cacheEntryOptions) - : this(null, cacheEntryOptions) { } + : this(cacheOptions: null, cacheEntryOptions) { } /// /// Creates a new instance of diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 103d3f0..811a75b 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -47,7 +47,7 @@ public static string GetMeterName(string? meterPrefix) /// /// Creates the metric instruments on a meter named that this class creates and owns. /// - public static void EnableOwnedMeter(string meterName) => s_registration.Use(null, meterName); + public static void EnableOwnedMeter(string meterName) => s_registration.Use(meter: null, meterName); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CacheHit() => s_registration.Current?.CacheHit.Add(1); diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs index 914753e..ee00870 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs @@ -18,7 +18,7 @@ internal static class HttpUserAgentParserMemoryCacheTelemetryState /// /// Registers a provider whose entries count towards . /// - public static void Register(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Add(provider, null); + public static void Register(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Add(provider, value: null); /// /// Removes a disposed provider, whose entries no longer count. diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs index 6bafc63..3a1bef4 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs @@ -75,7 +75,7 @@ private static void Reserve(Meter meter, ConditionalWeakTable re nameof(meter)); } - reservations.AddOrUpdate(meter, null); + reservations.AddOrUpdate(meter, value: null); } } } diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index e4c955a..08cb975 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -61,7 +61,7 @@ public static string GetMeterName(string? meterPrefix) /// /// Creates the metric instruments on a meter named that this class creates and owns. /// - public static void EnableOwnedMeter(string meterName) => s_registration.Use(null, meterName); + public static void EnableOwnedMeter(string meterName) => s_registration.Use(meter: null, meterName); /// /// Emits a counter increment for a parse request. diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs index 61432e6..2817906 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs @@ -19,7 +19,7 @@ internal static class HttpUserAgentParserTelemetryState /// /// Registers a provider whose entries count towards . /// - public static void Register(HttpUserAgentParserCachedProvider provider) => s_providers.Add(provider, null); + public static void Register(HttpUserAgentParserCachedProvider provider) => s_providers.Add(provider, value: null); /// /// Gets the number of entries of all live concurrent dictionary caches. diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs index 8ac0142..7b1e6de 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/Telemetry/HttpUserAgentParserMemoryCacheTelemetryPathTests.cs @@ -73,7 +73,7 @@ public void Expired_Rule_Token_Is_Passive() HttpUserAgentParserMemoryCachedProvider.RobotRulesChangeToken expired = new(new object()); Assert.True(expired.HasChanged); Assert.False(expired.ActiveChangeCallbacks); - using IDisposable registration = expired.RegisterChangeCallback(static _ => Assert.Fail("Passive token invoked a callback."), null); + using IDisposable registration = expired.RegisterChangeCallback(static _ => Assert.Fail("Passive token invoked a callback."), state: null); } [Fact] diff --git a/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs b/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs index d72a1e5..129a86d 100644 --- a/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs +++ b/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs @@ -76,50 +76,50 @@ public static class UserAgentCatalog public static IReadOnlyList Browsers { get; } = [ // Chrome 158 (current) and 157 (previous) - new("Chrome 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Windows 10", Windows, null), - new("Chrome 157 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Windows 10", Windows, null), - new("Chrome 158 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Mac OS X", MacOS, null), - new("Chrome 157 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Mac OS X", MacOS, null), - new("Chrome 158 Linux", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Linux", Linux, null), - new("Chrome 157 Linux", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Linux", Linux, null), + new("Chrome 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Windows 10", Windows, MobileDeviceType: null), + new("Chrome 157 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Windows 10", Windows, MobileDeviceType: null), + new("Chrome 158 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Mac OS X", MacOS, MobileDeviceType: null), + new("Chrome 157 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Mac OS X", MacOS, MobileDeviceType: null), + new("Chrome 158 Linux", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36", "Chrome", "158.0.0.0", "Linux", Linux, MobileDeviceType: null), + new("Chrome 157 Linux", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36", "Chrome", "157.0.0.0", "Linux", Linux, MobileDeviceType: null), new("Chrome 158 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Mobile Safari/537.36", "Chrome", "158.0.0.0", "Android", Android, "Android"), new("Chrome 157 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36", "Chrome", "157.0.0.0", "Android", Android, "Android"), new("Chrome 158 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/158.0.8127.35 Mobile/15E148 Safari/604.1", "Chrome", "158.0.8127.35", "iOS", IOS, "Apple iPhone"), new("Chrome 157 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 27_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/157.0.8103.37 Mobile/15E148 Safari/604.1", "Chrome", "157.0.8103.37", "iOS", IOS, "Apple iPhone"), // Safari 27.2 (current) and 26.6 (previous) - new("Safari 27 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Safari/605.1.15", "Safari", "27.2", "Mac OS X", MacOS, null), - new("Safari 26 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Safari/605.1.15", "Safari", "26.6", "Mac OS X", MacOS, null), + new("Safari 27 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Safari/605.1.15", "Safari", "27.2", "Mac OS X", MacOS, MobileDeviceType: null), + new("Safari 26 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Safari/605.1.15", "Safari", "26.6", "Mac OS X", MacOS, MobileDeviceType: null), new("Safari 27 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Mobile/15E148 Safari/604.1", "Safari", "27.2", "iOS", IOS, "Apple iPhone"), new("Safari 26 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Mobile/15E148 Safari/604.1", "Safari", "26.6", "iOS", IOS, "Apple iPhone"), new("Safari 27 iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Mobile/15E148 Safari/604.1", "Safari", "27.2", "iOS", IOS, "Apple iPad"), new("Safari 26 iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Mobile/15E148 Safari/604.1", "Safari", "26.6", "iOS", IOS, "Apple iPad"), // Edge 158 (current desktop), 156 (previous desktop, 157 was skipped), 157 / 156 (mobile) - new("Edge 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 Edg/158.0.0.0", "Edge", "158.0.0.0", "Windows 10", Windows, null), - new("Edge 156 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36 Edg/156.0.0.0", "Edge", "156.0.0.0", "Windows 10", Windows, null), - new("Edge 158 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 Edg/158.0.0.0", "Edge", "158.0.0.0", "Mac OS X", MacOS, null), - new("Edge 156 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36 Edg/156.0.0.0", "Edge", "156.0.0.0", "Mac OS X", MacOS, null), + new("Edge 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 Edg/158.0.0.0", "Edge", "158.0.0.0", "Windows 10", Windows, MobileDeviceType: null), + new("Edge 156 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36 Edg/156.0.0.0", "Edge", "156.0.0.0", "Windows 10", Windows, MobileDeviceType: null), + new("Edge 158 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36 Edg/158.0.0.0", "Edge", "158.0.0.0", "Mac OS X", MacOS, MobileDeviceType: null), + new("Edge 156 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36 Edg/156.0.0.0", "Edge", "156.0.0.0", "Mac OS X", MacOS, MobileDeviceType: null), new("Edge 157 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36 EdgA/157.0.0.0", "Edge", "157.0.0.0", "Android", Android, "Android"), new("Edge 156 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Mobile Safari/537.36 EdgA/156.0.0.0", "Edge", "156.0.0.0", "Android", Android, "Android"), new("Edge 157 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 27_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/157.0.4341.57 Version/27.0 Mobile/15E148 Safari/604.1", "Edge", "157.0.4341.57", "iOS", IOS, "Apple iPhone"), new("Edge 156 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 27_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/156.0.4314.56 Version/27.0 Mobile/15E148 Safari/604.1", "Edge", "156.0.4314.56", "iOS", IOS, "Apple iPhone"), // Firefox 160 (current) and 159 (previous) - new("Firefox 160 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Windows 10", Windows, null), - new("Firefox 159 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Windows 10", Windows, null), - new("Firefox 160 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Mac OS X", MacOS, null), - new("Firefox 159 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Mac OS X", MacOS, null), - new("Firefox 160 Linux", "Mozilla/5.0 (X11; Linux x86_64; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Linux", Linux, null), - new("Firefox 159 Linux", "Mozilla/5.0 (X11; Linux x86_64; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Linux", Linux, null), + new("Firefox 160 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Windows 10", Windows, MobileDeviceType: null), + new("Firefox 159 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Windows 10", Windows, MobileDeviceType: null), + new("Firefox 160 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Mac OS X", MacOS, MobileDeviceType: null), + new("Firefox 159 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Mac OS X", MacOS, MobileDeviceType: null), + new("Firefox 160 Linux", "Mozilla/5.0 (X11; Linux x86_64; rv:160.0) Gecko/20100101 Firefox/160.0", "Firefox", "160.0", "Linux", Linux, MobileDeviceType: null), + new("Firefox 159 Linux", "Mozilla/5.0 (X11; Linux x86_64; rv:159.0) Gecko/20100101 Firefox/159.0", "Firefox", "159.0", "Linux", Linux, MobileDeviceType: null), new("Firefox 160 Android", "Mozilla/5.0 (Android 17; Mobile; rv:160.0) Gecko/160.0 Firefox/160.0", "Firefox", "160.0", "Android", Android, "Android"), new("Firefox 159 Android", "Mozilla/5.0 (Android 17; Mobile; rv:159.0) Gecko/159.0 Firefox/159.0", "Firefox", "159.0", "Android", Android, "Android"), new("Firefox 160 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/160.0 Mobile/15E148 Safari/604.1", "Firefox", "160.0", "iOS", IOS, "Apple iPhone"), new("Firefox 159 iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/159.0 Mobile/15E148 Safari/604.1", "Firefox", "159.0", "iOS", IOS, "Apple iPhone"), // Opera 140 / 139 (desktop, Opera GX sends the same user agent) and Opera for Android 101 - new("Opera 140 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/140.0.0.0", "Opera", "140.0.0.0", "Windows 10", Windows, null), - new("Opera 139 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36 OPR/139.0.0.0", "Opera", "139.0.0.0", "Windows 10", Windows, null), + new("Opera 140 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/140.0.0.0", "Opera", "140.0.0.0", "Windows 10", Windows, MobileDeviceType: null), + new("Opera 139 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36 OPR/139.0.0.0", "Opera", "139.0.0.0", "Windows 10", Windows, MobileDeviceType: null), new("Opera 101 Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Mobile Safari/537.36 OPR/101.0.0.0", "Opera", "101.0.0.0", "Android", Android, "Android"), // Samsung Internet 30 (phone and tablet / DeX) @@ -127,7 +127,7 @@ public static class UserAgentCatalog new("Samsung Internet 30 DeX", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/30.0 Chrome/143.0.0.0 Safari/537.36", "Samsung Internet", "30.0", "Linux", Linux, "Samsung"), // Yandex Browser 26.11 - new("Yandex Browser 26 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 YaBrowser/26.11.0.2030 Yowser/2.5 Safari/537.36", "Yandex Browser", "26.11.0.2030", "Windows 10", Windows, null), + new("Yandex Browser 26 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 YaBrowser/26.11.0.2030 Yowser/2.5 Safari/537.36", "Yandex Browser", "26.11.0.2030", "Windows 10", Windows, MobileDeviceType: null), // UC Browser 15 (UCMobile token) and the classic UCBrowser token new("UC Browser 15 Android", "Mozilla/5.0 (Linux; Android 16; en-US; SM-S918B Build/BP2A.250605.031.A3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.80 UCMobile/15.0.7.1383 Mobile Safari/537.36", "UC Browser", "15.0.7.1383", "Android", Android, "Android"), diff --git a/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs b/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs index 40fc087..01b27f9 100644 --- a/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs +++ b/tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs @@ -13,35 +13,35 @@ public static class UserAgentsMeSnapshot [ // Desktop browsers and incomplete headers new("Chrome 152 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36", - HttpUserAgentType.Browser, "Chrome", "152.0.0.0", "Windows 10", null), + HttpUserAgentType.Browser, "Chrome", "152.0.0.0", "Windows 10", Device: null), new("Chrome 131 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", - HttpUserAgentType.Browser, "Chrome", "131.0.0.0", "Mac OS X", null), + HttpUserAgentType.Browser, "Chrome", "131.0.0.0", "Mac OS X", Device: null), new("Safari 17 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15", - HttpUserAgentType.Browser, "Safari", "17.6", "Mac OS X", null), + HttpUserAgentType.Browser, "Safari", "17.6", "Mac OS X", Device: null), new("Chrome 39 WOW64", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95", - HttpUserAgentType.Browser, "Chrome", "39.0.2171.95", "Windows 7", null), + HttpUserAgentType.Browser, "Chrome", "39.0.2171.95", "Windows 7", Device: null), new("Opera 9 Windows XP", "Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50", - HttpUserAgentType.Browser, "Opera", "9.50", "Windows XP", null), + HttpUserAgentType.Browser, "Opera", "9.50", "Windows XP", Device: null), new("Firefox 34 Windows 7", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0", - HttpUserAgentType.Browser, "Firefox", "34.0", "Windows 7", null), + HttpUserAgentType.Browser, "Firefox", "34.0", "Windows 7", Device: null), new("Edge 157 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Edg/157.0.0.0", - HttpUserAgentType.Browser, "Edge", "157.0.0.0", "Windows 10", null), + HttpUserAgentType.Browser, "Edge", "157.0.0.0", "Windows 10", Device: null), new("WebKit only Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - HttpUserAgentType.Unknown, null, null, "Windows 10", null), + HttpUserAgentType.Unknown, Name: null, Version: null, "Windows 10", Device: null), new("Edge 158 Windows", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Edg/158.0.4370.33", - HttpUserAgentType.Browser, "Edge", "158.0.4370.33", "Windows 10", null), + HttpUserAgentType.Browser, "Edge", "158.0.4370.33", "Windows 10", Device: null), new("Vivaldi WOW64", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Vivaldi/8.1.4087.61", - HttpUserAgentType.Browser, "Vivaldi", "8.1.4087.61", "Windows 10", null), + HttpUserAgentType.Browser, "Vivaldi", "8.1.4087.61", "Windows 10", Device: null), new("Opera WOW64", "Mozilla/5.0 (Windows NT 10.0; WOW64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 OPR/141.0.0.0", - HttpUserAgentType.Browser, "Opera", "141.0.0.0", "Windows 10", null), + HttpUserAgentType.Browser, "Opera", "141.0.0.0", "Windows 10", Device: null), new("Safari 27 macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_8_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Safari/605.1.15", - HttpUserAgentType.Browser, "Safari", "27.0", "Mac OS X", null), + HttpUserAgentType.Browser, "Safari", "27.0", "Mac OS X", Device: null), new("Yandex macOS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 YaBrowser/26.11.0.2030 Yowser/2.5 Safari/537.36", - HttpUserAgentType.Browser, "Yandex Browser", "26.11.0.2030", "Mac OS X", null), + HttpUserAgentType.Browser, "Yandex Browser", "26.11.0.2030", "Mac OS X", Device: null), new("Firefox 160 Linux i686", "Mozilla/5.0 (X11; Linux i686; rv:160.0) Gecko/20100101 Firefox/160.0", - HttpUserAgentType.Browser, "Firefox", "160.0", "Linux", null), + HttpUserAgentType.Browser, "Firefox", "160.0", "Linux", Device: null), new("Firefox 153 Linux x64", "Mozilla/5.0 (Linux x86_64; rv:153.0) Gecko/20100101 Firefox/153.0", - HttpUserAgentType.Browser, "Firefox", "153.0", "Linux", null), + HttpUserAgentType.Browser, "Firefox", "153.0", "Linux", Device: null), // Phones and embedded browsers new("Safari 13 iPhone", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1", @@ -103,40 +103,40 @@ public static class UserAgentsMeSnapshot new("Yandex iPad", "Mozilla/5.0 (iPad; CPU OS 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 YaBrowser/26.11.2.1177 Mobile/15E148 Safari/605.1", HttpUserAgentType.Browser, "Yandex Browser", "26.11.2.1177", "iOS", "Apple iPad"), new("Versionless iPad", "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Safari", - HttpUserAgentType.Unknown, null, null, "iOS", "Apple iPad"), + HttpUserAgentType.Unknown, Name: null, Version: null, "iOS", "Apple iPad"), new("Dalvik Android", "Dalvik/2.1.0 (Linux; U; Android 14; 100146663 Build/UP1A.231005.007)", - HttpUserAgentType.Unknown, null, null, "Android", "Android"), + HttpUserAgentType.Unknown, Name: null, Version: null, "Android", "Android"), // HTTP clients and crawlers new("Python requests", "python-requests/2.34.2", - HttpUserAgentType.Unknown, null, null, null, null), + HttpUserAgentType.Unknown, Name: null, Version: null, Platform: null, Device: null), new("Python aiohttp", "Python/3.14 aiohttp/3.13.2", - HttpUserAgentType.Unknown, null, null, null, null), + HttpUserAgentType.Unknown, Name: null, Version: null, Platform: null, Device: null), new("curl", "curl/8.23.0", - HttpUserAgentType.Unknown, null, null, null, null), + HttpUserAgentType.Unknown, Name: null, Version: null, Platform: null, Device: null), new("Guzzle", "GuzzleHttp/7", - HttpUserAgentType.Unknown, null, null, null, null), + HttpUserAgentType.Unknown, Name: null, Version: null, Platform: null, Device: null), new("axios", "axios/1.20.0", - HttpUserAgentType.Unknown, null, null, null, null), + HttpUserAgentType.Unknown, Name: null, Version: null, Platform: null, Device: null), new("QQDownload MSIE", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)", - HttpUserAgentType.Browser, "Internet Explorer", "6.0", "Windows XP", null), + HttpUserAgentType.Browser, "Internet Explorer", "6.0", "Windows XP", Device: null), new("Bravebot", "Mozilla/5.0 (compatible; Bravebot/1.0; +https://brave.com/search/)", - HttpUserAgentType.Robot, "Bravebot", null, null, null), + HttpUserAgentType.Robot, "Bravebot", Version: null, Platform: null, Device: null), new("KimiBot", "Mozilla/5.0 (compatible; KimiBot/1.0; +https://kimi.ai/)", - HttpUserAgentType.Robot, "KimiBot", null, null, null), + HttpUserAgentType.Robot, "KimiBot", Version: null, Platform: null, Device: null), new("meta-externalfetcher", "Mozilla/5.0 (compatible; Meta-ExternalFetcher/1.0; +https://developers.facebook.com/docs/sharing/webmasters/crawler)", - HttpUserAgentType.Robot, "meta-externalfetcher", null, null, null), + HttpUserAgentType.Robot, "meta-externalfetcher", Version: null, Platform: null, Device: null), new("DeepSeekBot", "Mozilla/5.0 (compatible; DeepSeekBot/1.0; +https://www.deepseek.com/)", - HttpUserAgentType.Robot, "DeepSeekBot", null, null, null), + HttpUserAgentType.Robot, "DeepSeekBot", Version: null, Platform: null, Device: null), new("ChatGLM-Spider", "Mozilla/5.0 (compatible; ChatGLM-Spider/1.0; +https://zhipuai.cn/)", - HttpUserAgentType.Robot, "ChatGLM-Spider", null, null, null), + HttpUserAgentType.Robot, "ChatGLM-Spider", Version: null, Platform: null, Device: null), new("OAI-AdsBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-AdsBot/1.0; +https://openai.com/adsbot", - HttpUserAgentType.Robot, "OAI-AdsBot", null, null, null), + HttpUserAgentType.Robot, "OAI-AdsBot", Version: null, Platform: null, Device: null), new("DuckAssistBot", "DuckAssistBot/1.1 (https://duckduckgo.com/duckassistbot)", - HttpUserAgentType.Robot, "DuckAssistBot", null, null, null), + HttpUserAgentType.Robot, "DuckAssistBot", Version: null, Platform: null, Device: null), new("OAI-SearchBot", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-SearchBot/1.0; +https://openai.com/searchbot", - HttpUserAgentType.Robot, "OAI-SearchBot", null, null, null), + HttpUserAgentType.Robot, "OAI-SearchBot", Version: null, Platform: null, Device: null), new("meta-externalagent", "Mozilla/5.0 (compatible; Meta-ExternalAgent/1.0; +https://developers.facebook.com/docs/sharing/webmasters/crawler)", - HttpUserAgentType.Robot, "meta-externalagent", null, null, null), + HttpUserAgentType.Robot, "meta-externalagent", Version: null, Platform: null, Device: null), ]; } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs index 16437bc..6abd216 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs @@ -93,8 +93,8 @@ public void Not_Equals_When_Any_Property_Differs(int property) 1 => HttpUserAgentInformation.CreateForUnknown("ua", platform, "Android"), 2 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Edge", "1.0", "Android"), 3 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Chrome", "2.0", "Android"), - 4 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Chrome", "1.0", null), - 5 => HttpUserAgentInformation.CreateForBrowser("ua", null, "Chrome", "1.0", "Android"), + 4 => HttpUserAgentInformation.CreateForBrowser("ua", platform, "Chrome", "1.0", deviceName: null), + 5 => HttpUserAgentInformation.CreateForBrowser("ua", platform: null, "Chrome", "1.0", "Android"), _ => HttpUserAgentInformation.CreateForBrowser("ua", new HttpUserAgentPlatformInformation(TextRegex(), "Linux", HttpUserAgentPlatformType.Linux), "Chrome", "1.0", "Android"), }; diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMeterNameHelperTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMeterNameHelperTests.cs index 7426f97..af654ce 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMeterNameHelperTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserMeterNameHelperTests.cs @@ -12,7 +12,7 @@ public class HttpUserAgentParserMeterNameHelperTests [Fact] public void GetMeterName_NullPrefix_ReturnsDefaultPrefixedName() { - string result = HttpUserAgentParserMeterNameHelper.GetMeterName(null, Suffix); + string result = HttpUserAgentParserMeterNameHelper.GetMeterName(meterPrefix: null, Suffix); Assert.Equal("mycsharp." + Suffix, result); } diff --git a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs index ba29372..d0a634e 100644 --- a/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Telemetry/HttpUserAgentParserTelemetryPathTests.cs @@ -221,7 +221,7 @@ public async Task Concurrent_Registration_Returns_After_All_Instruments_Exist() Assert.NotNull(captured); Task first = Task.Run(() => HttpUserAgentParserTelemetry.EnableMeters(meter), cancellationToken); Assert.True(creating.Wait(TimeSpan.FromSeconds(10), cancellationToken)); - Task second = Task.Run(() => ExecutionContext.Run(captured, _ => HttpUserAgentParserTelemetry.EnableMeters(meter), null), cancellationToken); + Task second = Task.Run(() => ExecutionContext.Run(captured, _ => HttpUserAgentParserTelemetry.EnableMeters(meter), state: null), cancellationToken); // The second registration must not return while the instruments of the first one are incomplete. Assert.NotSame(second, await Task.WhenAny(second, Task.Delay(200, cancellationToken))); From f5cc9e01278c2f47aa2f43e750c8777e9bacc515 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 22:33:14 +0100 Subject: [PATCH 15/41] perf: benchmark the captured user-agent corpus and document results --- README.md | 71 +++++----- docs/benchmarks/2026-11-23.md | 123 ++++++++++++++++++ .../RealWorldUserAgentBenchmarks.cs | 6 +- src/HttpUserAgentParser/readme.md | 2 +- 4 files changed, 163 insertions(+), 39 deletions(-) create mode 100644 docs/benchmarks/2026-11-23.md diff --git a/README.md b/README.md index 1c57d4a..c24c47e 100644 --- a/README.md +++ b/README.md @@ -135,14 +135,14 @@ If you only need the raw header value, use `httpContext.GetUserAgentString()`. `HttpUserAgentParser.Parse` checks, in this order: -1. **Robots**: search engine crawlers (e.g. Googlebot, Bingbot, Applebot, DuckDuckBot, YandexBot), SEO crawlers (e.g. AhrefsBot, SemrushBot, Screaming Frog) and AI crawlers and AI user agents (e.g. GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, PerplexityBot, Amazonbot, Bytespider, CCBot) +1. **Robots**: search engine crawlers (e.g. Googlebot, Bingbot, Applebot, Bravebot, DuckDuckBot, YandexBot), SEO crawlers (e.g. AhrefsBot, SemrushBot, Screaming Frog) and AI crawlers and AI user agents (e.g. GPTBot, ChatGPT-User, OAI-SearchBot, OAI-AdsBot, ClaudeBot, PerplexityBot, KimiBot, DeepSeekBot, ChatGLM-Spider, Amazonbot, Bytespider, CCBot) 2. **Platform**: Windows, macOS, iOS, Android, ChromeOS, Linux and others 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) 4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Amazon Silk, Yandex Browser, UC Browser and others In every list the first matching entry wins. Browser and version tokens only count at the start of a token: at the beginning of the user agent or after a space, tab, `+`, `;`, `(`, `)` or `,`, so `Knowledge/1.0` is no Edge and `VendorVersion/1.0` no version token. The version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next of these characters; Opera and Internet Explorer also accept `Opera 9.50` and `MSIE 6.0`; their separate version tokens (`Version/`, `rv:`) only count after the browser token. If a token has no version, later occurrences of the token are checked, then the next rule. `+` stands for a space as in URL-encoded logs (IIS); decode other encodings such as `%20` before parsing, e.g. with `WebUtility.UrlDecode`. -Brave and Vivaldi send the same user agent as Chrome and are reported as Chrome, as is Headless Chrome; iPadOS sends the macOS user agent by default. +A header with a Vivaldi product token identifies Vivaldi. Brave and Vivaldi can also send a Chrome-only header, which parses as Chrome. Headless Chrome also parses as Chrome. iPadOS sends the macOS user agent by default. ### `HttpUserAgentStatics` and regular expressions @@ -443,53 +443,52 @@ Notes: ## Benchmark -Run the parser benchmarks with the .NET 11 runtime (use `-f net8.0`, `net9.0` or `net10.0` for the other runtimes). +The parser benchmark runs without caching. The 68 individual cases include eight reference headers and 60 headers captured from November 15–22, 2026. Each captured header has a regression test for client type, name, version, platform and mobile device. All inputs are stored locally. [Captured headers](tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs) · [Snapshot source](https://useragents.me/api) + +The `Snapshot` workload contains 43 browsers, nine crawlers and eight unclassified clients. The separate catalog contains 44 browsers, 48 crawlers and four unclassified clients. Each mixed benchmark parses 5,280 headers per invocation, repeating its corpus in order. Every header in a workload has equal weight. [Catalog](tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs) + +### Parser performance on .NET 11 + +Run the 68 individual and four mixed benchmarks with the settings used for the November 23, 2026 measurements. ```shell -# individual cases, including the useragents.me snapshot -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks*" -# mixed real-world workload (closest to production) -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*MixedWorkloadBenchmarks*" -# every browser (current and previous browser version) and every crawler of the test catalog -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*BrowserUserAgentBenchmarks*" "*RobotUserAgentBenchmarks*" +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks.Parse" "*MixedWorkloadBenchmarks.Parse" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 ``` -The individual benchmarks include a fixed sample of desktop, phone, tablet, crawler and HTTP client headers from November 15–22, 2026. The parser tests validate each captured header in `UserAgentsMeSnapshot.cs`. The browser, crawler and mixed workload benchmarks use the separate `UserAgentCatalog.cs` corpus. Both datasets run offline. [Snapshot source](https://useragents.me/api) - -### Parser performance +BenchmarkDotNet 0.16.0-preview.2, .NET 11.0.0 x64, Windows 10, AMD Ryzen 9 9950X. Each case ran in a separate process with three warm-ups and five measurement iterations targeting 250 ms each. Times and managed allocations are per parsed header. -BenchmarkDotNet 0.16.0-preview.2 (default job: every benchmark case runs in its own process), x64, Windows 10 and an AMD Ryzen 9 9950X, without caching. For a user agent without leading or trailing white space, the only allocation is the version string; otherwise `Parse` also allocates the trimmed string. +| Workload | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| Catalog browsers (44) | 310.0 ns | 0.84 ns | 38 B | +| Catalog crawlers (48) | 171.5 ns | 2.43 ns | 0 B | +| Full catalog (96) | 247.9 ns | 0.58 ns | 18 B | +| API snapshot (60) | 311.0 ns | 0.37 ns | 29 B | -Mixed workload: the catalog user agents parsed in a loop, mean time per user agent. +| Selected individual headers | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| Googlebot | 22.13 ns | 0.245 ns | 0 B | +| Bravebot | 125.67 ns | 0.470 ns | 0 B | +| OAI-AdsBot | 261.96 ns | 1.682 ns | 0 B | +| IIS-encoded Screaming Frog | 251.06 ns | 3.469 ns | 0 B | +| Amazon Silk on Fire tablet | 277.44 ns | 3.096 ns | 40 B | -| Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | .NET 11.0.0 | Allocated | -| --- | ---: | ---: | ---: | ---: | ---: | -| 44 browser user agents | 754.0 ns | 331.8 ns | 291.7 ns | 262.5 ns | 38 B | -| 48 crawler user agents | 355.5 ns | 159.0 ns | 227.4 ns | 151.5 ns | 0 B | -| All 96 user agents | 609.4 ns | 261.0 ns | 262.3 ns | 216.2 ns | 18 B | +In a second run against the PR base (`be56445`), the snapshot mean fell from 438.2 to 321.8 ns per header, and the crawler catalog from 389.0 to 174.6 ns. The Googlebot header took 22.49 ns on the reviewed parser and 8.34 ns on the base. Both used 0 B per parse. [All individual results and the direct comparison](docs/benchmarks/2026-11-23.md) -.NET 8 has no `SearchValues`; the parser checks the tokens one by one there. +### Earlier measurements on .NET 8–10 -Single user agents on .NET 11: +The earlier default-job run used the catalog and repeated its entries to fill batches of 1,000. The table reports mean time per parsed header. The .NET 8 implementation scans tokens sequentially. The .NET 9 and later implementations use `SearchValues`. -| User agent | Mean | Allocated | -| --- | ---: | ---: | -| Chrome on Windows | 248.6 ns | 40 B | -| Firefox on Linux | 373.1 ns | 32 B | -| Chrome on Android | 267.5 ns | 40 B | -| Safari on iPhone | 289.2 ns | 32 B | -| Applebot | 195.5 ns | 0 B | -| Googlebot | 6.98 ns | 0 B | -| Unknown client | 378.2 ns | 0 B | +| Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | +| --- | ---: | ---: | ---: | +| 44 browsers | 754.0 ns | 331.8 ns | 291.7 ns | +| 48 crawlers | 355.5 ns | 159.0 ns | 227.4 ns | +| All 96 catalog headers | 609.4 ns | 261.0 ns | 262.3 ns | -Startup in a new .NET 11 process (median of 7 runs): +### Earlier .NET 11 startup measurements -| | Time | Allocated | -| --- | ---: | ---: | -| First `Parse` call | 9.1 ms | 122 KB | -| First use of all `HttpUserAgentStatics` regular expressions (43 platforms, 35 browsers) | 15.7 ms | 120 KB | +An earlier revision used 43 platform and 35 browser regular expressions. The median across seven fresh processes was 9.1 ms and 122 KB for the first parse, and 15.7 ms and 120 KB for first use of all regular expressions. The current set adds Amazon Silk as the 36th browser expression. -### Library comparison on .NET 11 +### Earlier library comparison on .NET 11 ```shell dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*LibraryComparison*" diff --git a/docs/benchmarks/2026-11-23.md b/docs/benchmarks/2026-11-23.md new file mode 100644 index 0000000..6a825c3 --- /dev/null +++ b/docs/benchmarks/2026-11-23.md @@ -0,0 +1,123 @@ +# Parser benchmarks on November 23, 2026 + +The Release build ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100, .NET runtime 11.0.0 and BenchmarkDotNet 0.16.0-preview.2. Each case used one process, three warm-up iterations and five measurement iterations targeting 250 ms. The tables report mean elapsed time, standard deviation and managed bytes allocated per uncached parse. [Reproduction command](../../README.md#parser-performance-on-net-11) + +## Mixed workloads + +Each invocation processes 5,280 headers in corpus order. Each distinct header contributes equally within its workload. + +| Workload | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| Catalog browsers (44) | 310.0 ns | 0.84 ns | 38 B | +| Catalog crawlers (48) | 171.5 ns | 2.43 ns | 0 B | +| Full catalog (96) | 247.9 ns | 0.58 ns | 18 B | +| API snapshot (60) | 311.0 ns | 0.37 ns | 29 B | + +## Comparison with the PR base + +A second run used the same harness, inputs and job settings for the main branch at `be56445` and the reviewed parser at `1fc5d9c`. Each implementation ran in its own benchmark process. Classification differences contribute to the times, especially when a newly recognized crawler returns early. + +| Workload | Main mean | PR mean | Main bytes/parse | PR bytes/parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers | 345.7 ns | 295.8 ns | 38 B | 38 B | +| Catalog crawlers | 389.0 ns | 174.6 ns | 2 B | 0 B | +| Full catalog | 385.8 ns | 256.4 ns | 19 B | 18 B | +| API snapshot | 438.2 ns | 321.8 ns | 29 B | 29 B | +| Googlebot | 8.336 ns | 22.486 ns | 0 B | 0 B | +| OAI-AdsBot | 797.867 ns | 265.783 ns | 0 B | 0 B | + +Googlebot took 2.70 times as long in the reviewed parser, adding 14.15 ns per parse. OAI-AdsBot took about one third of the base time. All four mixed workloads were faster on the reviewed parser. + +To reproduce the comparison, build the parser at `be56445` for `net11.0` in Release with `-p:AssemblyName=MyCSharp.HttpUserAgentParser.Baseline`. Set the environment variable `BenchmarkBaselineAssembly` to that DLL’s absolute path, then use the same benchmark command with the filters `"*MixedWorkloadBenchmarks.Parse*" "*HttpUserAgentParserBenchmarks.Parse*Googlebot*" "*HttpUserAgentParserBenchmarks.Parse*OAI-AdsBot*"`. + +## Individual headers + +The eight reference headers and 60 captured headers use the same parser entry point. The 60 expected results were checked on .NET 8, 9, 10 and 11. [Reference headers](../../perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs) · [Captured headers and expected results](../../tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs) + +### Reference headers + +| Header | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| Chrome Windows | 265.67 ns | 4.752 ns | 40 B | +| Firefox Linux | 392.05 ns | 7.098 ns | 32 B | +| Chrome Android | 279.29 ns | 0.544 ns | 40 B | +| Safari iPhone | 467.86 ns | 1.010 ns | 32 B | +| Googlebot | 22.13 ns | 0.245 ns | 0 B | +| Applebot | 217.19 ns | 0.520 ns | 0 B | +| Unknown | 364.41 ns | 2.060 ns | 0 B | +| IIS encoded crawler | 251.06 ns | 3.469 ns | 0 B | + +### Captured browser headers + +| Header | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| Chrome 152 Windows | 277.72 ns | 2.101 ns | 40 B | +| Chrome 131 macOS | 316.70 ns | 1.150 ns | 40 B | +| Safari 17 macOS | 475.56 ns | 31.164 ns | 32 B | +| Chrome 39 WOW64 | 269.60 ns | 0.885 ns | 48 B | +| Opera 9 Windows XP | 341.01 ns | 1.120 ns | 32 B | +| Firefox 34 Windows 7 | 263.98 ns | 2.321 ns | 32 B | +| Edge 157 Windows | 188.33 ns | 0.266 ns | 40 B | +| Edge 158 Windows | 230.10 ns | 0.438 ns | 48 B | +| Vivaldi WOW64 | 223.87 ns | 2.687 ns | 48 B | +| Opera WOW64 | 174.48 ns | 1.579 ns | 40 B | +| Safari 27 macOS | 438.25 ns | 0.526 ns | 32 B | +| Yandex macOS | 409.02 ns | 4.201 ns | 48 B | +| Firefox 160 Linux i686 | 280.14 ns | 1.468 ns | 32 B | +| Firefox 153 Linux x64 | 247.36 ns | 1.961 ns | 32 B | +| Safari 13 iPhone | 475.47 ns | 4.481 ns | 40 B | +| Safari 26 iPhone | 443.38 ns | 7.091 ns | 40 B | +| Reduced Chrome Android | 267.50 ns | 1.435 ns | 40 B | +| Misspelled WebView | 368.67 ns | 4.298 ns | 48 B | +| Edge Galaxy Core Max | 267.73 ns | 0.415 ns | 48 B | +| Chrome Galaxy J7 | 363.63 ns | 3.093 ns | 48 B | +| Chrome iPod | 314.98 ns | 2.999 ns | 48 B | +| Edge iPhone | 272.04 ns | 4.347 ns | 48 B | +| Firefox iPod touch | 310.66 ns | 3.370 ns | 32 B | +| Safari iPod touch | 443.02 ns | 1.021 ns | 32 B | +| Yandex iPhone | 290.20 ns | 1.554 ns | 48 B | +| Edge Pixel 3 XL | 263.41 ns | 3.837 ns | 48 B | +| Firefox LG | 316.74 ns | 2.946 ns | 32 B | +| Opera Android | 260.76 ns | 2.495 ns | 56 B | +| Yandex Android ARM64 | 303.65 ns | 1.915 ns | 48 B | +| Firefox Android tablet | 251.76 ns | 3.124 ns | 32 B | +| Reduced Chrome tablet | 291.63 ns | 1.963 ns | 40 B | +| Silk Fire tablet | 277.44 ns | 3.096 ns | 40 B | +| Chrome Android tablet 3G | 306.68 ns | 1.554 ns | 56 B | +| Chrome Galaxy Tab | 298.69 ns | 2.051 ns | 48 B | +| Safari 7 iPad | 412.07 ns | 4.415 ns | 32 B | +| Safari 9 iPad | 392.22 ns | 3.772 ns | 32 B | +| Firefox ESR tablet | 273.91 ns | 3.052 ns | 32 B | +| Safari comma version | 418.32 ns | 4.466 ns | 32 B | +| Chrome 76 iPad | 280.52 ns | 1.428 ns | 48 B | +| Chrome iPad | 307.55 ns | 0.852 ns | 48 B | +| Firefox iPad | 288.82 ns | 1.070 ns | 32 B | +| Yandex iPad | 276.59 ns | 1.975 ns | 48 B | +| QQDownload MSIE | 423.20 ns | 1.499 ns | 32 B | + +### Captured crawler headers + +| Header | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| Bravebot | 125.67 ns | 0.470 ns | 0 B | +| KimiBot | 100.29 ns | 9.639 ns | 0 B | +| meta-externalfetcher | 242.34 ns | 1.354 ns | 0 B | +| DeepSeekBot | 178.20 ns | 0.288 ns | 0 B | +| ChatGLM-Spider | 155.25 ns | 3.353 ns | 0 B | +| OAI-AdsBot | 261.96 ns | 1.682 ns | 0 B | +| DuckAssistBot | 173.69 ns | 0.366 ns | 0 B | +| OAI-SearchBot | 94.05 ns | 0.175 ns | 0 B | +| meta-externalagent | 74.17 ns | 0.580 ns | 0 B | + +### Captured unclassified headers + +| Header | Mean | Std. dev. | Allocated | +| --- | ---: | ---: | ---: | +| WebKit only Windows | 244.13 ns | 1.402 ns | 0 B | +| Versionless iPad | 338.68 ns | 1.078 ns | 0 B | +| Dalvik Android | 346.96 ns | 0.732 ns | 0 B | +| Python requests | 318.92 ns | 1.476 ns | 0 B | +| Python aiohttp | 298.12 ns | 0.466 ns | 0 B | +| curl | 388.36 ns | 0.257 ns | 0 B | +| Guzzle | 414.66 ns | 6.366 ns | 0 B | +| axios | 405.55 ns | 3.166 ns | 0 B | diff --git a/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs index 0e5cd1e..c754ee0 100644 --- a/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs +++ b/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs @@ -60,11 +60,12 @@ public class RobotUserAgentBenchmarks [MemoryDiagnoser] public class MixedWorkloadBenchmarks { - private const int OperationsPerInvoke = 1000; + // A whole number of passes over the 44, 48, 96 and 60 entry workloads. + private const int OperationsPerInvoke = 5280; private string[] _userAgents; - [Params("Browsers", "Robots", "All")] + [Params("Browsers", "Robots", "All", "Snapshot")] public string Workload { get; set; } [GlobalSetup] @@ -74,6 +75,7 @@ public void Setup() { "Browsers" => [.. UserAgentCatalog.Browsers.Select(static ua => ua.UserAgent)], "Robots" => [.. UserAgentCatalog.Robots.Select(static ua => ua.UserAgent)], + "Snapshot" => [.. UserAgentsMeSnapshot.Cases.Select(static ua => ua.UserAgent)], _ => UserAgentCatalog.All, }; diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index 60a0b81..dcfc239 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -5,7 +5,7 @@ Fast HTTP User-Agent parsing for .NET. - Allocation-free detection with vectorized searches (`SearchValues` on .NET 9+); for a user agent without surrounding white space only the version string is allocated; no regular expressions in the parser - Trimming and Native AOT compatible -- Detects the most used browsers and current search engine, SEO and AI crawlers +- Detects browsers including Amazon Silk, and search, SEO and AI crawlers including Bravebot, Screaming Frog SEO Spider, KimiBot, DeepSeekBot, ChatGLM-Spider and OAI-AdsBot Repository: https://github.com/mycsharp/HttpUserAgentParser From 56918338e5dc42cd4a359d19a8ebd8f42d8c148b Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 22:42:29 +0100 Subject: [PATCH 16/41] perf: match the first crawler before decoding the header --- README.md | 20 +++++----- docs/benchmarks/2026-11-23.md | 38 +++++++++++++++++-- .../HttpUserAgentParser.cs | 15 ++++++-- .../HttpUserAgentRobotSet.cs | 27 ++++++------- ...pUserAgentStaticsRobotsReplacementTests.cs | 11 ++++++ 5 files changed, 82 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c24c47e..2b1898a 100644 --- a/README.md +++ b/README.md @@ -459,20 +459,20 @@ BenchmarkDotNet 0.16.0-preview.2, .NET 11.0.0 x64, Windows 10, AMD Ryzen 9 9950X | Workload | Mean | Std. dev. | Allocated | | --- | ---: | ---: | ---: | -| Catalog browsers (44) | 310.0 ns | 0.84 ns | 38 B | -| Catalog crawlers (48) | 171.5 ns | 2.43 ns | 0 B | -| Full catalog (96) | 247.9 ns | 0.58 ns | 18 B | -| API snapshot (60) | 311.0 ns | 0.37 ns | 29 B | +| Catalog browsers (44) | 297.3 ns | 0.64 ns | 38 B | +| Catalog crawlers (48) | 158.9 ns | 1.63 ns | 0 B | +| Full catalog (96) | 254.8 ns | 2.61 ns | 18 B | +| API snapshot (60) | 307.3 ns | 0.89 ns | 29 B | | Selected individual headers | Mean | Std. dev. | Allocated | | --- | ---: | ---: | ---: | -| Googlebot | 22.13 ns | 0.245 ns | 0 B | -| Bravebot | 125.67 ns | 0.470 ns | 0 B | -| OAI-AdsBot | 261.96 ns | 1.682 ns | 0 B | -| IIS-encoded Screaming Frog | 251.06 ns | 3.469 ns | 0 B | -| Amazon Silk on Fire tablet | 277.44 ns | 3.096 ns | 40 B | +| Googlebot | 6.783 ns | 0.0712 ns | 0 B | +| Bravebot | 136.728 ns | 0.6628 ns | 0 B | +| OAI-AdsBot | 246.361 ns | 1.4094 ns | 0 B | +| IIS-encoded Screaming Frog | 238.949 ns | 0.9344 ns | 0 B | +| Amazon Silk on Fire tablet | 287.497 ns | 2.1981 ns | 40 B | -In a second run against the PR base (`be56445`), the snapshot mean fell from 438.2 to 321.8 ns per header, and the crawler catalog from 389.0 to 174.6 ns. The Googlebot header took 22.49 ns on the reviewed parser and 8.34 ns on the base. Both used 0 B per parse. [All individual results and the direct comparison](docs/benchmarks/2026-11-23.md) +The optimized parser checks the highest-priority robot rule before decoding the header. In a paired run the reference Googlebot header fell from 22.526 ns to 7.280 ns, with zero bytes allocated. A separate comparison measured 8.401 ns on main and 6.783 ns on the optimized parser. [Benchmarks and comparisons](docs/benchmarks/2026-11-23.md) ### Earlier measurements on .NET 8–10 diff --git a/docs/benchmarks/2026-11-23.md b/docs/benchmarks/2026-11-23.md index 6a825c3..6cad003 100644 --- a/docs/benchmarks/2026-11-23.md +++ b/docs/benchmarks/2026-11-23.md @@ -2,7 +2,39 @@ The Release build ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100, .NET runtime 11.0.0 and BenchmarkDotNet 0.16.0-preview.2. Each case used one process, three warm-up iterations and five measurement iterations targeting 250 ms. The tables report mean elapsed time, standard deviation and managed bytes allocated per uncached parse. [Reproduction command](../../README.md#parser-performance-on-net-11) -## Mixed workloads +## Googlebot optimization + +The first configured robot rule is checked against the original header. A Googlebot match returns before decoding the `+` in its contact URL. A first rule containing a space can still match the IIS-decoded header. Each comparison below used the job settings above and a freshly launched process per case. + +### Compared with the previous PR revision (`f5cc9e0`) + +| Workload | Previous PR mean | Optimized mean | Time change | Allocated per optimized parse | +| --- | ---: | ---: | ---: | ---: | +| Googlebot | 22.526 ns | 7.280 ns | −67.7% | 0 B | +| Googlebot Desktop | 24.322 ns | 7.620 ns | −68.7% | 0 B | +| Googlebot Smartphone | 29.798 ns | 9.264 ns | −68.9% | 0 B | +| Catalog browsers (44) | 298.4 ns | 304.7 ns | +2.1% | 38 B | +| Catalog crawlers (48) | 179.5 ns | 157.1 ns | −12.5% | 0 B | +| Full catalog (96) | 269.2 ns | 253.5 ns | −5.8% | 18 B | +| API snapshot (60) | 309.3 ns | 312.3 ns | +1.0% | 29 B | + +### Compared with main (`be56445`) + +| Workload | Main mean | Optimized mean | Time change | Allocated per optimized parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers (44) | 319.1 ns | 297.3 ns | −6.8% | 38 B | +| Catalog crawlers (48) | 372.2 ns | 158.9 ns | −57.3% | 0 B | +| Full catalog (96) | 367.6 ns | 254.8 ns | −30.7% | 18 B | +| API snapshot (60) | 424.6 ns | 307.3 ns | −27.6% | 29 B | +| Googlebot | 8.401 ns | 6.783 ns | −19.3% | 0 B | +| Bravebot | 456.896 ns | 136.728 ns | −70.1% | 0 B | +| OAI-AdsBot | 811.748 ns | 246.361 ns | −69.7% | 0 B | +| IIS-encoded Screaming Frog | 494.913 ns | 238.949 ns | −51.7% | 0 B | +| Amazon Silk on Fire tablet | 378.296 ns | 287.497 ns | −24.0% | 40 B | + +For the previous-PR comparison use the baseline build instructions below with `f5cc9e0` and the filters `"*HttpUserAgentParserBenchmarks.Parse*Googlebot*" "*RobotUserAgentBenchmarks.Parse*Googlebot*" "*MixedWorkloadBenchmarks.Parse*"`. For the main comparison, select the four mixed workloads and the five individual headers in the table. + +## Earlier mixed workloads before the Googlebot optimization Each invocation processes 5,280 headers in corpus order. Each distinct header contributes equally within its workload. @@ -13,7 +45,7 @@ Each invocation processes 5,280 headers in corpus order. Each distinct header co | Full catalog (96) | 247.9 ns | 0.58 ns | 18 B | | API snapshot (60) | 311.0 ns | 0.37 ns | 29 B | -## Comparison with the PR base +## Earlier comparison with the PR base A second run used the same harness, inputs and job settings for the main branch at `be56445` and the reviewed parser at `1fc5d9c`. Each implementation ran in its own benchmark process. Classification differences contribute to the times, especially when a newly recognized crawler returns early. @@ -30,7 +62,7 @@ Googlebot took 2.70 times as long in the reviewed parser, adding 14.15 ns per pa To reproduce the comparison, build the parser at `be56445` for `net11.0` in Release with `-p:AssemblyName=MyCSharp.HttpUserAgentParser.Baseline`. Set the environment variable `BenchmarkBaselineAssembly` to that DLL’s absolute path, then use the same benchmark command with the filters `"*MixedWorkloadBenchmarks.Parse*" "*HttpUserAgentParserBenchmarks.Parse*Googlebot*" "*HttpUserAgentParserBenchmarks.Parse*OAI-AdsBot*"`. -## Individual headers +## Earlier individual measurements before the Googlebot optimization The eight reference headers and 60 captured headers use the same parser entry point. The 60 expected results were checked on .NET 8, 9, 10 and 11. [Reference headers](../../perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs) · [Captured headers and expected results](../../tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs) diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 6381c76..03d5fa0 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -56,11 +56,16 @@ internal static HttpUserAgentInformation Parse(string userAgent, HttpUserAgentRo } private static HttpUserAgentInformation ParseInternal(string userAgent, HttpUserAgentRobotSet robots) - => Detect(Cleanup(userAgent), robots, AnalyzeUserAgent); + { + userAgent = Cleanup(userAgent); + return robots.MatchFirst(userAgent) is { } first + ? HttpUserAgentInformation.CreateForRobot(userAgent, first) + : Detect(userAgent, robots, AnalyzeUserAgent); + } private static HttpUserAgentInformation AnalyzeUserAgent(string userAgent, ReadOnlySpan ua, HttpUserAgentRobotSet robots) { - if (robots.Match(userAgent, ua) is { } robotName) + if (robots.MatchAfterFirst(userAgent, ua) is { } robotName) { return HttpUserAgentInformation.CreateForRobot(userAgent, robotName); } @@ -344,7 +349,11 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri /// returns the robot or null /// public static string? GetRobot(string userAgent) - => Detect(userAgent, HttpUserAgentRules.RobotSet, static (original, decoded, robots) => robots.Match(original, decoded)); + { + HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; + return robots.MatchFirst(userAgent) + ?? Detect(userAgent, robots, static (original, decoded, rules) => rules.MatchAfterFirst(original, decoded)); + } /// /// returns true if robot was found diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs index 0d51097..946e022 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -11,6 +11,8 @@ namespace MyCSharp.HttpUserAgentParser; /// internal sealed class HttpUserAgentRobotSet { + private readonly (string? Key, string? Value) _first; + private readonly int _decodedStart; private readonly int[] _literalPlusRules; /// @@ -21,7 +23,10 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) ReadOnlyEntries = [.. robots]; Keys = Array.ConvertAll(robots, static robot => robot.Key); - _literalPlusRules = [.. Enumerable.Range(0, robots.Length).Where(i => robots[i].Key.Contains('+'))]; + _first = robots.FirstOrDefault(); + // Decoding can create a new match for the first key only if that key contains a space. + _decodedStart = _first.Key?.Contains(' ') == true ? 0 : 1; + _literalPlusRules = [.. Enumerable.Range(0, robots.Length).Skip(1).Where(i => robots[i].Key.Contains('+'))]; // The first robot is checked on its own (Googlebot in the default list, by far the most common robot): own group. Matcher = new PriorityTokenMatcher(Keys, 1); @@ -29,12 +34,18 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) HttpUserAgentRules.CreateRobotAnchors(Keys, HttpUserAgentRules.CuratedRobotAnchors)); } + /// + /// The first rule has priority over every decoded or literal match, including when its name is customized. + /// + public string? MatchFirst(ReadOnlySpan original) + => _first.Key is { } key && original.Contains(key, StringComparison.OrdinalIgnoreCase) ? _first.Value : null; + /// /// Matches both IIS-encoded names and literal plus signs in custom keys, in configured priority order. /// - public string? Match(string original, ReadOnlySpan decoded) + public string? MatchAfterFirst(string original, ReadOnlySpan decoded) { - int index = Find(decoded); + int index = Keys.Length > _decodedStart && AnchorMatcher.ContainsAny(decoded) ? Matcher.Find(decoded, _decodedStart) : -1; foreach (int literal in _literalPlusRules) { if (index >= 0 && literal >= index) @@ -51,16 +62,6 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) return index >= 0 ? ReadOnlyEntries[index].Value : null; } - private int Find(ReadOnlySpan input) - { - if (Keys.Length > 0 && input.Contains(Keys[0], StringComparison.OrdinalIgnoreCase)) - { - return 0; - } - - return Keys.Length > 1 && AnchorMatcher.ContainsAny(input) ? Matcher.Find(input, 1) : -1; - } - /// /// Opaque identity for cache entries. Expired entries can retain this object without retaining the rules. /// diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs index 4fbe793..abbeb5d 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsRobotsReplacementTests.cs @@ -121,6 +121,17 @@ public void Literal_And_Iis_Encoded_Robot_Keys_Respect_Their_Configured_Order() Assert.Null(HttpUserAgentParser.GetRobot("C Bot")); } + [Fact] + public void First_Rule_Can_Match_After_Decoding_And_Still_Outrank_Literal_Matches() + { + HttpUserAgentStatics.SetRobots([("Log Spider", "First"), ("C++Bot", "Literal"), ("Chrome", "Last")]); + foreach ((string header, string expected) in new[] { ("C++Bot log+spider Chrome/1", "First"), ("Chrome/1 C++Bot", "Literal") }) + { + Assert.Equal(expected, HttpUserAgentParser.Parse(header).Name); + Assert.Equal(expected, HttpUserAgentParser.GetRobot(header)); + } + } + [Fact] public void SetRobots_Accepts_A_Single_Robot_And_No_Robots() { From f54e5b21aed7552dbc69489293b0e68d17209d21 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 23:14:29 +0100 Subject: [PATCH 17/41] perf: share rule filtering across user-agent detectors --- README.md | 25 ++-- docs/benchmarks/2026-11-23.md | 55 +++++++- .../HttpUserAgentParserBenchmarks.cs | 29 +++++ .../HttpUserAgentParser.cs | 38 +++--- .../HttpUserAgentRobotSet.cs | 9 +- src/HttpUserAgentParser/HttpUserAgentRules.cs | 4 +- src/HttpUserAgentParser/UserAgentRuleIndex.cs | 123 ++++++++++++++++++ .../UserAgentRuleIndexTests.cs | 58 +++++++++ 8 files changed, 305 insertions(+), 36 deletions(-) create mode 100644 src/HttpUserAgentParser/UserAgentRuleIndex.cs create mode 100644 tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs diff --git a/README.md b/README.md index 2b1898a..d923f58 100644 --- a/README.md +++ b/README.md @@ -455,24 +455,17 @@ Run the 68 individual and four mixed benchmarks with the settings used for the N dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks.Parse" "*MixedWorkloadBenchmarks.Parse" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 ``` -BenchmarkDotNet 0.16.0-preview.2, .NET 11.0.0 x64, Windows 10, AMD Ryzen 9 9950X. Each case ran in a separate process with three warm-ups and five measurement iterations targeting 250 ms each. Times and managed allocations are per parsed header. +BenchmarkDotNet 0.16.0-preview.2, .NET 11.0.0 x64, Windows 10, AMD Ryzen 9 9950X. Each row compares mean time per uncached header with the previous PR revision (`5691833`). Negative percentages mean less time per header. -| Workload | Mean | Std. dev. | Allocated | -| --- | ---: | ---: | ---: | -| Catalog browsers (44) | 297.3 ns | 0.64 ns | 38 B | -| Catalog crawlers (48) | 158.9 ns | 1.63 ns | 0 B | -| Full catalog (96) | 254.8 ns | 2.61 ns | 18 B | -| API snapshot (60) | 307.3 ns | 0.89 ns | 29 B | - -| Selected individual headers | Mean | Std. dev. | Allocated | -| --- | ---: | ---: | ---: | -| Googlebot | 6.783 ns | 0.0712 ns | 0 B | -| Bravebot | 136.728 ns | 0.6628 ns | 0 B | -| OAI-AdsBot | 246.361 ns | 1.4094 ns | 0 B | -| IIS-encoded Screaming Frog | 238.949 ns | 0.9344 ns | 0 B | -| Amazon Silk on Fire tablet | 287.497 ns | 2.1981 ns | 40 B | +| Workload | Previous PR | Shared filter | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers (44) | 289.37 ns | 238.36 ns | −17.6% | 38 B | +| Catalog crawlers (48) | 164.18 ns | 79.73 ns | −51.4% | 0 B | +| Full catalog (96) | 256.87 ns | 155.38 ns | −39.5% | 18 B | +| API snapshot (60) | 308.70 ns | 202.46 ns | −34.4% | 29 B | +| Googlebot | 6.797 ns | 6.821 ns | +0.4% | 0 B | -The optimized parser checks the highest-priority robot rule before decoding the header. In a paired run the reference Googlebot header fell from 22.526 ns to 7.280 ns, with zero bytes allocated. A separate comparison measured 8.401 ns on main and 6.783 ns on the optimized parser. [Benchmarks and comparisons](docs/benchmarks/2026-11-23.md) +The four detectors share a 64 KiB lookup table for ASCII headers up to 255 characters. Longer headers and Unicode inputs use the full rule set. The benchmark report includes those controls, the comparison with main and results for .NET 8–11. [Detailed measurements](docs/benchmarks/2026-11-23.md) ### Earlier measurements on .NET 8–10 diff --git a/docs/benchmarks/2026-11-23.md b/docs/benchmarks/2026-11-23.md index 6cad003..7d9a93c 100644 --- a/docs/benchmarks/2026-11-23.md +++ b/docs/benchmarks/2026-11-23.md @@ -1,8 +1,59 @@ # Parser benchmarks on November 23, 2026 -The Release build ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100, .NET runtime 11.0.0 and BenchmarkDotNet 0.16.0-preview.2. Each case used one process, three warm-up iterations and five measurement iterations targeting 250 ms. The tables report mean elapsed time, standard deviation and managed bytes allocated per uncached parse. [Reproduction command](../../README.md#parser-performance-on-net-11) +Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case used a separate process, three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../README.md#parser-performance-on-net-11) -## Googlebot optimization +## Shared rule filter + +For ASCII headers up to 255 characters, a single scan selects candidates for the built-in crawler, platform, device and browser rules. The parser checks those candidates in rule order. The highest-priority crawler can return before this scan. Custom crawler rules use their configured matcher. The shared lookup table occupies 64 KiB. Managed allocations per parse were the same as the previous PR on every workload measured below. + +### Compared with the previous PR revision (`5691833`) + +Each mixed workload repeats its inputs in catalog order, with equal weight per header. Time changes on .NET 8.0.34, 9.0.23, 10.0.15 and 11.0.0 were measured separately. + +| Runtime | Catalog browsers | Catalog crawlers | Full catalog | API snapshot | +| --- | ---: | ---: | ---: | ---: | +| .NET 8 | −61.2% | −73.8% | −66.3% | −65.0% | +| .NET 9 | −17.2% | −46.8% | −29.9% | −33.3% | +| .NET 10 | −21.6% | −48.6% | −32.9% | −32.0% | +| .NET 11 | −17.6% | −51.4% | −39.5% | −34.4% | + +Mean times on .NET 11 for the same comparison. + +| Workload | Previous PR | Shared filter | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers (44) | 289.37 ns | 238.36 ns | −17.6% | 38 B | +| Catalog crawlers (48) | 164.18 ns | 79.73 ns | −51.4% | 0 B | +| Full catalog (96) | 256.87 ns | 155.38 ns | −39.5% | 18 B | +| API snapshot (60) | 308.70 ns | 202.46 ns | −34.4% | 29 B | +| Googlebot | 6.797 ns | 6.821 ns | +0.4% | 0 B | + +### Compared with main (`be56445`) on .NET 11 + +| Workload | Main | Shared filter | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers (44) | 326.69 ns | 233.39 ns | −28.6% | 38 B | +| Catalog crawlers (48) | 378.77 ns | 78.47 ns | −79.3% | 0 B | +| Full catalog (96) | 389.59 ns | 155.96 ns | −60.0% | 18 B | +| API snapshot (60) | 359.15 ns | 205.52 ns | −42.8% | 29 B | +| Googlebot | 8.178 ns | 6.819 ns | −16.6% | 0 B | +| OAI-AdsBot | 904.130 ns | 141.179 ns | −84.4% | 0 B | + +### Header length and Unicode on .NET 11 + +These cases append a comment to the same Chrome header. Within each pair, only the last letter of the comment changes. Headers longer than 255 characters and headers containing non-ASCII characters use the full rule set. The time change depends on the header. + +| Chrome header length | Comment | Previous PR | Shared filter | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | ---: | +| 128 | ASCII | 320.3 ns | 230.7 ns | −28.0% | 40 B | +| 128 | Unicode | 323.2 ns | 334.1 ns | +3.4% | 40 B | +| 256 | ASCII | 367.7 ns | 395.7 ns | +7.6% | 40 B | +| 256 | Unicode | 353.7 ns | 372.0 ns | +5.2% | 40 B | +| 4096 | ASCII | 4,059.2 ns | 3,869.1 ns | −4.7% | 40 B | +| 4096 | Unicode | 4,058.9 ns | 4,057.8 ns | <0.1% | 40 B | + +To reproduce a paired run, build the baseline revision in Release for the target framework with `-p:AssemblyName=MyCSharp.HttpUserAgentParser.Baseline` and set `BenchmarkBaselineAssembly` to the absolute path of that DLL. Run the benchmark command with the same framework and the filters `"*MixedWorkloadBenchmarks.Parse*" "*HttpUserAgentParserBenchmarks.Parse*Googlebot*" "*HeaderLengthBenchmarks.Parse*"`. For the comparison with main, replace the length filter with `"*HttpUserAgentParserBenchmarks.Parse*OAI-AdsBot*"`. + +## Earlier Googlebot optimization The first configured robot rule is checked against the original header. A Googlebot match returns before decoding the `+` in its contact URL. A first rule containing a space can still match the IIS-decoded header. Each comparison below used the job settings above and a freshly launched process per case. diff --git a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs index ec5bff6..e8c86e9 100644 --- a/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs +++ b/perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs @@ -64,3 +64,32 @@ public class RepeatedBrowserTokenBenchmarks [Benchmark] public (string Name, string Version)? GetBrowser() => Parser.GetBrowser(_userAgent); } + +[MemoryDiagnoser] +public class HeaderLengthBenchmarks +{ + private const string Prefix = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36"; + private string _userAgent; + + [Params(128, 256, 4096)] + public int Length { get; set; } + + [Params(false, true)] + public bool Unicode { get; set; } + + [GlobalSetup] + public void Setup() + { + // Keep browser tokens and total length identical. Only the trailing comment changes. + string suffix = Unicode ? "é)" : "x)"; + _userAgent = Prefix + " (" + new string('x', Length - Prefix.Length - 4) + suffix; + } + + [Benchmark] + public string Parse() => Parser.Parse(_userAgent).Name; + +#if BENCHMARK_BASELINE + [Benchmark(Baseline = true)] + public string ParseBaseline() => Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(_userAgent).Name; +#endif +} diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 03d5fa0..8603c83 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -65,15 +65,17 @@ private static HttpUserAgentInformation ParseInternal(string userAgent, HttpUser private static HttpUserAgentInformation AnalyzeUserAgent(string userAgent, ReadOnlySpan ua, HttpUserAgentRobotSet robots) { - if (robots.MatchAfterFirst(userAgent, ua) is { } robotName) + UserAgentRuleIndex.RuleMasks candidates = UserAgentRuleIndex.BuiltIn.Find(ua); + ulong robotMask = ReferenceEquals(robots, HttpUserAgentRules.DefaultRobotSet) ? candidates.Robots : ulong.MaxValue; + if (robots.MatchAfterFirst(userAgent, ua, robotMask) is { } robotName) { return HttpUserAgentInformation.CreateForRobot(userAgent, robotName); } - HttpUserAgentPlatformInformation? platform = FindPlatform(ua); - string? mobileDeviceType = FindMobileDevice(ua); + HttpUserAgentPlatformInformation? platform = FindPlatform(ua, candidates.Platforms); + string? mobileDeviceType = FindMobileDevice(ua, candidates.Devices); - if (FindBrowser(ua) is { } browser) + if (FindBrowser(ua, candidates.Browsers) is { } browser) { return HttpUserAgentInformation.CreateForBrowser(userAgent, platform, browser.Name, browser.Version, mobileDeviceType); } @@ -126,14 +128,15 @@ private static T Detect(string userAgent, TState state, Detector public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent) - => DetectProduct(userAgent, FindPlatform); + => DetectProduct(userAgent, static ua => FindPlatform(ua, ulong.MaxValue)); - private static HttpUserAgentPlatformInformation? FindPlatform(ReadOnlySpan ua) + private static HttpUserAgentPlatformInformation? FindPlatform(ReadOnlySpan ua, ulong mask) { - // Rules are sorted by frequency, so a sequential scan usually stops after a few tokens. - // (Measured with a mixed real-world workload, this beats vectorized token groups here.) - foreach ((string token, HttpUserAgentPlatformInformation platform) in HttpUserAgentRules.Platforms) + (string Token, HttpUserAgentPlatformInformation Platform)[] rules = HttpUserAgentRules.Platforms; + UserAgentRuleIndex.Candidates candidates = new(mask, rules.Length); + for (int i = candidates.Next(); i >= 0; i = candidates.Next()) { + (string token, HttpUserAgentPlatformInformation platform) = rules[i]; int index = ua.IndexOf(token, StringComparison.OrdinalIgnoreCase); while (index >= 0) { @@ -177,12 +180,15 @@ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out Http /// or after a space, tab, +, ;, (, ) or ,. /// public static (string Name, string? Version)? GetBrowser(string userAgent) - => DetectProduct(userAgent, FindBrowser); + => DetectProduct(userAgent, static ua => FindBrowser(ua, UserAgentRuleIndex.BuiltIn.Find(ua).Browsers)); - private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua) + private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua, ulong mask) { - foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) + (string Name, string DetectToken, string? VersionToken)[] rules = HttpUserAgentRules.Browsers; + UserAgentRuleIndex.Candidates candidates = new(mask, rules.Length); + for (int i = candidates.Next(); i >= 0; i = candidates.Next()) { + (string name, string detectToken, string? versionToken) = rules[i]; int detectIndex = IndexOfTokenStart(ua, detectToken, 0); if (detectIndex < 0) { @@ -368,11 +374,13 @@ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? /// returns the device or null /// public static string? GetMobileDevice(string userAgent) - => DetectProduct(userAgent, FindMobileDevice); + => DetectProduct(userAgent, static ua => FindMobileDevice(ua, ulong.MaxValue)); - private static string? FindMobileDevice(ReadOnlySpan ua) + private static string? FindMobileDevice(ReadOnlySpan ua, ulong mask) { - int index = HttpUserAgentRules.MobileMatcher.Find(ua, 0); + int index = mask != ulong.MaxValue + ? UserAgentRuleIndex.FindKey(ua, HttpUserAgentRules.MobileKeys, mask) + : HttpUserAgentRules.MobileMatcher.Find(ua, 0); return index >= 0 ? HttpUserAgentRules.Mobiles[index].Value : null; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs index 946e022..2d46b8b 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -43,9 +43,11 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) /// /// Matches both IIS-encoded names and literal plus signs in custom keys, in configured priority order. /// - public string? MatchAfterFirst(string original, ReadOnlySpan decoded) + public string? MatchAfterFirst(string original, ReadOnlySpan decoded, ulong mask = ulong.MaxValue) { - int index = Keys.Length > _decodedStart && AnchorMatcher.ContainsAny(decoded) ? Matcher.Find(decoded, _decodedStart) : -1; + int index = mask != ulong.MaxValue + ? UserAgentRuleIndex.FindKey(decoded, Keys, mask) + : FindAfterFirst(decoded); foreach (int literal in _literalPlusRules) { if (index >= 0 && literal >= index) @@ -62,6 +64,9 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) return index >= 0 ? ReadOnlyEntries[index].Value : null; } + private int FindAfterFirst(ReadOnlySpan decoded) + => Keys.Length > _decodedStart && AnchorMatcher.ContainsAny(decoded) ? Matcher.Find(decoded, _decodedStart) : -1; + /// /// Opaque identity for cache entries. Expired entries can retain this object without retaining the rules. /// diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 9b97bfe..116e7ac 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -394,10 +394,12 @@ internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAncho ("cellphone", "Generic Mobile"), ]; + internal static string[] MobileKeys { get; } = Array.ConvertAll(Mobiles, static rule => rule.Key); + /// /// Mobile token matcher. /// - internal static PriorityTokenMatcher MobileMatcher { get; } = new(Array.ConvertAll(Mobiles, static rule => rule.Key)); + internal static PriorityTokenMatcher MobileMatcher { get; } = new(MobileKeys); /// /// Creates the public, case-insensitive lookup of . diff --git a/src/HttpUserAgentParser/UserAgentRuleIndex.cs b/src/HttpUserAgentParser/UserAgentRuleIndex.cs new file mode 100644 index 0000000..2404a29 --- /dev/null +++ b/src/HttpUserAgentParser/UserAgentRuleIndex.cs @@ -0,0 +1,123 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using System.Numerics; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Text; + +namespace MyCSharp.HttpUserAgentParser; + +/// Shares one candidate search across the four built-in rule tables. +internal sealed class UserAgentRuleIndex +{ + private const int BucketCount = 2048; + // For longer headers the individual vectorized substring searches cost less than indexing the full input. + private const int MaxIndexedLength = 255; + private readonly Vector256[] _buckets = new Vector256[BucketCount]; + private readonly Vector256 _always; + + // Built only when a shared filter is needed. The first robot rule can return before this point. + public static UserAgentRuleIndex BuiltIn { get; } = new( + HttpUserAgentRules.DefaultRobotSet.Keys, Array.ConvertAll(HttpUserAgentRules.Platforms, static r => r.Token), + HttpUserAgentRules.MobileKeys, Array.ConvertAll(HttpUserAgentRules.Browsers, static r => r.DetectToken)); + + // Each lane belongs to one rule table. Register both overlapping triples of the first four + // characters: one triple must start at an even offset, regardless of the key's position. + public UserAgentRuleIndex(string[] robots, string[] platforms, string[] devices, string[] browsers) + { + string[][] tables = [robots, platforms, devices, browsers]; + for (int table = 0; table < tables.Length; table++) + { + string[] keys = tables[table]; + for (int rule = 0; rule < keys.Length; rule++) + { + string key = keys[rule]; + ulong bit = 1UL << (rule % 64); + if (key.Length < 4 || !Ascii.IsValid(key)) + { + _always = _always.WithElement(table, _always.GetElement(table) | bit); + continue; + } + + Add(Hash(key[0], key[1], key[2]), table, bit); + Add(Hash(key[1], key[2], key[3]), table, bit); + } + } + } + + private void Add(int hash, int table, ulong bit) + { + ref Vector256 bucket = ref _buckets[hash]; + bucket = bucket.WithElement(table, bucket.GetElement(table) | bit); + } + + // Fold ASCII letters to the same bucket. Punctuation and hash collisions can only add candidates. + private static int Hash(char a, char b, char c) => (((a | 32) * 31) ^ ((b | 32) << 5) ^ (c | 32)) & (BucketCount - 1); + + public RuleMasks Find(ReadOnlySpan input) + { + if (input.Length > MaxIndexedLength || !Ascii.IsValid(input)) + { + // Non-ASCII headers also require the full ordinal case-folding semantics. + return new RuleMasks(Vector256.Create(ulong.MaxValue)); + } + + Vector256 candidates = _always; + for (int i = 2; i < input.Length; i += 2) + { + candidates |= _buckets[Hash(input[i - 2], input[i - 1], input[i])]; + } + + return new RuleMasks(candidates); + } + + [StructLayout(LayoutKind.Auto)] + internal readonly struct RuleMasks(Vector256 bits) + { + public ulong Robots => bits.GetElement(0); + public ulong Platforms => bits.GetElement(1); + public ulong Devices => bits.GetElement(2); + public ulong Browsers => bits.GetElement(3); + } + + public static int FindKey(ReadOnlySpan input, string[] keys, ulong mask) + { + Candidates candidates = new(mask, keys.Length); + for (int i = candidates.Next(); i >= 0; i = candidates.Next()) + { + if (input.Contains(keys[i], StringComparison.OrdinalIgnoreCase)) + { + return i; + } + } + + return -1; + } + + // The same 64 bits cover each successive block of rules. The full key confirms the match. + [StructLayout(LayoutKind.Auto)] + internal struct Candidates(ulong mask, int count) + { + private readonly ulong _mask = mask; + private ulong _remaining = mask; + private int _offset; + + public int Next() + { + if (_remaining == 0) + { + _offset += 64; + if (_mask == 0 || _offset >= count) + { + return -1; + } + + _remaining = _mask; + } + + int index = _offset + BitOperations.TrailingZeroCount(_remaining); + _remaining &= _remaining - 1; + return index < count ? index : -1; + } + } +} diff --git a/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs b/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs new file mode 100644 index 0000000..68ef69b --- /dev/null +++ b/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs @@ -0,0 +1,58 @@ +// Copyright © https://myCSharp.de - all rights reserved + +using Xunit; + +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class UserAgentRuleIndexTests +{ + [Fact] + public void Built_In_Keys_Are_Candidates_At_Either_Alignment() + { + string[][] tables = + [ + HttpUserAgentRules.DefaultRobotSet.Keys, Array.ConvertAll(HttpUserAgentRules.Platforms, static r => r.Token), + HttpUserAgentRules.MobileKeys, Array.ConvertAll(HttpUserAgentRules.Browsers, static r => r.DetectToken), + ]; + + for (int table = 0; table < tables.Length; table++) + { + string[] keys = tables[table]; + for (int i = 0; i < keys.Length; i++) + { + foreach (string prefix in new[] { "", " " }) + { + string header = prefix + keys[i].ToUpperInvariant(); + UserAgentRuleIndex.RuleMasks masks = UserAgentRuleIndex.BuiltIn.Find(header); + ulong[] lanes = [masks.Robots, masks.Platforms, masks.Devices, masks.Browsers]; + int expected = Array.FindIndex(keys, key => header.Contains(key, StringComparison.OrdinalIgnoreCase)); + Assert.NotEqual(0UL, lanes[table] & (1UL << (i % 64))); + Assert.Equal(expected, UserAgentRuleIndex.FindKey(header, keys, lanes[table])); + } + } + } + } + + [Fact] + public void Long_Headers_Use_All_Rules_At_The_Length_Threshold() + { + UserAgentRuleIndex index = new(["Safari"], [], [], []); + Assert.Equal(0UL, index.Find(new string('x', 255)).Robots); + string header = new string('x', 250) + "Safari"; + ulong mask = index.Find(header).Robots; + Assert.Equal(ulong.MaxValue, mask); + Assert.Equal(0, UserAgentRuleIndex.FindKey(header, ["Safari"], mask)); + } + + [Fact] + public void Short_And_Unicode_Keys_Are_Checked_Exactly() + { + string[] keys = ["LG", "Café", "Safari"]; + UserAgentRuleIndex index = new(keys, [], [], []); + foreach (string header in new[] { "L", "lg", "Café", "K Safari/17", "SafariHelper", "Cafe" }) + { + int expected = Array.FindIndex(keys, key => header.Contains(key, StringComparison.OrdinalIgnoreCase)); + Assert.Equal(expected, UserAgentRuleIndex.FindKey(header, keys, index.Find(header).Robots)); + } + } +} From bf01ad235ce3e162c93a3db525f62f831a1bcd97 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 23 Nov 2026 23:22:14 +0100 Subject: [PATCH 18/41] docs: refresh README benchmarks and chart library timings --- README.md | 80 ++--- docs/benchmarks/library-comparison-net11.svg | 316 +++++++++++++++++++ 2 files changed, 337 insertions(+), 59 deletions(-) create mode 100644 docs/benchmarks/library-comparison-net11.svg diff --git a/README.md b/README.md index d923f58..923cc49 100644 --- a/README.md +++ b/README.md @@ -443,80 +443,42 @@ Notes: ## Benchmark -The parser benchmark runs without caching. The 68 individual cases include eight reference headers and 60 headers captured from November 15–22, 2026. Each captured header has a regression test for client type, name, version, platform and mobile device. All inputs are stored locally. [Captured headers](tests/HttpUserAgentParser.TestHelpers/UserAgentsMeSnapshot.cs) · [Snapshot source](https://useragents.me/api) - -The `Snapshot` workload contains 43 browsers, nine crawlers and eight unclassified clients. The separate catalog contains 44 browsers, 48 crawlers and four unclassified clients. Each mixed benchmark parses 5,280 headers per invocation, repeating its corpus in order. Every header in a workload has equal weight. [Catalog](tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs) - ### Parser performance on .NET 11 -Run the 68 individual and four mixed benchmarks with the settings used for the November 23, 2026 measurements. - -```shell -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks.Parse" "*MixedWorkloadBenchmarks.Parse" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 -``` - -BenchmarkDotNet 0.16.0-preview.2, .NET 11.0.0 x64, Windows 10, AMD Ryzen 9 9950X. Each row compares mean time per uncached header with the previous PR revision (`5691833`). Negative percentages mean less time per header. +Mean time per uncached header on Windows 10 x64, AMD Ryzen 9 9950X, .NET 11.0.0. Each mixed workload processes 5,280 headers per invocation, with equal weight per distinct header. The API snapshot contains 60 captured user agents. [Test inputs and measurements](docs/benchmarks/2026-11-23.md) -| Workload | Previous PR | Shared filter | Time change | Allocated per parse | +| Workload | v3.1.9 | Current parser | Time change | Allocated per current parse | | --- | ---: | ---: | ---: | ---: | -| Catalog browsers (44) | 289.37 ns | 238.36 ns | −17.6% | 38 B | -| Catalog crawlers (48) | 164.18 ns | 79.73 ns | −51.4% | 0 B | -| Full catalog (96) | 256.87 ns | 155.38 ns | −39.5% | 18 B | -| API snapshot (60) | 308.70 ns | 202.46 ns | −34.4% | 29 B | -| Googlebot | 6.797 ns | 6.821 ns | +0.4% | 0 B | +| Catalog browsers (44) | 326.69 ns | 233.39 ns | −28.6% | 38 B | +| Catalog crawlers (48) | 378.77 ns | 78.47 ns | −79.3% | 0 B | +| Full catalog (96) | 389.59 ns | 155.96 ns | −60.0% | 18 B | +| API snapshot (60) | 359.15 ns | 205.52 ns | −42.8% | 29 B | +| Googlebot | 8.178 ns | 6.819 ns | −16.6% | 0 B | +| OAI-AdsBot | 904.130 ns | 141.179 ns | −84.4% | 0 B | -The four detectors share a 64 KiB lookup table for ASCII headers up to 255 characters. Longer headers and Unicode inputs use the full rule set. The benchmark report includes those controls, the comparison with main and results for .NET 8–11. [Detailed measurements](docs/benchmarks/2026-11-23.md) +Full-catalog means on the other supported runtimes were 193.01 ns (.NET 8), 196.53 ns (.NET 9) and 168.41 ns (.NET 10). The first Chrome parse on .NET 11 took 12.18 ms and allocated 199,984 B on the calling thread (medians across nine fresh processes). -### Earlier measurements on .NET 8–10 +### Library comparison on .NET 11 -The earlier default-job run used the catalog and repeated its entries to fill batches of 1,000. The table reports mean time per parsed header. The .NET 8 implementation scans tokens sequentially. The .NET 9 and later implementations use `SearchValues`. +BenchmarkDotNet ShortRun, three warm-ups and three measured iterations. UAParser 3.1.47 and DeviceDetector.NET 6.5.0 use the calls listed below. The crawler header in this comparison is `APIs-Google`. -| Workload | .NET 8.0.34 | .NET 9.0.23 | .NET 10.0.15 | -| --- | ---: | ---: | ---: | -| 44 browsers | 754.0 ns | 331.8 ns | 291.7 ns | -| 48 crawlers | 355.5 ns | 159.0 ns | 227.4 ns | -| All 96 catalog headers | 609.4 ns | 261.0 ns | 262.3 ns | +![Mean parse times for Chrome on Windows and APIs-Google by library and operation, on a logarithmic axis. Exact times follow in the table.](docs/benchmarks/library-comparison-net11.svg) -### Earlier .NET 11 startup measurements +| Library | Measured operation | Chrome on Windows | Allocated | APIs-Google | Allocated | +| --- | --- | ---: | ---: | ---: | ---: | +| MyCSharp | Parse | 246.46 ns | 48 B | 104.26 ns | 0 B | +| UAParser | GetDefault + Parse | 9,411,708.33 ns | 11,653,583 B | 9,340,315.10 ns | 12,010,118 B | +| DeviceDetector.NET | New detector + Parse | 5,701,457.29 ns | 5,529,305 B | 7,332,071.61 ns | 10,123,039 B | +| MyCSharp | Result cache hit | 19.42 ns | 0 B | 12.65 ns | 0 B | +| UAParser | Reused compiled parser | 123,522.75 ns | 37,400 B | 110,026.41 ns | 45,832 B | -An earlier revision used 43 platform and 35 browser regular expressions. The median across seven fresh processes was 9.1 ms and 122 KB for the first parse, and 15.7 ms and 120 KB for first use of all regular expressions. The current set adds Amazon Silk as the 36th browser expression. - -### Earlier library comparison on .NET 11 +### Run the benchmarks ```shell +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks.Parse" "*MixedWorkloadBenchmarks.Parse" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*LibraryComparison*" ``` -The ShortRun job (3 iterations) runs every benchmark case in its own process. - -```shell -BenchmarkDotNet v0.16.0-preview.2, Windows 10 (10.0.19045.7846/22H2/2022Update) -AMD Ryzen 9 9950X 4.30GHz, 1 CPU, 32 logical and 16 physical cores -Memory: 61,64 GB Total, 31,34 GB Available -.NET SDK 11.0.100 - [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 - ShortRun : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 - -Job=ShortRun IterationCount=3 LaunchCount=1 -WarmupCount=3 -``` - -| Method | Categories | Data | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio | -|------------------- |----------- |------------- |----------------:|-----------------:|---------------:|----------:|--------:|---------:|---------:|---------:|-----------:|------------:| -| MyCSharp | Basic | Chrome Win10 | 304.64 ns | 9.540 ns | 0.523 ns | 1.00 | 0.00 | 0.0029 | - | - | 48 B | 1.00 | -| UAParser | Basic | Chrome Win10 | 9,491,617.71 ns | 1,334,799.918 ns | 73,164.888 ns | 31,156.50 | 213.09 | 671.8750 | 609.3750 | 109.3750 | 11653583 B | 242,782.98 | -| DeviceDetector.NET | Basic | Chrome Win10 | 5,911,814.32 ns | 2,450,967.779 ns | 134,345.815 ns | 19,405.70 | 383.00 | 335.9375 | 179.6875 | 46.8750 | 5529304 B | 115,193.83 | -| | | | | | | | | | | | | | -| MyCSharp | Basic | Google-Bot | 239.51 ns | 12.113 ns | 0.664 ns | 1.00 | 0.00 | - | - | - | - | NA | -| UAParser | Basic | Google-Bot | 9,398,484.90 ns | 2,371,656.128 ns | 129,998.476 ns | 39,239.89 | 479.38 | 687.5000 | 625.0000 | 125.0000 | 12010118 B | NA | -| DeviceDetector.NET | Basic | Google-Bot | 7,600,150.00 ns | 1,546,038.456 ns | 84,743.585 ns | 31,731.61 | 315.73 | 656.2500 | 179.6875 | 70.3125 | 10123039 B | NA | -| | | | | | | | | | | | | | -| MyCSharp | Cached | Chrome Win10 | 18.95 ns | 0.720 ns | 0.039 ns | 1.00 | 0.00 | - | - | - | - | NA | -| UAParser | Cached | Chrome Win10 | 126,033.06 ns | 11,193.962 ns | 613.579 ns | 6,652.00 | 30.50 | 2.1973 | - | - | 37400 B | NA | -| | | | | | | | | | | | | | -| MyCSharp | Cached | Google-Bot | 13.42 ns | 1.006 ns | 0.055 ns | 1.00 | 0.00 | - | - | - | - | NA | -| UAParser | Cached | Google-Bot | 108,784.53 ns | 19,649.227 ns | 1,077.040 ns | 8,105.83 | 75.26 | 2.6855 | - | - | 45832 B | NA | - ## Disclaimer This library is inspired by [UserAgentService by DannyBoyNg](https://github.com/DannyBoyNg/UserAgentService) and contains optimizations for our requirements on [myCSharp.de](https://mycsharp.de). diff --git a/docs/benchmarks/library-comparison-net11.svg b/docs/benchmarks/library-comparison-net11.svg new file mode 100644 index 0000000..9aa1ef7 --- /dev/null +++ b/docs/benchmarks/library-comparison-net11.svg @@ -0,0 +1,316 @@ + + + Library benchmarks on .NET 11 + + + + + Library benchmarks on .NET 11 + Mean time per call for Chrome on Windows and APIs-Google. The horizontal axis is logarithmic and begins at one nanosecond. + image/svg+xml + + + Matplotlib v3.10.9, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + 1 ns + + + + + + + + + 10 ns + + + + + + + + + 100 ns + + + + + + + + + 1 µs + + + + + + + + + 10 µs + + + + + + + + + 100 µs + + + + + + + + + 1 ms + + + + + + + + + 10 ms + + + + Mean time per call (logarithmic scale) + + + + + + + MyCSharp + Parse + + + + + + UAParser + GetDefault + Parse + + + + + + DeviceDetector.NET + New detector + Parse + + + + + + MyCSharp + Result cache hit + + + + + + UAParser + Reused compiled parser + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 246 ns + + + 9.41 ms + + + 5.7 ms + + + 19.4 ns + + + 124 µs + + + 104 ns + + + 9.34 ms + + + 7.33 ms + + + 12.7 ns + + + 110 µs + + + + + + + Chrome on Windows + + + + + + APIs-Google + + + + + + + + + + From 549b45841078bc9e56afa3fd5e81dc4d4bc08836 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 11:11:50 +0100 Subject: [PATCH 19/41] chore: update dependencies for security improvements --- README.md | 37 +++++++++++++++++++++++++------ res/httpuseragentparser-logo.png | Bin 0 -> 250705 bytes 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 res/httpuseragentparser-logo.png diff --git a/README.md b/README.md index 923cc49..db09186 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,40 @@ +
+ +HttpUserAgentParser logo: the myCSharp.de raccoon in a browser window, inspecting a user agent with a magnifying glass + # MyCSharp.HttpUserAgentParser -Parsing HTTP User Agents with .NET +**Parsing HTTP User Agents with .NET** -The NuGet packages target .NET 8, 9, 10, and 11. Building the solution requires the .NET 11 SDK. +Detects browsers, platforms, mobile devices and crawlers with low allocations. + +[![Build](https://img.shields.io/github/actions/workflow/status/mycsharp/HttpUserAgentParser/main-build.yml?branch=main&logo=githubactions&logoColor=white&label=build)](https://github.com/mycsharp/HttpUserAgentParser/actions/workflows/main-build.yml) +[![Coverage: 100% line, branch and method coverage, enforced in CI](https://img.shields.io/badge/coverage-100%25-brightgreen)](Directory.Build.props) +[![NuGet](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser?logo=nuget&label=nuget&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser) +[![NuGet downloads](https://img.shields.io/nuget/dt/MyCSharp.HttpUserAgentParser?logo=nuget&label=downloads&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser) +[![License: MIT](https://img.shields.io/github/license/mycsharp/HttpUserAgentParser?color=blue)](LICENSE) + +[![.NET 8 | 9 | 10 | 11](https://img.shields.io/badge/.NET-8%20%7C%209%20%7C%2010%20%7C%2011-512BD4?logo=dotnet&logoColor=white)](https://dotnet.microsoft.com/) +[![Native AOT compatible](https://img.shields.io/badge/Native%20AOT-compatible-512BD4?logo=dotnet&logoColor=white)](#native-aot-and-trimming) +[![Trimming compatible](https://img.shields.io/badge/trimming-compatible-512BD4?logo=dotnet&logoColor=white)](#native-aot-and-trimming) +[![Strong-named assemblies](https://img.shields.io/badge/strong--named-yes-blue)](https://learn.microsoft.com/dotnet/standard/assembly/strong-named) +[![SourceLink enabled](https://img.shields.io/badge/SourceLink-enabled-blue)](https://learn.microsoft.com/dotnet/standard/library-guidance/sourcelink) + +[![GitHub stars](https://img.shields.io/github/stars/mycsharp/HttpUserAgentParser?logo=github)](https://github.com/mycsharp/HttpUserAgentParser/stargazers) +[![Last commit](https://img.shields.io/github/last-commit/mycsharp/HttpUserAgentParser/main?logo=github)](https://github.com/mycsharp/HttpUserAgentParser/commits/main) +[![Open issues](https://img.shields.io/github/issues/mycsharp/HttpUserAgentParser?logo=github)](https://github.com/mycsharp/HttpUserAgentParser/issues) + +
## NuGet -| NuGet | -|-| -| [![MyCSharp.HttpUserAgentParser](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser.svg?logo=nuget&label=MyCSharp.HttpUserAgentParser)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser) | -| [![MyCSharp.HttpUserAgentParser](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser.MemoryCache.svg?logo=nuget&label=MyCSharp.HttpUserAgentParser.MemoryCache)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache)| `dotnet add package MyCSharp.HttpUserAgentParser.MemoryCache` | -| [![MyCSharp.HttpUserAgentParser.AspNetCore](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser.AspNetCore.svg?logo=nuget&label=MyCSharp.HttpUserAgentParser.AspNetCore)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) | `dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore` | +| Package | Version | Downloads | Install | +| --- | --- | --- | --- | +| **[MyCSharp.HttpUserAgentParser](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser)**
Core parser | [![NuGet](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser?logo=nuget&label=nuget&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser) | [![Downloads](https://img.shields.io/nuget/dt/MyCSharp.HttpUserAgentParser?label=downloads&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser) | `dotnet add package MyCSharp.HttpUserAgentParser` | +| **[MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache)**
Caching with `IMemoryCache` | [![NuGet](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser.MemoryCache?logo=nuget&label=nuget&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache) | [![Downloads](https://img.shields.io/nuget/dt/MyCSharp.HttpUserAgentParser.MemoryCache?label=downloads&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache) | `dotnet add package MyCSharp.HttpUserAgentParser.MemoryCache` | +| **[MyCSharp.HttpUserAgentParser.AspNetCore](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore)**
ASP.NET Core integration | [![NuGet](https://img.shields.io/nuget/v/MyCSharp.HttpUserAgentParser.AspNetCore?logo=nuget&label=nuget&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) | [![Downloads](https://img.shields.io/nuget/dt/MyCSharp.HttpUserAgentParser.AspNetCore?label=downloads&color=004880)](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.AspNetCore) | `dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore` | +The NuGet packages target .NET 8, 9, 10, and 11. Building the solution requires the .NET 11 SDK. ## Usage diff --git a/res/httpuseragentparser-logo.png b/res/httpuseragentparser-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..6b4d6d71e49c910927fd804c1e28c8b42d1a11f7 GIT binary patch literal 250705 zcmb4KV`H3M*Nttbv2B};n>2P~Pa3Pi#7Se@Mq}GH8k-F#Hr~0PfAD^pnNQc8YoC4g zUTf`jet%b%MMe681OWkoDlaFk1_1#D{s{$v00;iM^IUv^fP{dMmzL1*TszP9$THOY z`_bc_>%4w9Sp+Tb@A}IjbgQ_mE{~ke9n+hQt)S-cuQsrov5d{MFI4*L_Y;KtM=Ux2 z?`m?{ljbk>$LC!@V3rH$ZY(=pC{f-yCHIvuYoqOW!{uT1OxI52Ocz7fJpL=*|KsB# zfwn*q!*F1fGLpI8a7D=#k@A>FYgx9|wLGtmqg5-Bjwpo%1%E@6R?p{uPZnCJPU@S{ z45aaWJh6_Afe;^CHZ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$>|U`7De?;KXiUU7WxJK<28=}L{|B(;3m{VS)t4`|nd z-FFSH#!Y@f(=+hnHR3~lk1>W$s7EH+ksVrEDsVGB?4dObIQ+Oec+6=so*B0p)1PaR zPu(&oXux7N;0U+MeI184dD{rI>tQd>dQq+`m+ zGDH+sQaJKOl-`m18Eh5iQH{YqCo4;pyM>9lVAz#>e4|S7b-(zH!dQAuyur{=Of`8e zRt&WO-B1g8F4vse8dQSow}u*ILgpC=__d5#&gK10t8G%W%*jEbjpQ+qO{+5gO@xQq zpQwCEvAQr?J7V`Cw2FGeG24DFuKvfFu4(`vEwuX&U=chY=?25$(d|cqP6B37gHqfH z6ib-_N0f`)umx1YRbC}Zx}C1C;fNMN=iGU>d`=5^!s`pm;O2aIUvI7bUT(g`fp_LghvbG;Dm?qcb$WMx{Cz1S zV#qhOBD)|bE@b?pvoAYji!WSM{m0yBX7=69i*)sNL+6?bUuxn{6*l*cuwW@-*qmwm z)WY_aWM#_NuTAeMcz=$kHXl1eD~-QoQ>h3!NgP`<)^&~g^2I=2gR@=9pwTLRIOi3Z zkY*BA;k3Ia@8Mb*@c8dW+DJz*sUu(4rm*0IwXPVQAAfHBKE0H8`aa=QWDN6g9O Date: Tue, 24 Nov 2026 11:13:13 +0100 Subject: [PATCH 20/41] chore(package): update NuGet package icon and path --- Directory.Build.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index f853268..fa39212 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -59,12 +59,12 @@ MIT UserAgent, User Agent, Parse, Browser, Client, Detector, Detection, Console, ASP, Desktop, Mobile - mycsharpde-logo-nuget.png + httpuseragentparser-logo.png - + - + From dd7d95e9cb9faf05f9cb0bf8ce8479729d2dec8a Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 18:28:31 +0100 Subject: [PATCH 21/41] feat(docs): add library comparison chart for .NET 11 --- README.md | 5 +- .../library-comparison-net11-dark.svg | 80 ++++ docs/benchmarks/library-comparison-net11.svg | 394 ++++-------------- 3 files changed, 163 insertions(+), 316 deletions(-) create mode 100644 docs/benchmarks/library-comparison-net11-dark.svg diff --git a/README.md b/README.md index db09186..91825b6 100644 --- a/README.md +++ b/README.md @@ -485,7 +485,10 @@ Full-catalog means on the other supported runtimes were 193.01 ns (.NET 8), 196. BenchmarkDotNet ShortRun, three warm-ups and three measured iterations. UAParser 3.1.47 and DeviceDetector.NET 6.5.0 use the calls listed below. The crawler header in this comparison is `APIs-Google`. -![Mean parse times for Chrome on Windows and APIs-Google by library and operation, on a logarithmic axis. Exact times follow in the table.](docs/benchmarks/library-comparison-net11.svg) + + + Mean parse times for Chrome on Windows and APIs-Google by library and operation, as columns on a linear axis. MyCSharp's columns are too short to draw next to UAParser and DeviceDetector.NET. Exact times follow in the table. + | Library | Measured operation | Chrome on Windows | Allocated | APIs-Google | Allocated | | --- | --- | ---: | ---: | ---: | ---: | diff --git a/docs/benchmarks/library-comparison-net11-dark.svg b/docs/benchmarks/library-comparison-net11-dark.svg new file mode 100644 index 0000000..917d00a --- /dev/null +++ b/docs/benchmarks/library-comparison-net11-dark.svg @@ -0,0 +1,80 @@ + +Library comparison on .NET 11 +Linear column charts of mean time per call. Single parse with setup: MyCSharp 246 ns and 104 ns, UAParser 9.41 ms and 9.34 ms, DeviceDetector.NET 5.70 ms and 7.33 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 19.4 ns and 12.7 ns, UAParser reused compiled parser 124 µs and 110 µs. + +Mean time per call on .NET 11 +Linear scale, lower is better. Each panel has its own axis. + +Chrome on Windows + +APIs-Google +Single parse, including each library's setup +0 + +2 ms + +4 ms + +6 ms + +8 ms + +10 ms + +246 ns + +104 ns +MyCSharp +Parse + +Bars too short to draw +at this scale: +23,000× to 90,000× +faster + + +9.41 ms + +9.34 ms +UAParser +GetDefault + Parse + +5.70 ms + +7.33 ms +DeviceDetector.NET +New detector + Parse + +Repeated parse with reused state +0 + +25 µs + +50 µs + +75 µs + +100 µs + +125 µs + +19.4 ns + +12.7 ns +MyCSharp +Result cache hit + +Bars too short to draw +at this scale: +6,400× to 8,700× +faster + + +124 µs + +110 µs +UAParser +Reused compiled parser + +BenchmarkDotNet ShortRun, UAParser 3.1.47, DeviceDetector.NET 6.5.0. Exact times and allocations are in the table below. + diff --git a/docs/benchmarks/library-comparison-net11.svg b/docs/benchmarks/library-comparison-net11.svg index 9aa1ef7..4918bbf 100644 --- a/docs/benchmarks/library-comparison-net11.svg +++ b/docs/benchmarks/library-comparison-net11.svg @@ -1,316 +1,80 @@ - - - Library benchmarks on .NET 11 - - - - - Library benchmarks on .NET 11 - Mean time per call for Chrome on Windows and APIs-Google. The horizontal axis is logarithmic and begins at one nanosecond. - image/svg+xml - - - Matplotlib v3.10.9, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - 1 ns - - - - - - - - - 10 ns - - - - - - - - - 100 ns - - - - - - - - - 1 µs - - - - - - - - - 10 µs - - - - - - - - - 100 µs - - - - - - - - - 1 ms - - - - - - - - - 10 ms - - - - Mean time per call (logarithmic scale) - - - - - - - MyCSharp - Parse - - - - - - UAParser - GetDefault + Parse - - - - - - DeviceDetector.NET - New detector + Parse - - - - - - MyCSharp - Result cache hit - - - - - - UAParser - Reused compiled parser - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 246 ns - - - 9.41 ms - - - 5.7 ms - - - 19.4 ns - - - 124 µs - - - 104 ns - - - 9.34 ms - - - 7.33 ms - - - 12.7 ns - - - 110 µs - - - - - - - Chrome on Windows - - - - - - APIs-Google - - - - - - - - - + +Library comparison on .NET 11 +Linear column charts of mean time per call. Single parse with setup: MyCSharp 246 ns and 104 ns, UAParser 9.41 ms and 9.34 ms, DeviceDetector.NET 5.70 ms and 7.33 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 19.4 ns and 12.7 ns, UAParser reused compiled parser 124 µs and 110 µs. + +Mean time per call on .NET 11 +Linear scale, lower is better. Each panel has its own axis. + +Chrome on Windows + +APIs-Google +Single parse, including each library's setup +0 + +2 ms + +4 ms + +6 ms + +8 ms + +10 ms + +246 ns + +104 ns +MyCSharp +Parse + +Bars too short to draw +at this scale: +23,000× to 90,000× +faster + + +9.41 ms + +9.34 ms +UAParser +GetDefault + Parse + +5.70 ms + +7.33 ms +DeviceDetector.NET +New detector + Parse + +Repeated parse with reused state +0 + +25 µs + +50 µs + +75 µs + +100 µs + +125 µs + +19.4 ns + +12.7 ns +MyCSharp +Result cache hit + +Bars too short to draw +at this scale: +6,400× to 8,700× +faster + + +124 µs + +110 µs +UAParser +Reused compiled parser + +BenchmarkDotNet ShortRun, UAParser 3.1.47, DeviceDetector.NET 6.5.0. Exact times and allocations are in the table below. From 05ef3b0e65d2c3c76d8a17a086ab3b6e57b6e76a Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 18:52:56 +0100 Subject: [PATCH 22/41] feat: add feedback --- src/HttpUserAgentParser.AspNetCore/{readme.md => README.md} | 0 src/HttpUserAgentParser.MemoryCache/{readme.md => README.md} | 0 src/HttpUserAgentParser/{readme.md => README.md} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/HttpUserAgentParser.AspNetCore/{readme.md => README.md} (100%) rename src/HttpUserAgentParser.MemoryCache/{readme.md => README.md} (100%) rename src/HttpUserAgentParser/{readme.md => README.md} (100%) diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/README.md similarity index 100% rename from src/HttpUserAgentParser.AspNetCore/readme.md rename to src/HttpUserAgentParser.AspNetCore/README.md diff --git a/src/HttpUserAgentParser.MemoryCache/readme.md b/src/HttpUserAgentParser.MemoryCache/README.md similarity index 100% rename from src/HttpUserAgentParser.MemoryCache/readme.md rename to src/HttpUserAgentParser.MemoryCache/README.md diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/README.md similarity index 100% rename from src/HttpUserAgentParser/readme.md rename to src/HttpUserAgentParser/README.md From 876111f8b31d2e1a7706f52874c4a2dbbe1b418e Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 18:53:05 +0100 Subject: [PATCH 23/41] refactor(telemetry): clean up telemetry comments and structure refactor(parser): simplify user agent parsing logic refactor(cache): improve cache handling and telemetry integration style(docs): update documentation for clarity and consistency chore(project): rename README.md for consistency --- .../HttpUserAgentParser.AspNetCore.csproj | 4 +- .../HttpUserAgentParserAccessor.cs | 9 +--- .../HttpUserAgentParserContextAccessor.cs | 3 -- ...ttpUserAgentParserAspNetCoreEventSource.cs | 27 +---------- .../HttpUserAgentParserAspNetCoreMeters.cs | 18 -------- .../HttpUserAgentParserAspNetCoreTelemetry.cs | 45 +------------------ .../HttpUserAgentParser.MemoryCache.csproj | 4 +- ...HttpUserAgentParserMemoryCachedProvider.cs | 18 +------- ...tpUserAgentParserMemoryCacheEventSource.cs | 27 +---------- .../HttpUserAgentParserMemoryCacheMeters.cs | 5 +-- ...HttpUserAgentParserMemoryCacheTelemetry.cs | 21 +-------- ...serAgentParserMemoryCacheTelemetryState.cs | 16 +------ .../HttpUserAgentParser.cs | 18 ++------ .../HttpUserAgentParser.csproj | 4 +- .../HttpUserAgentRobotSet.cs | 12 ----- src/HttpUserAgentParser/HttpUserAgentRules.cs | 33 ++------------ .../PriorityTokenMatcher.cs | 32 +------------ .../HttpUserAgentParserCachedProvider.cs | 13 +----- .../HttpUserAgentParserCacheMeterGuard.cs | 6 --- .../HttpUserAgentParserEventSource.cs | 41 +---------------- .../HttpUserAgentParserMeterRegistration.cs | 28 +++--------- .../Telemetry/HttpUserAgentParserMeters.cs | 30 +------------ .../Telemetry/HttpUserAgentParserTelemetry.cs | 36 +-------------- .../HttpUserAgentParserTelemetryState.cs | 10 +---- 24 files changed, 41 insertions(+), 419 deletions(-) diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj index 8a27dc0..699aaad 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj @@ -11,11 +11,11 @@ true - readme.md + README.md - + diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs index a5a2a70..16690d9 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs @@ -19,16 +19,11 @@ public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAg { private readonly IHttpUserAgentParserProvider _httpUserAgentParser = httpUserAgentParser; - /// - /// Returns the User-Agent header of - /// + /// public string? GetHttpContextUserAgent(HttpContext httpContext) => httpContext.GetUserAgentString(); - /// - /// Returns the parsed of , - /// or if the request has no User-Agent header or only white space - /// + /// public HttpUserAgentInformation? Get(HttpContext httpContext) { string? httpUserAgent = GetHttpContextUserAgent(httpContext); diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs index 25566bf..21ff58a 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserContextAccessor.cs @@ -9,9 +9,6 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore; /// User Agent parser accessor for an explicitly passed and for the current request, /// which is resolved via . ///

lIM3b{0v$1n_w0Vxa29$2)S?#?*kEC}}`ksw{UT0S3 zw-^o~L%-5?MO71`-24|)afdDkYaVm4UZ^nV-GO#n@wp;_k~-7pBStx*cgsN5G1lKO1)Gt$;|UD`5f7e$_MGD@k$aIt zC5F@5O8;^0gXQN6* zBc$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// Creates a new instance of -/// public class HttpUserAgentParserContextAccessor(IHttpUserAgentParserProvider httpUserAgentParser, IHttpContextAccessor httpContextAccessor) : HttpUserAgentParserAccessor(httpUserAgentParser), IHttpUserAgentParserContextAccessor { diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs index c0f83ca..5a287a5 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreEventSource.cs @@ -15,20 +15,12 @@ public sealed class HttpUserAgentParserAspNetCoreEventSource : EventSource ///
public const string EventSourceName = "MyCSharp.HttpUserAgentParser.AspNetCore"; - /// - /// Singleton instance of the EventSource. - /// internal static HttpUserAgentParserAspNetCoreEventSource Log { get; } = new(); private readonly IncrementingEventCounter _userAgentPresent; private readonly IncrementingEventCounter _userAgentMissing; - /// - /// Initializes all EventCounters used by this EventSource. - /// - /// - /// Use ; the constructor is only accessible for tests. - /// + // Tests construct and dispose their own event source. internal HttpUserAgentParserAspNetCoreEventSource() { _userAgentPresent = new IncrementingEventCounter("useragent-present", this) @@ -44,9 +36,6 @@ internal HttpUserAgentParserAspNetCoreEventSource() }; } - /// - /// Records a request with a User-Agent header. - /// [NonEvent] internal void UserAgentPresent() { @@ -56,9 +45,6 @@ internal void UserAgentPresent() } } - /// - /// Records a request without a User-Agent header. - /// [NonEvent] internal void UserAgentMissing() { @@ -68,16 +54,7 @@ internal void UserAgentMissing() } } - /// - /// Releases all EventCounter resources used by this EventSource. - /// - /// - /// when called from ; - /// when called from a finalizer. - /// - /// - /// Follows the pattern of the EventCounters documentation: the counters are released in both cases. - /// + /// protected override void Dispose(bool disposing) { _userAgentPresent.Dispose(); diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs index 1c0f7d7..4f15339 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreMeters.cs @@ -14,14 +14,8 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// internal static class HttpUserAgentParserAspNetCoreMeters { - /// - /// Name of the meter used to publish AspNetCore User-Agent metrics. - /// private const string MeterNameSuffix = "http_user_agent_parser.aspnetcore"; - /// - /// Name of the meter used to publish AspNetCore User-Agent metrics. - /// public const string MeterName = "mycsharp." + MeterNameSuffix; /// @@ -52,26 +46,14 @@ public static string GetMeterName(string? meterPrefix) /// public static void EnableOwnedMeter(string meterName) => s_registration.Use(meter: null, meterName); - /// - /// Records a metric indicating that a User-Agent header was present. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UserAgentPresent() => s_registration.Current?.UserAgentPresent.Add(1); - /// - /// Records a metric indicating that a User-Agent header was missing. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UserAgentMissing() => s_registration.Current?.UserAgentMissing.Add(1); - /// - /// Resets static state to support isolated unit tests. - /// public static void ResetForTests() => s_registration.ResetForTests(); - /// - /// The instruments of one meter. - /// private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstruments(meter) { private Counter? _userAgentPresent; diff --git a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs index fa139e2..565dd92 100644 --- a/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs +++ b/src/HttpUserAgentParser.AspNetCore/Telemetry/HttpUserAgentParserAspNetCoreTelemetry.cs @@ -8,39 +8,14 @@ namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; /// /// Opt-in switch for AspNetCore package telemetry. /// -/// -/// Controls whether telemetry is emitted via event counters and/or meters. -/// The state is evaluated using lock-free, thread-safe reads and is intended -/// to be checked on hot paths. -/// internal static class HttpUserAgentParserAspNetCoreTelemetry { - /// - /// Flag indicating that event counter–based telemetry is enabled. - /// private const int EventCountersFlag = 1; - /// - /// Flag indicating that meter-based telemetry is enabled. - /// private const int MetersFlag = 2; - /// - /// Bit field storing the currently enabled telemetry backends. - /// - /// - /// Accessed using volatile reads to ensure cross-thread visibility - /// without requiring synchronization. - /// private static int s_enabledFlags; - /// - /// Gets a value indicating whether any telemetry backend is enabled. - /// - /// - /// Returns if at least one telemetry backend - /// has been enabled. - /// public static bool IsEnabled => Volatile.Read(ref s_enabledFlags) != 0; @@ -49,8 +24,7 @@ public static bool IsEnabled ///
public static void Enable() { - // Force EventSource construction at enable-time so listeners can subscribe deterministically. - // This avoids CI-only timing races where first telemetry events happen before listener attachment. + // Give listeners a chance to subscribe before recording the first event. _ = HttpUserAgentParserAspNetCoreEventSource.Log; Interlocked.Or(ref s_enabledFlags, EventCountersFlag); } @@ -69,13 +43,6 @@ public static void EnableMetersWithName(string meterName) internal static void MarkMetersEnabled() => Interlocked.Or(ref s_enabledFlags, MetersFlag); - /// - /// Records telemetry indicating that a User-Agent header was present. - /// - /// - /// Emits telemetry only for the enabled backends (event counters and/or meters). - /// The method is optimized for hot paths and performs a single volatile flag read. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UserAgentPresent() { @@ -91,13 +58,6 @@ public static void UserAgentPresent() } } - /// - /// Records telemetry indicating that a User-Agent header was missing. - /// - /// - /// Emits telemetry only for the enabled backends (event counters and/or meters). - /// The method is optimized for hot paths and performs a single volatile flag read. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UserAgentMissing() { @@ -113,9 +73,6 @@ public static void UserAgentMissing() } } - /// - /// Resets telemetry state for unit tests. - /// public static void ResetForTests() { Volatile.Write(ref s_enabledFlags, 0); diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj index 3a072ca..cc2968b 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj @@ -11,11 +11,11 @@ true - readme.md + README.md - + diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index 96cc00e..e3f77c1 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -8,7 +8,6 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache; -/// /// /// that caches the results in an . /// @@ -38,7 +37,7 @@ public IDisposable RegisterChangeCallback(Action callback, object? stat private readonly HttpUserAgentParserMemoryCachedProviderOptions _options; /// - /// Creates a new instance of . + /// Creates a provider with its own . /// /// The options used to set expiration and size limit public HttpUserAgentParserMemoryCachedProvider(HttpUserAgentParserMemoryCachedProviderOptions options) @@ -50,16 +49,11 @@ public HttpUserAgentParserMemoryCachedProvider(HttpUserAgentParserMemoryCachedPr HttpUserAgentParserMemoryCacheTelemetryState.Register(this); } - /// - /// Number of cached user agents. - /// internal int CacheEntryCount => _memoryCache.Count; /// /// - /// The user agent string itself is the cache key (ordinal comparison), so a cache hit does not allocate. - /// Telemetry checks use a volatile flag to ensure zero overhead when disabled; the cache size is counted only - /// when a cache size instrument is observed. + /// The cache uses the exact header as its key. Concurrent misses for the same header can cause multiple parses. /// public HttpUserAgentInformation Parse(string userAgent) { @@ -86,14 +80,6 @@ public void Dispose() GC.SuppressFinalize(this); } - /// - /// Parses the user agent and adds the result to the cache (miss path). - /// - /// - /// Every entry gets all - /// (expiration, priority, expiration tokens, eviction callbacks) and the size 1, unless the options specify a size. - /// Like other cache implementations, concurrent misses of the same user agent may parse it more than once; the last result is kept. - /// private HttpUserAgentInformation ParseAndCache(string userAgent) { HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs index 7029dfa..e01445f 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheEventSource.cs @@ -15,21 +15,13 @@ public sealed class HttpUserAgentParserMemoryCacheEventSource : EventSource ///
public const string EventSourceName = "MyCSharp.HttpUserAgentParser.MemoryCache"; - /// - /// Singleton instance of the EventSource. - /// internal static HttpUserAgentParserMemoryCacheEventSource Log { get; } = new(); private readonly IncrementingEventCounter _cacheHit; private readonly IncrementingEventCounter _cacheMiss; private readonly PollingCounter _cacheSize; - /// - /// Initializes all EventCounters and polling counters used by this EventSource. - /// - /// - /// Use ; the constructor is only accessible for tests. - /// + // Tests construct and dispose their own event source. internal HttpUserAgentParserMemoryCacheEventSource() { _cacheHit = new IncrementingEventCounter("cache-hit", this) @@ -51,9 +43,6 @@ internal HttpUserAgentParserMemoryCacheEventSource() }; } - /// - /// Records a cache hit. - /// [NonEvent] internal void CacheHit() { @@ -63,9 +52,6 @@ internal void CacheHit() } } - /// - /// Records a cache miss. - /// [NonEvent] internal void CacheMiss() { @@ -75,16 +61,7 @@ internal void CacheMiss() } } - /// - /// Releases all EventCounter and PollingCounter resources used by this EventSource. - /// - /// - /// when called from ; - /// when called from a finalizer. - /// - /// - /// Follows the pattern of the EventCounters documentation: the counters are released in both cases. - /// + /// protected override void Dispose(bool disposing) { _cacheHit.Dispose(); diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs index 811a75b..18f3e3b 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheMeters.cs @@ -57,9 +57,6 @@ public static string GetMeterName(string? meterPrefix) public static void ResetForTests() => s_registration.ResetForTests(); - /// - /// The instruments of one meter. - /// private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstruments(meter) { private Counter? _cacheHit; @@ -75,7 +72,7 @@ public override void CreateMissingInstruments() CreateInstrument(ref _cacheHit, Meter.CreateCounter, "cache.hit", "{call}", "Cache hit"); CreateInstrument(ref _cacheMiss, Meter.CreateCounter, "cache.miss", "{call}", "Cache miss"); - // Observable instruments are not shared by the meter: created at most once, also if a listener threw. + // A listener can throw after publication. Creating the gauge again would register a second callback. if (Interlocked.Exchange(ref _cacheSizeCreated, 1) == 0) { _ = Meter.CreateObservableGauge(name: "cache.size", observeValues: ObserveCacheSize, unit: "{entry}", description: "Cache size"); diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs index 5b1a6df..a6a79e9 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetry.cs @@ -10,20 +10,11 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; ///
internal static class HttpUserAgentParserMemoryCacheTelemetry { - // Bit flags to track which telemetry systems are enabled. - // This allows us to support both EventCounters and Meters simultaneously with a single check. private const int EventCountersFlag = 1; private const int MetersFlag = 2; - // Volatile integer used as a bitmask. - // Volatile.Read is used to ensure we get the latest value without the overhead of a full lock, - // making the "is telemetry enabled?" check extremely cheap on the hot path. private static int s_enabledFlags; - /// - /// Fast check if ANY telemetry is enabled. - /// Used to guard the entire telemetry block to minimize overhead when not in use. - /// public static bool IsEnabled => Volatile.Read(ref s_enabledFlags) != 0; /// @@ -31,8 +22,7 @@ internal static class HttpUserAgentParserMemoryCacheTelemetry /// public static void Enable() { - // Force EventSource construction at enable-time so listeners can subscribe deterministically. - // This avoids CI-only timing races where first telemetry events happen before listener attachment. + // Give listeners a chance to subscribe before recording the first event. _ = HttpUserAgentParserMemoryCacheEventSource.Log; Interlocked.Or(ref s_enabledFlags, EventCountersFlag); } @@ -51,9 +41,6 @@ public static void EnableMetersWithName(string meterName) internal static void MarkMetersEnabled() => Interlocked.Or(ref s_enabledFlags, MetersFlag); - /// - /// Records a cache hit. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CacheHit() { @@ -69,9 +56,6 @@ public static void CacheHit() } } - /// - /// Records a cache miss. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CacheMiss() { @@ -87,9 +71,6 @@ public static void CacheMiss() } } - /// - /// Resets telemetry state for unit tests. - /// public static void ResetForTests() { Volatile.Write(ref s_enabledFlags, 0); diff --git a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs index ee00870..5085979 100644 --- a/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs +++ b/src/HttpUserAgentParser.MemoryCache/Telemetry/HttpUserAgentParserMemoryCacheTelemetryState.cs @@ -5,29 +5,17 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache.Telemetry; /// -/// Knows the live instances to report their cache size. +/// Tracks providers from construction so the reported cache size includes entries added before telemetry was enabled. +/// Weak references let providers be collected between observations. /// -/// -/// Every provider registers itself when it is created, independent of whether telemetry is enabled, so the -/// reported size includes entries cached before telemetry was enabled. Providers are referenced weakly. -/// internal static class HttpUserAgentParserMemoryCacheTelemetryState { private static readonly ConditionalWeakTable s_providers = new(); - /// - /// Registers a provider whose entries count towards . - /// public static void Register(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Add(provider, value: null); - /// - /// Removes a disposed provider, whose entries no longer count. - /// public static void Unregister(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.Remove(provider); - /// - /// Gets whether the entries of count towards . - /// public static bool IsRegistered(HttpUserAgentParserMemoryCachedProvider provider) => s_providers.TryGetValue(provider, out _); /// diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 8603c83..25313f7 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -27,8 +27,7 @@ public static class HttpUserAgentParser /// Parses given user agent /// /// - /// If telemetry is enabled, this method will emit metrics for parse requests and duration. - /// The telemetry check is designed to be zero-overhead when disabled (using a volatile boolean check). + /// When telemetry is enabled, the parser records requests and measures duration for active listeners. /// public static HttpUserAgentInformation Parse(string userAgent) => Parse(userAgent, HttpUserAgentRules.RobotSet); @@ -137,6 +136,7 @@ private static T Detect(string userAgent, TState state, Detector= 0; i = candidates.Next()) { (string token, HttpUserAgentPlatformInformation platform) = rules[i]; + Debug.Assert(token.Length > 0); int index = ua.IndexOf(token, StringComparison.OrdinalIgnoreCase); while (index >= 0) { @@ -204,9 +204,6 @@ private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua return null; } - /// - /// Reads the version of a browser rule whose detect token starts a token at first. - /// private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectToken, int detectIndex, string? versionToken, out Range version) { if (versionToken is null) @@ -215,8 +212,7 @@ private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectTo return TryReadVersion(ua, detectToken, detectIndex, allowSpace: false, out version); } - // A separate version token after the detect token ("Opera/9.80 ... Version/12.16", "Trident/7.0; rv:11.0"); with the same - // token as the detect token (Safari "Version/", "MSIE 6.0") the detect token has been found already. + // Safari's "Version/" and IE's "MSIE" identify both the browser and its version. if (string.Equals(detectToken, versionToken, StringComparison.Ordinal)) { return TryReadVersion(ua, detectToken, detectIndex, allowSpace: true, out version); @@ -261,6 +257,7 @@ private static bool TryReadBrowserVersion(ReadOnlySpan ua, string detectTo /// private static bool TryReadVersion(ReadOnlySpan ua, string token, int index, bool allowSpace, out Range version) { + Debug.Assert(token.Length > 0); bool separatorIncluded = token[^1] is '/' or ':'; do { @@ -302,9 +299,6 @@ private static bool TryReadVersion(ReadOnlySpan ua, string token, int inde return false; } - /// - /// Returns whether a token at starts a token of its own (at the beginning or after a delimiter). - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsTokenStart(ReadOnlySpan ua, int index) => index == 0 || s_productTokenDelimiters.Contains(ua[index - 1]); @@ -312,10 +306,6 @@ private static bool IsTokenStart(ReadOnlySpan ua, int index) private static bool IsProductNameEnd(ReadOnlySpan ua, int end) => end == ua.Length || ua[end] == '/' || s_productTokenDelimiters.Contains(ua[end]); - /// - /// Returns whether separates a product name from its version in Token 1.2 - /// (+ stands for a space in URL-encoded logs). - /// private static bool IsSpace(char c) => c is ' ' or '\t'; /// diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.csproj b/src/HttpUserAgentParser/HttpUserAgentParser.csproj index fcfa165..bb22df8 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.csproj +++ b/src/HttpUserAgentParser/HttpUserAgentParser.csproj @@ -11,11 +11,11 @@ true - readme.md + README.md - + diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs index 2d46b8b..4ab04f6 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -15,9 +15,6 @@ internal sealed class HttpUserAgentRobotSet private readonly int _decodedStart; private readonly int[] _literalPlusRules; - /// - /// Creates the set for in priority order; the array must not be changed afterwards. - /// public HttpUserAgentRobotSet((string Key, string Value)[] robots) { ReadOnlyEntries = [.. robots]; @@ -72,19 +69,10 @@ private int FindAfterFirst(ReadOnlySpan decoded) /// public object CacheGeneration { get; } = new(); - /// - /// Gets the robots as read-only list for . - /// public IReadOnlyList<(string Key, string Value)> ReadOnlyEntries { get; } - /// - /// Gets the keys in priority order. - /// public string[] Keys { get; } - /// - /// Gets the matcher over . - /// public PriorityTokenMatcher Matcher { get; } /// diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 116e7ac..0107360 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -13,13 +13,11 @@ namespace MyCSharp.HttpUserAgentParser; /// internal static class HttpUserAgentRules { - /// Marker type of the robot . + // Separate value types give the JIT a distinct matcher profile for each rule set. internal readonly struct RobotDetector; - /// Marker type of the robot anchor . internal readonly struct RobotAnchorDetector; - /// Marker type of the mobile device . internal readonly struct MobileDetector; /// @@ -29,20 +27,16 @@ internal static class HttpUserAgentRules [ // Compatibility tokens on Windows Phone can identify both desktop Windows and Android. ("windows phone", new(HttpUserAgentPlatformRegexId.WindowsPhone, "Windows Phone", HttpUserAgentPlatformType.Windows)), - // Most common: Windows (specific versions before generic) ("windows nt 10.0", new(HttpUserAgentPlatformRegexId.WindowsNt100, "Windows 10", HttpUserAgentPlatformType.Windows)), ("windows nt 6.1", new(HttpUserAgentPlatformRegexId.WindowsNt61, "Windows 7", HttpUserAgentPlatformType.Windows)), ("windows nt 6.3", new(HttpUserAgentPlatformRegexId.WindowsNt63, "Windows 8.1", HttpUserAgentPlatformType.Windows)), ("windows nt 6.2", new(HttpUserAgentPlatformRegexId.WindowsNt62, "Windows 8", HttpUserAgentPlatformType.Windows)), ("windows nt 6.0", new(HttpUserAgentPlatformRegexId.WindowsNt60, "Windows Vista", HttpUserAgentPlatformType.Windows)), - // Android (very common on mobile) ("android", new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android)), - // iOS devices (very common) ("iphone", new(HttpUserAgentPlatformRegexId.IPhone, "iOS", HttpUserAgentPlatformType.IOS)), ("ipad", new(HttpUserAgentPlatformRegexId.IPad, "iOS", HttpUserAgentPlatformType.IOS)), ("ipod", new(HttpUserAgentPlatformRegexId.IPod, "iOS", HttpUserAgentPlatformType.IOS)), ("cros", new(HttpUserAgentPlatformRegexId.CrOS, "ChromeOS", HttpUserAgentPlatformType.ChromeOS)), - // Mac OS (common) ("os x", new(HttpUserAgentPlatformRegexId.OsX, "Mac OS X", HttpUserAgentPlatformType.MacOS)), // A distribution can also identify itself as GNU/Linux. ("debian", new(HttpUserAgentPlatformRegexId.Debian, "Debian", HttpUserAgentPlatformType.Linux)), @@ -258,21 +252,12 @@ internal static class HttpUserAgentRules "measurement", "barkrowler", "brightedge", "cotoyogi", "geedo", "ahrefs", "cohere", "yeti/", ]; - /// - /// The default robots with their matchers. - /// internal static HttpUserAgentRobotSet DefaultRobotSet { get; } = new(DefaultRobots); private static HttpUserAgentRobotSet s_robotSet = DefaultRobotSet; - /// - /// Gets the robots the parser detects. - /// internal static HttpUserAgentRobotSet RobotSet => Volatile.Read(ref s_robotSet); - /// - /// Replaces the robots the parser detects. - /// internal static void SetRobotSet(HttpUserAgentRobotSet robotSet) => Volatile.Write(ref s_robotSet, robotSet); /// @@ -297,17 +282,8 @@ internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAncho /// Mobile device rules in priority order: the most specific match wins. /// /// - /// - /// Legacy devices and browsers - /// Devices and manufacturers (e.g. "Samsung" before the "Android" operating system) - /// Operating systems - /// Mobile browsers - /// Carriers and other - /// Generic fallbacks ("mobile", ...) - /// - /// A token that contains another token comes first ("palmsource" before "palm", "nintendo dsi" before "nintendo ds", - /// "SymbianOS" before "symbian"). - /// The order is explicit on purpose: the enumeration order of a (frozen) dictionary is unspecified and must not decide the priority. + /// Keep specific tokens ahead of their substrings, such as "nintendo dsi" before "nintendo ds". + /// Frozen dictionary enumeration does not preserve this priority. /// internal static (string Key, string Value)[] Mobiles { get; } = [ @@ -396,9 +372,6 @@ internal static string[] CreateRobotAnchors(string[] keys, string[] curatedAncho internal static string[] MobileKeys { get; } = Array.ConvertAll(Mobiles, static rule => rule.Key); - /// - /// Mobile token matcher. - /// internal static PriorityTokenMatcher MobileMatcher { get; } = new(MobileKeys); /// diff --git a/src/HttpUserAgentParser/PriorityTokenMatcher.cs b/src/HttpUserAgentParser/PriorityTokenMatcher.cs index 97c3809..072cbfa 100644 --- a/src/HttpUserAgentParser/PriorityTokenMatcher.cs +++ b/src/HttpUserAgentParser/PriorityTokenMatcher.cs @@ -17,14 +17,9 @@ namespace MyCSharp.HttpUserAgentParser; /// implementations of that detector instead of mixing the profiles of all detectors. /// /// -/// /// On .NET 9 and later, consecutive tokens are grouped into small sets. /// A single vectorized pass rejects a whole group, so only groups that may contain a match are checked /// token by token. Groups never reorder tokens, which preserves the priority semantics of a sequential scan. -/// -/// -/// See PriorityTokenGroup for the group layout. -/// /// internal sealed class PriorityTokenMatcher where TDetector : struct @@ -35,11 +30,7 @@ internal sealed class PriorityTokenMatcher private readonly PriorityTokenGroup[] _groups; #endif - /// - /// Creates a matcher for in priority order. - /// - /// Tokens, highest priority first. - /// Token indices that must start a new group, e.g. to give a very frequent token its own group. + // Explicit group boundaries let frequent tokens be checked on their own. public PriorityTokenMatcher(string[] tokens, params ReadOnlySpan groupStarts) { _tokens = tokens; @@ -50,25 +41,15 @@ public PriorityTokenMatcher(string[] tokens, params ReadOnlySpan groupStart #endif } - /// - /// Number of tokens. - /// public int Count => _tokens.Length; #if NET9_0_OR_GREATER - /// - /// The token groups. - /// internal ReadOnlySpan Groups => _groups; #endif - /// - /// Returns if any token occurs in . - /// public bool ContainsAny(ReadOnlySpan input) { #if NET9_0_OR_GREATER - // The group filters alone answer the question. foreach (ref readonly PriorityTokenGroup group in _groups.AsSpan()) { if (group.MayMatch(input)) @@ -93,8 +74,6 @@ public bool ContainsAny(ReadOnlySpan input) /// Returns the index of the first token at or after that occurs in , /// or -1 if none occurs. /// - /// The text to search. - /// The first token index to consider. public int Find(ReadOnlySpan input, int startIndex) { string[] tokens = _tokens; @@ -152,9 +131,6 @@ private PriorityTokenGroup(int start, int end, List values, List ShortTokens = [.. shortTokens]; } - /// - /// Index of the first token of the group. - /// public int Start { get; } /// @@ -172,9 +148,6 @@ private PriorityTokenGroup(int start, int end, List values, List /// public string[] ShortTokens { get; } - /// - /// Returns if no token of the group occurs in . - /// public bool MayMatch(ReadOnlySpan input) { if (Values is not null && input.ContainsAny(Values)) @@ -193,9 +166,6 @@ public bool MayMatch(ReadOnlySpan input) return false; } - /// - /// Splits into groups. - /// public static PriorityTokenGroup[] Create(string[] tokens, ReadOnlySpan groupStarts) { List groups = []; diff --git a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs index 7a0948a..6b834aa 100644 --- a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs +++ b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs @@ -10,12 +10,6 @@ namespace MyCSharp.HttpUserAgentParser.Providers; /// public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider { - /// - /// internal cache - /// - /// - /// The key is the exact user agent (ordinal): the result contains the user agent, so a differently cased one is another entry. - /// private sealed class Cache(HttpUserAgentRobotSet robots) { public HttpUserAgentRobotSet Robots { get; } = robots; @@ -45,12 +39,9 @@ private Cache GetCurrentCache() /// public HttpUserAgentParserCachedProvider() => HttpUserAgentParserTelemetryState.Register(this); - /// - /// Parses the user agent or uses the internal cached information - /// + /// /// - /// Telemetry checks use a volatile flag to ensure zero overhead when disabled. The cache size is counted only - /// when a cache size instrument is observed. + /// Cache keys use ordinal comparison because each result retains the original header. /// public HttpUserAgentInformation Parse(string userAgent) { diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs index 3a1bef4..16b681c 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserCacheMeterGuard.cs @@ -41,9 +41,6 @@ internal static class HttpUserAgentParserCacheMeterGuard /// The core package has used . public static void ReserveForMemoryCache(Meter meter) => Reserve(meter, s_memoryCacheMeters, s_coreMeters, CorePackage); - /// - /// Forgets the reservations of the core package (unit tests). - /// public static void ResetCoreForTests() { lock (s_lock) @@ -52,9 +49,6 @@ public static void ResetCoreForTests() } } - /// - /// Forgets the reservations of the MemoryCache package (unit tests). - /// public static void ResetMemoryCacheForTests() { lock (s_lock) diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs index 858ca4e..807e242 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserEventSource.cs @@ -7,11 +7,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// /// EventSource for EventCounters emitted by MyCSharp.HttpUserAgentParser. /// -/// -/// The implementation is designed to keep overhead negligible unless a listener -/// is enabled. All counters are updated using lightweight, non-blocking operations -/// suitable for hot paths. -/// [EventSource(Name = EventSourceName)] public sealed class HttpUserAgentParserEventSource : EventSource { @@ -20,9 +15,6 @@ public sealed class HttpUserAgentParserEventSource : EventSource ///
public const string EventSourceName = "MyCSharp.HttpUserAgentParser"; - /// - /// Singleton instance of the EventSource. - /// internal static HttpUserAgentParserEventSource Log { get; } = new(); private readonly IncrementingEventCounter _parseRequests; @@ -32,15 +24,9 @@ public sealed class HttpUserAgentParserEventSource : EventSource private readonly IncrementingEventCounter _cacheMiss; private readonly PollingCounter _cacheSize; - /// - /// Initializes all EventCounters and polling counters used by this EventSource. - /// - /// - /// Use ; the constructor is only accessible for tests. - /// + // Tests construct and dispose their own event source. internal HttpUserAgentParserEventSource() { - // Parser _parseRequests = new IncrementingEventCounter("parse-requests", this) { DisplayName = "User-Agent parse requests", @@ -53,7 +39,6 @@ internal HttpUserAgentParserEventSource() DisplayUnits = "s", }; - // Providers (cache) _cacheHit = new IncrementingEventCounter("cache-hit", this) { DisplayName = "Cache hit", @@ -76,9 +61,6 @@ internal HttpUserAgentParserEventSource() }; } - /// - /// Records a User-Agent parse request. - /// [NonEvent] internal void ParseRequest() { @@ -88,10 +70,6 @@ internal void ParseRequest() } } - /// - /// Records the duration of a User-Agent parse operation. - /// - /// Elapsed parse time in seconds. [NonEvent] internal void ParseDuration(double seconds) { @@ -101,9 +79,6 @@ internal void ParseDuration(double seconds) } } - /// - /// Records a cache hit. - /// [NonEvent] internal void CacheHit() { @@ -113,9 +88,6 @@ internal void CacheHit() } } - /// - /// Records a cache miss. - /// [NonEvent] internal void CacheMiss() { @@ -125,16 +97,7 @@ internal void CacheMiss() } } - /// - /// Releases all EventCounter and PollingCounter resources used by this EventSource. - /// - /// - /// when called from ; - /// when called from a finalizer. - /// - /// - /// Follows the pattern of the EventCounters documentation: the counters are released in both cases. - /// + /// protected override void Dispose(bool disposing) { _parseRequests.Dispose(); diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs index 18e5248..2fd8c09 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeterRegistration.cs @@ -5,10 +5,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; -/// -/// The instruments of one package on one meter. -/// -/// The meter the instruments belong to. internal abstract class HttpUserAgentParserMeterInstruments(Meter meter) { // Shared across packages. Listener callbacks may synchronously register another package @@ -17,7 +13,7 @@ internal sealed class Publication : IDisposable { private static readonly AsyncLocal s_current = new(); private readonly Publication? _parent = s_current.Value; - private volatile bool _finished; + private bool _finished; public Publication() => s_current.Value = this; @@ -27,7 +23,7 @@ public static bool InProgress { for (Publication? scope = s_current.Value; scope is not null; scope = scope._parent) { - if (!scope._finished) + if (!Volatile.Read(ref scope._finished)) { return true; } @@ -40,14 +36,11 @@ public static bool InProgress public void Dispose() { // ExecutionContext may have been captured by a listener for work that runs later. - _finished = true; + Volatile.Write(ref _finished, true); s_current.Value = _parent; } } - /// - /// Gets the meter the instruments belong to. - /// public Meter Meter { get; } = meter; // An owned meter lives for one registration. Its instruments stay discoverable from @@ -55,13 +48,9 @@ public void Dispose() public bool IsOwned { get; set; } /// - /// Creates the instruments that do not exist yet. + /// A callback may register another meter or throw after publication. + /// Call outside the registration lock and reuse any instruments published by an earlier attempt. /// - /// - /// .NET runs the callbacks while an instrument is created, so listener code - /// runs here and may throw or register meters itself; no lock is held. An instrument that was published before a listener - /// threw exists on the meter even when its factory did not return it. - /// public abstract void CreateMissingInstruments(); protected void CreateInstrument(ref T? field, Func create, string name, string unit, string description) @@ -108,7 +97,6 @@ protected void CreateInstrument(ref T? field, Func /// listeners may register meters of any package without deadlocks. The lock only protects the switch of the state. /// /// -/// The instruments of the package. /// Creates the (still empty) instruments of a meter; must not create instruments itself. /// Reserves a meter for the package before its instruments are created; throws if the meter must not be used. /// Forgets the reservations of the package (unit tests). @@ -117,12 +105,11 @@ internal sealed class HttpUserAgentParserMeterRegistration( Func createInstruments, Action reserve, Action resetReservations, Action markEnabled) where TInstruments : HttpUserAgentParserMeterInstruments { - // Monitor.Wait releases this lock while an independent registration finishes. private readonly object _lock = new(); private readonly HashSet _publishingMeters = new(ReferenceEqualityComparer.Instance); private readonly HashSet _publishingNames = new(StringComparer.Ordinal); - // Keyed by the non-generic base type: the table's value type needs a trimming annotation a generic argument cannot provide. + // The non-generic value type satisfies the table's trimming annotation. private readonly ConditionalWeakTable _instrumentsByMeter = new(); private readonly ConditionalWeakTable.CreateValueCallback _createInstruments = createInstruments.Invoke; @@ -211,9 +198,6 @@ public void Use(Meter? meter, string ownedMeterName) replacedOwnedMeter?.Dispose(); } - /// - /// Resets the registration (unit tests). - /// public void ResetForTests() { Meter? ownedMeter; diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs index 08cb975..bf612be 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserMeters.cs @@ -7,7 +7,6 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// /// System.Diagnostics.Metrics instruments emitted by MyCSharp.HttpUserAgentParser. -/// This is opt-in and designed to keep overhead negligible unless a listener is enabled. /// /// /// See for the registration rules; a replaced meter no longer @@ -15,14 +14,8 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// internal static class HttpUserAgentParserMeters { - /// - /// The meter name used for all instruments. - /// private const string MeterNameSuffix = "http_user_agent_parser"; - /// - /// The meter name used for all instruments. - /// public const string MeterName = "mycsharp." + MeterNameSuffix; /// @@ -43,9 +36,6 @@ public static string GetMeterName(string? meterPrefix) HttpUserAgentParserCacheMeterGuard.ResetCoreForTests, HttpUserAgentParserTelemetry.MarkMetersEnabled); - /// - /// Gets whether meters have been initialized. - /// public static bool IsEnabled => s_registration.Current is not null; /// @@ -63,38 +53,20 @@ public static string GetMeterName(string? meterPrefix) /// public static void EnableOwnedMeter(string meterName) => s_registration.Use(meter: null, meterName); - /// - /// Emits a counter increment for a parse request. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ParseRequest() => s_registration.Current?.ParseRequests.Add(1); - /// - /// Records the parse duration in seconds. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ParseDuration(double seconds) => s_registration.Current?.ParseDuration.Record(seconds); - /// - /// Emits a counter increment for a cache hit. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CacheHit() => s_registration.Current?.CacheHit.Add(1); - /// - /// Emits a counter increment for a cache miss. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CacheMiss() => s_registration.Current?.CacheMiss.Add(1); - /// - /// Resets static state to support isolated unit tests. - /// public static void ResetForTests() => s_registration.ResetForTests(); - /// - /// The instruments of one meter. - /// private sealed class Instruments(Meter meter) : HttpUserAgentParserMeterInstruments(meter) { private Counter? _parseRequests; @@ -118,7 +90,7 @@ public override void CreateMissingInstruments() CreateInstrument(ref _cacheHit, Meter.CreateCounter, "cache.hit", "{call}", "Cache hit"); CreateInstrument(ref _cacheMiss, Meter.CreateCounter, "cache.miss", "{call}", "Cache miss"); - // Observable instruments are not shared by the meter: created at most once, also if a listener threw. + // A listener can throw after publication. Creating the gauge again would register a second callback. if (Interlocked.Exchange(ref _cacheSizeCreated, 1) == 0) { _ = Meter.CreateObservableGauge(name: "cache.size", observeValues: ObserveCacheSize, unit: "{entry}", description: "Cache size"); diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs index 0d4a632..dbd2df9 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetry.cs @@ -7,37 +7,20 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// /// Opt-in switch for core telemetry. -/// Telemetry is disabled by default to ensure zero overhead unless explicitly enabled. /// internal static class HttpUserAgentParserTelemetry { - // Bit flags to track which telemetry systems are enabled. - // This allows us to support both EventCounters and Meters simultaneously with a single check. private const int EventCountersFlag = 1; private const int MetersFlag = 2; - // Volatile integer used as a bitmask. - // Volatile.Read is used to ensure we get the latest value without the overhead of a full lock, - // making the "is telemetry enabled?" check extremely cheap on the hot path. private static int s_enabledFlags; - /// - /// Fast check if ANY telemetry is enabled. - /// Used to guard the entire telemetry block to minimize overhead when not in use. - /// public static bool IsEnabled => Volatile.Read(ref s_enabledFlags) != 0; - /// - /// Checks if EventCounters are specifically enabled. - /// public static bool AreCountersEnabled => (Volatile.Read(ref s_enabledFlags) & EventCountersFlag) != 0 && HttpUserAgentParserEventSource.Log.IsEnabled(); - /// - /// Checks if parse duration should be measured. - /// This is true if either EventCounters are enabled OR if the specific Meter instrument for duration is enabled. - /// public static bool ShouldMeasureParseDuration => AreCountersEnabled || HttpUserAgentParserMeters.IsParseDurationEnabled; @@ -46,8 +29,7 @@ public static bool ShouldMeasureParseDuration /// public static void Enable() { - // Force EventSource construction at enable-time so listeners can subscribe deterministically. - // This avoids CI-only timing races where first telemetry events happen before listener attachment. + // Give listeners a chance to subscribe before recording the first event. _ = HttpUserAgentParserEventSource.Log; Interlocked.Or(ref s_enabledFlags, EventCountersFlag); } @@ -66,9 +48,6 @@ public static void EnableMetersWithName(string meterName) internal static void MarkMetersEnabled() => Interlocked.Or(ref s_enabledFlags, MetersFlag); - /// - /// Records a parse request event. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ParseRequest() { @@ -84,10 +63,6 @@ public static void ParseRequest() } } - /// - /// Records the duration of a parse request. - /// - /// The elapsed duration. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ParseDuration(TimeSpan duration) { @@ -103,9 +78,6 @@ public static void ParseDuration(TimeSpan duration) } } - /// - /// Records a cache hit in the concurrent dictionary. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ConcurrentCacheHit() { @@ -121,9 +93,6 @@ public static void ConcurrentCacheHit() } } - /// - /// Records a cache miss in the concurrent dictionary. - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ConcurrentCacheMiss() { @@ -139,9 +108,6 @@ public static void ConcurrentCacheMiss() } } - /// - /// Resets telemetry state for unit testing. - /// public static void ResetForTests() { Volatile.Write(ref s_enabledFlags, 0); diff --git a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs index 2817906..5da36a5 100644 --- a/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs +++ b/src/HttpUserAgentParser/Telemetry/HttpUserAgentParserTelemetryState.cs @@ -6,19 +6,13 @@ namespace MyCSharp.HttpUserAgentParser.Telemetry; /// -/// Knows the live instances to report their cache size. +/// Tracks providers from construction so the reported cache size includes entries added before telemetry was enabled. +/// Weak references let providers be collected between observations. /// -/// -/// Every provider registers itself when it is created, independent of whether telemetry is enabled, so the -/// reported size includes entries cached before telemetry was enabled. Providers are referenced weakly. -/// internal static class HttpUserAgentParserTelemetryState { private static readonly ConditionalWeakTable s_providers = new(); - /// - /// Registers a provider whose entries count towards . - /// public static void Register(HttpUserAgentParserCachedProvider provider) => s_providers.Add(provider, value: null); /// From bfde3bf3faa92d5930eb8ebe88ba111ff5aca156 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 19:15:17 +0100 Subject: [PATCH 24/41] docs(parser): add comments on stack depth and buffer size --- src/HttpUserAgentParser/HttpUserAgentParser.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 25313f7..525cfb1 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -98,6 +98,9 @@ private static T Detect(string userAgent, TState state, Detector decoded = stackalloc char[ua.Length]; From ecbef2512fe30265ad0474644eb507f5b0a545ee Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 20:21:35 +0100 Subject: [PATCH 25/41] perf(parser): optimize header parsing performance and memory usage --- README.md | 28 ++++----- docs/benchmarks/2026-11-24.md | 51 ++++++++++++++++ .../library-comparison-net11-dark.svg | 60 ++++++++++--------- docs/benchmarks/library-comparison-net11.svg | 60 ++++++++++--------- .../HttpUserAgentParser.cs | 16 +++-- 5 files changed, 137 insertions(+), 78 deletions(-) create mode 100644 docs/benchmarks/2026-11-24.md diff --git a/README.md b/README.md index 91825b6..e3c788f 100644 --- a/README.md +++ b/README.md @@ -468,18 +468,18 @@ Notes: ### Parser performance on .NET 11 -Mean time per uncached header on Windows 10 x64, AMD Ryzen 9 9950X, .NET 11.0.0. Each mixed workload processes 5,280 headers per invocation, with equal weight per distinct header. The API snapshot contains 60 captured user agents. [Test inputs and measurements](docs/benchmarks/2026-11-23.md) +Mean time per uncached header on Windows 10 x64, AMD Ryzen 9 9950X, .NET 11.0.0. Each mixed workload processes 5,280 headers per invocation, with equal weight per distinct header. The API snapshot contains 60 captured user agents. [Test inputs and measurements](docs/benchmarks/2026-11-24.md) | Workload | v3.1.9 | Current parser | Time change | Allocated per current parse | | --- | ---: | ---: | ---: | ---: | -| Catalog browsers (44) | 326.69 ns | 233.39 ns | −28.6% | 38 B | -| Catalog crawlers (48) | 378.77 ns | 78.47 ns | −79.3% | 0 B | -| Full catalog (96) | 389.59 ns | 155.96 ns | −60.0% | 18 B | -| API snapshot (60) | 359.15 ns | 205.52 ns | −42.8% | 29 B | -| Googlebot | 8.178 ns | 6.819 ns | −16.6% | 0 B | -| OAI-AdsBot | 904.130 ns | 141.179 ns | −84.4% | 0 B | +| Catalog browsers (44) | 318.05 ns | 234.69 ns | −26.2% | 38 B | +| Catalog crawlers (48) | 378.70 ns | 82.12 ns | −78.3% | 0 B | +| Full catalog (96) | 373.01 ns | 157.98 ns | −57.6% | 18 B | +| API snapshot (60) | 398.19 ns | 202.41 ns | −49.2% | 29 B | +| Googlebot | 8.537 ns | 6.915 ns | −19.0% | 0 B | +| OAI-AdsBot | 842.291 ns | 139.364 ns | −83.5% | 0 B | -Full-catalog means on the other supported runtimes were 193.01 ns (.NET 8), 196.53 ns (.NET 9) and 168.41 ns (.NET 10). The first Chrome parse on .NET 11 took 12.18 ms and allocated 199,984 B on the calling thread (medians across nine fresh processes). +Full-catalog means on the other supported runtimes were 191.49 ns (.NET 8), 196.83 ns (.NET 9) and 166.70 ns (.NET 10). The first Chrome parse on .NET 11 took 13.43 ms and allocated 193,792 B on the calling thread (medians across nine fresh processes). ### Library comparison on .NET 11 @@ -492,16 +492,16 @@ BenchmarkDotNet ShortRun, three warm-ups and three measured iterations. UAParser | Library | Measured operation | Chrome on Windows | Allocated | APIs-Google | Allocated | | --- | --- | ---: | ---: | ---: | ---: | -| MyCSharp | Parse | 246.46 ns | 48 B | 104.26 ns | 0 B | -| UAParser | GetDefault + Parse | 9,411,708.33 ns | 11,653,583 B | 9,340,315.10 ns | 12,010,118 B | -| DeviceDetector.NET | New detector + Parse | 5,701,457.29 ns | 5,529,305 B | 7,332,071.61 ns | 10,123,039 B | -| MyCSharp | Result cache hit | 19.42 ns | 0 B | 12.65 ns | 0 B | -| UAParser | Reused compiled parser | 123,522.75 ns | 37,400 B | 110,026.41 ns | 45,832 B | +| MyCSharp | Parse | 241.39 ns | 48 B | 106.15 ns | 0 B | +| UAParser | GetDefault + Parse | 9,769,158.85 ns | 11,653,583 B | 9,323,358.33 ns | 12,010,118 B | +| DeviceDetector.NET | New detector + Parse | 5,826,561.20 ns | 5,529,304 B | 7,377,367.19 ns | 10,123,039 B | +| MyCSharp | Result cache hit | 17.84 ns | 0 B | 12.69 ns | 0 B | +| UAParser | Reused compiled parser | 125,258.05 ns | 37,400 B | 110,313.30 ns | 45,832 B | ### Run the benchmarks ```shell -dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks.Parse" "*MixedWorkloadBenchmarks.Parse" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*HttpUserAgentParserBenchmarks.Parse" "*MixedWorkloadBenchmarks.Parse" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 --launchCount 3 dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*LibraryComparison*" ``` diff --git a/docs/benchmarks/2026-11-24.md b/docs/benchmarks/2026-11-24.md new file mode 100644 index 0000000..626172c --- /dev/null +++ b/docs/benchmarks/2026-11-24.md @@ -0,0 +1,51 @@ +# Parser benchmarks on November 24, 2026 + +Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case ran in three separate processes, each with three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../README.md#run-the-benchmarks) + +## Compared with main (`be56445`) on .NET 11 + +Each mixed workload repeats its inputs in catalog order, with equal weight per header. + +| Workload | Main | Current parser | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers (44) | 318.05 ns | 234.69 ns | −26.2% | 38 B | +| Catalog crawlers (48) | 378.70 ns | 82.12 ns | −78.3% | 0 B | +| Full catalog (96) | 373.01 ns | 157.98 ns | −57.6% | 18 B | +| API snapshot (60) | 398.19 ns | 202.41 ns | −49.2% | 29 B | +| Googlebot | 8.537 ns | 6.915 ns | −19.0% | 0 B | +| OAI-AdsBot | 842.291 ns | 139.364 ns | −83.5% | 0 B | + +## Mixed workloads per runtime + +Mean time per header of the current parser. Allocations match the .NET 11 table on every runtime. + +| Runtime | Catalog browsers | Catalog crawlers | Full catalog | API snapshot | +| --- | ---: | ---: | ---: | ---: | +| .NET 8.0.34 | 296.20 ns | 97.46 ns | 191.49 ns | 249.72 ns | +| .NET 9.0.23 | 305.51 ns | 95.04 ns | 196.83 ns | 248.87 ns | +| .NET 10.0.15 | 245.84 ns | 91.60 ns | 166.70 ns | 216.50 ns | +| .NET 11.0.0 | 234.69 ns | 82.12 ns | 157.98 ns | 202.41 ns | + +## Fixed-size stack buffer for IIS-encoded headers + +Headers containing `+` are decoded into a copy with spaces before detection. Up to 512 characters, the copy now lives in a stack buffer with a fixed size of 1 KiB, sliced to the header length. The previous revision (`876111f`) allocated exactly the header length on the stack. Longer headers still rent from `ArrayPool`. The fixed size keeps stack usage independent of the input. The runtime zeroes the whole buffer, so each decoded header took 1.6–2.8 ns longer. Headers without `+` skip this step. + +| Header or workload | Previous revision | Fixed-size buffer | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | +| IIS-encoded Screaming Frog | 71.66 ns | 74.47 ns | +3.9% | 0 B | +| Unknown client with `+` in its URL | 101.59 ns | 104.03 ns | +2.4% | 0 B | +| Applebot | 116.89 ns | 118.48 ns | +1.4% | 0 B | +| Catalog browsers (44) | 235.64 ns | 235.86 ns | +0.1% | 38 B | +| Catalog crawlers (48) | 81.13 ns | 82.05 ns | +1.1% | 0 B | +| Full catalog (96) | 155.83 ns | 156.27 ns | +0.3% | 18 B | +| API snapshot (60) | 199.06 ns | 204.51 ns | +2.7% | 29 B | + +A variant that routed the stack buffer and the rented array through one shared `try`/`finally` block took another 4–5 ns per decoded header and was not adopted. + +## First parse in a fresh process + +Nine fresh .NET 11 processes each timed their first `Parse` call for Chrome on Windows with `Stopwatch` and read `GC.GetAllocatedBytesForCurrentThread` before and after it. The median was 13.43 ms and 193,792 B. The previous revision took 13.48 ms with the same program and allocated the same number of bytes. The program was rewritten for this run, so compare it only with the previous revision above, not with earlier first-parse figures. + +## Reproduction + +Build the baseline revision in Release for `net11.0` with `-p:AssemblyName=MyCSharp.HttpUserAgentParser.Baseline` and set `BenchmarkBaselineAssembly` to the absolute path of that DLL. Run the first README benchmark command with the filters `"*MixedWorkloadBenchmarks.Parse*" "*HttpUserAgentParserBenchmarks.Parse*Googlebot*" "*HttpUserAgentParserBenchmarks.Parse*OAI-AdsBot*"` for the comparison with main. For the stack buffer comparison, use `876111f` as baseline and the filters `"*MixedWorkloadBenchmarks.Parse*" "*HttpUserAgentParserBenchmarks.Parse*IIS*" "*HttpUserAgentParserBenchmarks.Parse*Applebot*" "*HttpUserAgentParserBenchmarks.Parse*Unknown*"`. The runtime table uses the mixed workload filter without a baseline and with `-f net8.0`, `net9.0` or `net10.0`. diff --git a/docs/benchmarks/library-comparison-net11-dark.svg b/docs/benchmarks/library-comparison-net11-dark.svg index 917d00a..8a58d28 100644 --- a/docs/benchmarks/library-comparison-net11-dark.svg +++ b/docs/benchmarks/library-comparison-net11-dark.svg @@ -1,6 +1,6 @@ Library comparison on .NET 11 -Linear column charts of mean time per call. Single parse with setup: MyCSharp 246 ns and 104 ns, UAParser 9.41 ms and 9.34 ms, DeviceDetector.NET 5.70 ms and 7.33 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 19.4 ns and 12.7 ns, UAParser reused compiled parser 124 µs and 110 µs. +Linear column charts of mean time per call. Single parse with setup: MyCSharp 241 ns and 106 ns, UAParser 9.77 ms and 9.32 ms, DeviceDetector.NET 5.83 ms and 7.38 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 17.8 ns and 12.7 ns, UAParser reused compiled parser 125 µs and 110 µs. Mean time per call on .NET 11 Linear scale, lower is better. Each panel has its own axis. @@ -21,58 +21,60 @@ 10 ms -246 ns +241 ns -104 ns +106 ns MyCSharp Parse Bars too short to draw at this scale: -23,000× to 90,000× +24,000× to 88,000× faster - -9.41 ms - -9.34 ms + +9.77 ms + +9.32 ms UAParser GetDefault + Parse - -5.70 ms - -7.33 ms + +5.83 ms + +7.38 ms DeviceDetector.NET New detector + Parse Repeated parse with reused state 0 - -25 µs - -50 µs - -75 µs - -100 µs + +25 µs + +50 µs + +75 µs + +100 µs + +125 µs -125 µs - -19.4 ns - +150 µs + +17.8 ns + 12.7 ns MyCSharp Result cache hit Bars too short to draw at this scale: -6,400× to 8,700× +7,000× to 8,700× faster - -124 µs - -110 µs + +125 µs + +110 µs UAParser Reused compiled parser diff --git a/docs/benchmarks/library-comparison-net11.svg b/docs/benchmarks/library-comparison-net11.svg index 4918bbf..7f94426 100644 --- a/docs/benchmarks/library-comparison-net11.svg +++ b/docs/benchmarks/library-comparison-net11.svg @@ -1,6 +1,6 @@ Library comparison on .NET 11 -Linear column charts of mean time per call. Single parse with setup: MyCSharp 246 ns and 104 ns, UAParser 9.41 ms and 9.34 ms, DeviceDetector.NET 5.70 ms and 7.33 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 19.4 ns and 12.7 ns, UAParser reused compiled parser 124 µs and 110 µs. +Linear column charts of mean time per call. Single parse with setup: MyCSharp 241 ns and 106 ns, UAParser 9.77 ms and 9.32 ms, DeviceDetector.NET 5.83 ms and 7.38 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 17.8 ns and 12.7 ns, UAParser reused compiled parser 125 µs and 110 µs. Mean time per call on .NET 11 Linear scale, lower is better. Each panel has its own axis. @@ -21,58 +21,60 @@ 10 ms -246 ns +241 ns -104 ns +106 ns MyCSharp Parse Bars too short to draw at this scale: -23,000× to 90,000× +24,000× to 88,000× faster - -9.41 ms - -9.34 ms + +9.77 ms + +9.32 ms UAParser GetDefault + Parse - -5.70 ms - -7.33 ms + +5.83 ms + +7.38 ms DeviceDetector.NET New detector + Parse Repeated parse with reused state 0 - -25 µs - -50 µs - -75 µs - -100 µs + +25 µs + +50 µs + +75 µs + +100 µs + +125 µs -125 µs - -19.4 ns - +150 µs + +17.8 ns + 12.7 ns MyCSharp Result cache hit Bars too short to draw at this scale: -6,400× to 8,700× +7,000× to 8,700× faster - -124 µs - -110 µs + +125 µs + +110 µs UAParser Reused compiled parser diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 525cfb1..a47cf28 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -100,24 +100,28 @@ private static T Detect(string userAgent, TState state, Detector decoded = stackalloc char[ua.Length]; + Span decoded = stackalloc char[MaxStackLength]; + decoded = decoded[..ua.Length]; ua.Replace(decoded, '+', ' '); return detect(userAgent, decoded, state); } - char[] buffer = ArrayPool.Shared.Rent(ua.Length); + char[] rented = ArrayPool.Shared.Rent(ua.Length); try { - Span decoded = buffer.AsSpan(0, ua.Length); + Span decoded = rented.AsSpan(0, ua.Length); ua.Replace(decoded, '+', ' '); return detect(userAgent, decoded, state); } finally { - ArrayPool.Shared.Return(buffer); + ArrayPool.Shared.Return(rented); } } From 28ae2c534526a093a15fa7cd0c28f81935bb7d77 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 20:23:23 +0100 Subject: [PATCH 26/41] feat(docs): add README files for core and memory cache packages --- README.md => readme.md | 0 src/HttpUserAgentParser.AspNetCore/{README.md => readme.md} | 0 src/HttpUserAgentParser.MemoryCache/{README.md => readme.md} | 0 src/HttpUserAgentParser/{README.md => readme.md} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename README.md => readme.md (100%) rename src/HttpUserAgentParser.AspNetCore/{README.md => readme.md} (100%) rename src/HttpUserAgentParser.MemoryCache/{README.md => readme.md} (100%) rename src/HttpUserAgentParser/{README.md => readme.md} (100%) diff --git a/README.md b/readme.md similarity index 100% rename from README.md rename to readme.md diff --git a/src/HttpUserAgentParser.AspNetCore/README.md b/src/HttpUserAgentParser.AspNetCore/readme.md similarity index 100% rename from src/HttpUserAgentParser.AspNetCore/README.md rename to src/HttpUserAgentParser.AspNetCore/readme.md diff --git a/src/HttpUserAgentParser.MemoryCache/README.md b/src/HttpUserAgentParser.MemoryCache/readme.md similarity index 100% rename from src/HttpUserAgentParser.MemoryCache/README.md rename to src/HttpUserAgentParser.MemoryCache/readme.md diff --git a/src/HttpUserAgentParser/README.md b/src/HttpUserAgentParser/readme.md similarity index 100% rename from src/HttpUserAgentParser/README.md rename to src/HttpUserAgentParser/readme.md From 4821699192253d4828eb154e85233baf90398de7 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Tue, 24 Nov 2026 20:23:38 +0100 Subject: [PATCH 27/41] chore: rename README.md to readme.md for consistency --- MyCSharp.HttpUserAgentParser.sln | 2 +- docs/benchmarks/2026-11-23.md | 2 +- docs/benchmarks/2026-11-24.md | 2 +- .../HttpUserAgentParser.AspNetCore.csproj | 4 ++-- .../HttpUserAgentParser.MemoryCache.csproj | 4 ++-- src/HttpUserAgentParser/HttpUserAgentParser.csproj | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MyCSharp.HttpUserAgentParser.sln b/MyCSharp.HttpUserAgentParser.sln index 0a67c64..32a8aa1 100644 --- a/MyCSharp.HttpUserAgentParser.sln +++ b/MyCSharp.HttpUserAgentParser.sln @@ -30,7 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{5738CE0D-5E6E-47 Justfile = Justfile LICENSE = LICENSE NuGet.config = NuGet.config - README.md = README.md + readme.md = readme.md version.json = version.json EndProjectSection EndProject diff --git a/docs/benchmarks/2026-11-23.md b/docs/benchmarks/2026-11-23.md index 7d9a93c..25ad3c4 100644 --- a/docs/benchmarks/2026-11-23.md +++ b/docs/benchmarks/2026-11-23.md @@ -1,6 +1,6 @@ # Parser benchmarks on November 23, 2026 -Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case used a separate process, three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../README.md#parser-performance-on-net-11) +Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case used a separate process, three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../readme.md#parser-performance-on-net-11) ## Shared rule filter diff --git a/docs/benchmarks/2026-11-24.md b/docs/benchmarks/2026-11-24.md index 626172c..9859eed 100644 --- a/docs/benchmarks/2026-11-24.md +++ b/docs/benchmarks/2026-11-24.md @@ -1,6 +1,6 @@ # Parser benchmarks on November 24, 2026 -Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case ran in three separate processes, each with three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../README.md#run-the-benchmarks) +Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case ran in three separate processes, each with three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../readme.md#run-the-benchmarks) ## Compared with main (`be56445`) on .NET 11 diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj index 699aaad..8a27dc0 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj @@ -11,11 +11,11 @@ true - README.md + readme.md - + diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj index cc2968b..3a072ca 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj @@ -11,11 +11,11 @@ true - README.md + readme.md - + diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.csproj b/src/HttpUserAgentParser/HttpUserAgentParser.csproj index bb22df8..fcfa165 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.csproj +++ b/src/HttpUserAgentParser/HttpUserAgentParser.csproj @@ -11,11 +11,11 @@ true - README.md + readme.md - + From 9bdd0c8e262baa30ccb9c5794dab3b84060da549 Mon Sep 17 00:00:00 2001 From: BEN ABT Date: Wed, 25 Nov 2026 09:34:55 +0100 Subject: [PATCH 28/41] chore(package): pack a 128 px icon instead of the 512 px logo The packages contained the 512x512 logo (251 KB), while the DLLs are about 20 KB each. NuGet shows the icon at 128x128, so the packages now contain a 128x128 icon (30 KB). The readme keeps the 512x512 logo. The myCSharp.de NuGet logo is no longer used and is removed. --- Directory.Build.props | 6 +++--- res/httpuseragentparser-icon.png | Bin 0 -> 29592 bytes res/mycsharpde-logo-nuget.png | Bin 102068 -> 0 bytes 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 res/httpuseragentparser-icon.png delete mode 100644 res/mycsharpde-logo-nuget.png diff --git a/Directory.Build.props b/Directory.Build.props index fa39212..fb8bff6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -59,12 +59,12 @@ MIT UserAgent, User Agent, Parse, Browser, Client, Detector, Detection, Console, ASP, Desktop, Mobile - httpuseragentparser-logo.png + httpuseragentparser-icon.png - + - + diff --git a/res/httpuseragentparser-icon.png b/res/httpuseragentparser-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6b6b73a1dc2c7d1c9e9cdc9e48881dfc97661893 GIT binary patch literal 29592 zcmV*aKvlnqP)Z~7&|l^*@nyx5p8s8)FTZ7FWixz47LY|2 z5CR}Xs5V4hsQaMr3u!XJ*7qVq3dHlz+kpI^5`aMq@0-44j%_JN3B_7~Eysf>l+q6T z@A4kx0ty9HQ?N{%SUe6%6Rh4f6QC&I*6?^dXsOppX%9Gv5)pz{iP(=6>jmmZv7N81 z2kd`E5Wb=S+@ip(Hb8LFnfZodUm}F{EntpNG(aMy1S!9+0RI2xrl~3k!z3Aw;_`c$ zGc3<{AcOz}(zZa#twK?s z7RW~;+h1=UxMu&J05}q5!BW*bHGZAMzEM%MVN%*)TOct(3Irl`IPt&B-TwkBszOg! z4+TYeeEY29Id{oX%$_<9P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3ZRf@NQyI1jGbHbA!Je}= z=Gx=(J?9uE<`517P-Mk=Lb=|4CM(5j@raf|pz^nbVWNRZTHh~^ph0DN^)H-}(H}en z8^M4pbJAQ`THi!cjBU^1$q~tWUIx}m_$T(vL^=dt;cFRM;`yjPkpO$=_=?DzCI zH8|;SN0Kiyd${_@aPoe30jn6VZ#kg)&1lQ$U4t4w6@YUVI- Q;^sR=Syh>zQYL}_0bpKkc>n+a literal 0 HcmV?d00001 diff --git a/res/mycsharpde-logo-nuget.png b/res/mycsharpde-logo-nuget.png deleted file mode 100644 index 8657cbb2764e38ff4f82d0036df99f98393d5296..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 102068 zcmeFYWm8;j6E2z%+$FfXySrNm9^3;2cXu7!A-F?ucXxN!K?Zks%bq-Mo&D+jgLArS z)zq4rx~EpJ)~l}$S5lBhg2#jZ^yw3ltc--pr%#{n{#~%p;BUs4wj#hEpPf{s#XeO{ z5gdbWAk9SOML&J2jYW7ff&$;e*~@4-efos%{O|g_`HR^7)2F|GWFi?)19J&A!FUJ>^nfUT$S;Z5)HF1>xj8si6rlenq4)xV zf;zAplarIKTrB?ykM0Z*SP^_-Yk-gQpAZbO1lt<^lNoqJ*o~fll8f1c+VnxA=W{if4YM7%{QeGZ3f80?0&&EDB zw{=Ms6%`Be@ZX$7Ns~=J?%1b~Jhp_ScT0=2rEG1h+FqZZaYdJVdbVo-ToZ)~y>@7F zMf~vG9ua}Zv-+#Y$7LR=D^3=cr}jScBj~?8JOo{ut(KfG568ysnnyFW>`jF>b=41m z&`_8nfon+Hu45_=POkj6qM-*?@UuQ`_5I1i7vp}C4tV5kJTEDs`TF(iN>xuyqO{>m z4M-*`d|)c7vgI}V)jG!q4G%A3TKF%-FtIQ!r`Sof*u_6b`zx2q+&T%Q_X#^_w^i=k%pGG7mk`BR#j0DQ$JgO4GH{=hF5N2 z=MC~BsA@gHd!6W$)X)veT3wg)f$0zsP|{M31exhY%}?{nQEYie5%Mn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=-+y%9=#F4*z zS}TV=Gz&%p4Jp&@5uJBMc`Q41IPRZandTiDTka!`@dB= zsemByT((gNXtW`MKne#<&X%Dw;^JWPt=T-!#vK zg&U%9zwgSPaPEeS(`VhV40tOuOxvbC&?raQ%F|pYLm5RWb7F)r2O{niM}zMja;dnx zotYe6Y6Z6px1LOzz&ihTAQ zqEOf^)Rog?kjQ%6`K=rJKl*(>M%P&9rC~V*3%(JV^%nBD7;PUmr3?COMGtWXj5N-< zc?Sb0zNOovB5IrGC__HVifz9Hd7!Q1s0Lr?^vws*D5SA=UU&{i^k5gc8>3S*Fl^(r zE6ur=Ap=|P6lW#qN`B~C=}YhHKa~aC7S|?1Z-~j&yAP04M@8S>w$tF|E2iz>XuS~& zMcsJKO!rC>@JyJr|~~+t)l5)m7y5W$ngPd>vH8YVH1h3qU||f z->ZU!VepMB7!bWL?4~>+aJar^s zV9W%SRagv7+L3M!7jlGw+iLP)j-ze{X2`|ldGF(d_6SnFt zO`Wk+O;Hp@S?y6l?*zJ(dNS_CdHB%kd16Pz1KDtJrL5h%jDfnMD2k$FL5S?H9HeZSW zakd$4=VUn4$Z4Z`NP|8+R}@82BA|j^NPJh$`pe$mOH^N&->3q9}@@L`4O? z0F;!va@vaM+(ytv{I0%?Sx=X$DT<;f*`b1-XMB|CyrnJj!e>kIi_KU&XimsETlO@O zy2`ntD2kE|D(HEptcxdSy!74w)}3=WJ<}0O$OT*WUbWwwIG74}`@N>LI7f%v|!f}U?!ihPb9YqgjXb2KKfi>G7P)EUb?9Ik|(nW_`u2#Sg+ zN(!nke(}Tt12wRVL9_%Ibgr6AAs0Xqv6KU*#({NI0Vu3S!vT_JC=Z7NE7z~*Pudvq zDIApI0>jK}?u##9xl*&^_~VoIpgh>MY1hNbd4KFv>KL Date: Wed, 25 Nov 2026 09:51:17 +0100 Subject: [PATCH 29/41] chore(package): use single-word NuGet tags NuGet splits tags at spaces, so "User Agent" became the tags "User" and "Agent" on NuGet.org. The tags are now single words that describe what the packages detect, for example user-agent, browser-detection and bot-detection. useragent is kept. Console, ASP and Desktop are removed, because they do not describe the packages. --- Directory.Build.props | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index fb8bff6..5bd35c6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -57,7 +57,8 @@ https://github.com/mycsharp/HttpUserAgentParser https://github.com/mycsharp/HttpUserAgentParser MIT - UserAgent, User Agent, Parse, Browser, Client, Detector, Detection, Console, ASP, Desktop, Mobile + + user-agent;useragent;user-agent-parser;parser;browser-detection;platform-detection;mobile-detection;bot-detection;crawler-detection;aspnetcore;http httpuseragentparser-icon.png From 58d7bd607eff93681ecc242248e37331adc8bc0d Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Wed, 25 Nov 2026 10:27:00 +0100 Subject: [PATCH 30/41] perf(parser): optimize memory usage in user agent parsing --- src/HttpUserAgentParser/HttpUserAgentParser.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index a47cf28..05cf95b 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -113,16 +113,11 @@ private static T Detect(string userAgent, TState state, Detector.Shared.Rent(ua.Length); - try - { - Span decoded = rented.AsSpan(0, ua.Length); - ua.Replace(decoded, '+', ' '); - return detect(userAgent, decoded, state); - } - finally - { - ArrayPool.Shared.Return(rented); - } + Span rentedSpan = rented.AsSpan(0, ua.Length); + ua.Replace(rentedSpan, '+', ' '); + T result = detect(userAgent, rentedSpan, state); + ArrayPool.Shared.Return(rented); + return result; } /// From a9e2c9f11bb731a04b0004e4345503b7dc460403 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 13:54:52 +0100 Subject: [PATCH 31/41] feat(parser): add null checks for user agent methods --- ...serDependencyInjectionOptionsExtensions.cs | 4 ++ .../HttpContextExtensions.cs | 2 + ...rMemoryCacheServiceCollectionExtensions.cs | 5 +- ...HttpUserAgentParserMemoryCachedProvider.cs | 2 + ...rAgentParserServiceCollectionExtensions.cs | 21 +++++++- .../HttpUserAgentParser.cs | 12 ++++- .../HttpUserAgentRegexes.cs | 8 ++- .../HttpUserAgentStatics.cs | 8 ++- .../HttpUserAgentParserCachedProvider.cs | 51 ++++++++++++++++--- ...tParserServiceCollectionExtensionsTests.cs | 9 ++++ .../HttpContextExtensionsTests.cs | 8 +++ ...yCacheServiceCollectionExtensionssTests.cs | 27 ++++++++++ ...tParserServiceCollectionExtensionsTests.cs | 44 ++++++++++++++++ .../HttpUserAgentParserTests.cs | 16 ++++++ .../HttpUserAgentStaticsTests.cs | 32 +++++++++--- .../HttpUserAgentParserCachedProviderTests.cs | 50 ++++++++++++++++++ 16 files changed, 280 insertions(+), 19 deletions(-) diff --git a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs index 4c99c83..2ae26f6 100644 --- a/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs +++ b/src/HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs @@ -25,6 +25,8 @@ public static class HttpUserAgentParserDependencyInjectionOptionsExtensions public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserAccessor( this HttpUserAgentParserDependencyInjectionOptions options) { + ArgumentNullException.ThrowIfNull(options); + options.Services.TryAddSingleton(); return options; } @@ -42,6 +44,8 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentPars public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserContextAccessor( this HttpUserAgentParserDependencyInjectionOptions options) { + ArgumentNullException.ThrowIfNull(options); + options.Services.AddHttpContextAccessor(); options.Services.TryAddSingleton(); options.Services.TryAddSingleton( diff --git a/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs b/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs index 40f34e6..c8f7b59 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs @@ -20,6 +20,8 @@ public static class HttpContextExtensions /// public static string? GetUserAgentString(this HttpContext httpContext) { + ArgumentNullException.ThrowIfNull(httpContext); + StringValues value = httpContext.Request.Headers.UserAgent; if (value.Count > 0) { diff --git a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs index d0aeec4..3065ba5 100644 --- a/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs +++ b/src/HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs @@ -1,6 +1,7 @@ // Copyright © https://myCSharp.de - all rights reserved using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using MyCSharp.HttpUserAgentParser.DependencyInjection; using MyCSharp.HttpUserAgentParser.Providers; @@ -18,11 +19,13 @@ public static class HttpUserAgentParserMemoryCacheServiceCollectionExtensions public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentMemoryCachedParser( this IServiceCollection services, Action? options = null) { + ArgumentNullException.ThrowIfNull(services); + HttpUserAgentParserMemoryCachedProviderOptions providerOptions = new(); options?.Invoke(providerOptions); // register options - services.AddSingleton(providerOptions); + services.TryAddSingleton(providerOptions); // register cache provider return services.AddHttpUserAgentParser(); diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs index e3f77c1..97b8675 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs @@ -42,6 +42,8 @@ public IDisposable RegisterChangeCallback(Action callback, object? stat /// The options used to set expiration and size limit public HttpUserAgentParserMemoryCachedProvider(HttpUserAgentParserMemoryCachedProviderOptions options) { + ArgumentNullException.ThrowIfNull(options); + _memoryCache = new(options.CacheOptions); _options = options; diff --git a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs index dcd433d..c387241 100644 --- a/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs +++ b/src/HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using MyCSharp.HttpUserAgentParser.Providers; namespace MyCSharp.HttpUserAgentParser.DependencyInjection; @@ -29,6 +30,22 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentCach return AddHttpUserAgentParser(services); } + /// + /// Registers with the specified limit + /// as singleton to + /// + public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentCachedParser( + this IServiceCollection services, int maxCacheEntries) + { + ArgumentNullException.ThrowIfNull(services); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxCacheEntries); + + HttpUserAgentParserDependencyInjectionOptions options = new(services); + services.TryAddSingleton(_ => new HttpUserAgentParserCachedProvider(maxCacheEntries)); + + return options; + } + /// /// Registers as singleton to /// @@ -38,11 +55,13 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentCach public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>( this IServiceCollection services) where TProvider : class, IHttpUserAgentParserProvider { + ArgumentNullException.ThrowIfNull(services); + // create options HttpUserAgentParserDependencyInjectionOptions options = new(services); // add provider - services.AddSingleton(); + services.TryAddSingleton(); return options; } diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index 05cf95b..f38fe33 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -34,6 +34,8 @@ public static HttpUserAgentInformation Parse(string userAgent) internal static HttpUserAgentInformation Parse(string userAgent, HttpUserAgentRobotSet robots) { + ArgumentNullException.ThrowIfNull(userAgent); + if (!HttpUserAgentParserTelemetry.IsEnabled) { return ParseInternal(userAgent, robots); @@ -92,6 +94,8 @@ private static T DetectProduct(string userAgent, ProductDetector detector) // string in the result and share the decoded span across all detectors. private static T Detect(string userAgent, TState state, Detector detect) { + ArgumentNullException.ThrowIfNull(userAgent); + ReadOnlySpan ua = userAgent.AsSpan(); if (!ua.Contains('+')) { @@ -123,7 +127,11 @@ private static T Detect(string userAgent, TState state, Detector /// pre-cleanup of user agent /// - public static string Cleanup(string userAgent) => userAgent.Trim(); + public static string Cleanup(string userAgent) + { + ArgumentNullException.ThrowIfNull(userAgent); + return userAgent.Trim(); + } /// /// returns the platform or null @@ -348,6 +356,8 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri /// public static string? GetRobot(string userAgent) { + ArgumentNullException.ThrowIfNull(userAgent); + HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; return robots.MatchFirst(userAgent) ?? Detect(userAgent, robots, static (original, decoded, rules) => rules.MatchAfterFirst(original, decoded)); diff --git a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs index 9622bb6..3bc154e 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs @@ -199,10 +199,10 @@ internal static partial class HttpUserAgentRegexes [GeneratedRegex(@"Netscape.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserNetscape(); [GeneratedRegex(@"OmniWeb.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserOmniWeb(); [GeneratedRegex(@"Version.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserVersion(); - [GeneratedRegex(@"Mozilla.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserMozilla(); [GeneratedRegex(@"Konqueror.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserKonqueror(); [GeneratedRegex(@"icab.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserICab(); [GeneratedRegex(@"Lynx.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserLynx(); + [GeneratedRegex(@"ELinks.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserELinks(); [GeneratedRegex(@"Links.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserLinks(); [GeneratedRegex(@"hotjava.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserHotJava(); [GeneratedRegex(@"amaya.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserAmaya(); @@ -210,5 +210,11 @@ internal static partial class HttpUserAgentRegexes [GeneratedRegex(@"Maxthon.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserMaxthon(); [GeneratedRegex(@"ipod touch.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserIPodTouch(); [GeneratedRegex(@"Ubuntu.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserUbuntu(); + [GeneratedRegex(@"EdgiOS.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserEdgiOS(); + [GeneratedRegex(@"SamsungBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserSamsungBrowser(); + [GeneratedRegex(@"YaBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserYaBrowser(); + [GeneratedRegex(@"UCBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserUCBrowser(); + [GeneratedRegex(@"UCMobile.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserUCMobile(); + [GeneratedRegex(@"HeadlessChrome.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserHeadlessChrome(); #pragma warning restore MA0023 } diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index 5bb8722..be0e469 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -38,10 +38,16 @@ public static class HttpUserAgentStatics { HttpUserAgentRegexes.BrowserEdge(), "Edge" }, { HttpUserAgentRegexes.BrowserEdgA(), "Edge" }, { HttpUserAgentRegexes.BrowserEdg(), "Edge" }, + { HttpUserAgentRegexes.BrowserEdgiOS(), "Edge" }, { HttpUserAgentRegexes.BrowserVivaldi(), "Vivaldi" }, { HttpUserAgentRegexes.BrowserBraveChrome(), "Brave" }, + { HttpUserAgentRegexes.BrowserSamsungBrowser(), "Samsung Internet" }, + { HttpUserAgentRegexes.BrowserYaBrowser(), "Yandex Browser" }, + { HttpUserAgentRegexes.BrowserUCBrowser(), "UC Browser" }, + { HttpUserAgentRegexes.BrowserUCMobile(), "UC Browser" }, { HttpUserAgentRegexes.BrowserChrome(), "Chrome" }, { HttpUserAgentRegexes.BrowserCriOS(), "Chrome" }, + { HttpUserAgentRegexes.BrowserHeadlessChrome(), "Chrome" }, { HttpUserAgentRegexes.BrowserOperaVersion(), "Opera" }, { HttpUserAgentRegexes.BrowserOpera(), "Opera" }, { HttpUserAgentRegexes.BrowserMsie(), "Internet Explorer" }, @@ -57,10 +63,10 @@ public static class HttpUserAgentStatics { HttpUserAgentRegexes.BrowserNetscape(), "Netscape" }, { HttpUserAgentRegexes.BrowserOmniWeb(), "OmniWeb" }, { HttpUserAgentRegexes.BrowserVersion(), "Safari" }, // https://github.com/mycsharp/HttpUserAgentParser/issues/34 - { HttpUserAgentRegexes.BrowserMozilla(), "Mozilla" }, { HttpUserAgentRegexes.BrowserKonqueror(), "Konqueror" }, { HttpUserAgentRegexes.BrowserICab(), "iCab" }, { HttpUserAgentRegexes.BrowserLynx(), "Lynx" }, + { HttpUserAgentRegexes.BrowserELinks(), "ELinks" }, { HttpUserAgentRegexes.BrowserLinks(), "Links" }, { HttpUserAgentRegexes.BrowserHotJava(), "HotJava" }, { HttpUserAgentRegexes.BrowserAmaya(), "Amaya" }, diff --git a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs index 6b834aa..9b835ef 100644 --- a/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs +++ b/src/HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs @@ -10,6 +10,11 @@ namespace MyCSharp.HttpUserAgentParser.Providers; /// public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider { + /// + /// Default maximum number of cached user agent entries before the cache is rotated. + /// + public const int DefaultMaxCacheEntries = 10_000; + private sealed class Cache(HttpUserAgentRobotSet robots) { public HttpUserAgentRobotSet Robots { get; } = robots; @@ -35,9 +40,30 @@ private Cache GetCurrentCache() } /// - /// Creates a provider with an empty cache. + /// Creates a provider with an empty cache limited to entries. + /// + public HttpUserAgentParserCachedProvider() + : this(DefaultMaxCacheEntries) + { + } + + /// + /// Creates a provider with an empty cache limited to entries. + /// + /// Maximum number of entries retained before the cache is rotated. + /// is less than or equal to zero. + public HttpUserAgentParserCachedProvider(int maxCacheEntries) + { + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxCacheEntries); + + MaxCacheEntries = maxCacheEntries; + HttpUserAgentParserTelemetryState.Register(this); + } + + /// + /// Maximum number of entries retained in the cache before it is rotated. /// - public HttpUserAgentParserCachedProvider() => HttpUserAgentParserTelemetryState.Register(this); + public int MaxCacheEntries { get; } /// /// @@ -46,20 +72,29 @@ private Cache GetCurrentCache() public HttpUserAgentInformation Parse(string userAgent) { Cache cache = GetCurrentCache(); - if (!HttpUserAgentParserTelemetry.IsEnabled) + if (cache.Entries.TryGetValue(userAgent, out HttpUserAgentInformation cached)) { - return cache.Entries.GetOrAdd(userAgent, static (ua, robots) => HttpUserAgentParser.Parse(ua, robots), cache.Robots); + if (HttpUserAgentParserTelemetry.IsEnabled) + { + HttpUserAgentParserTelemetry.ConcurrentCacheHit(); + } + + return cached; } - if (cache.Entries.TryGetValue(userAgent, out HttpUserAgentInformation cached)) + if (cache.Entries.Count >= MaxCacheEntries) { - HttpUserAgentParserTelemetry.ConcurrentCacheHit(); - return cached; + Interlocked.CompareExchange(ref _cache, new Cache(cache.Robots), cache); + cache = GetCurrentCache(); } // Report the observed miss after insertion so a synchronous listener can read the entry. HttpUserAgentInformation information = cache.Entries.GetOrAdd(userAgent, static (ua, robots) => HttpUserAgentParser.Parse(ua, robots), cache.Robots); - HttpUserAgentParserTelemetry.ConcurrentCacheMiss(); + if (HttpUserAgentParserTelemetry.IsEnabled) + { + HttpUserAgentParserTelemetry.ConcurrentCacheMiss(); + } + return information; } diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index 29638db..deb81ca 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -76,4 +76,13 @@ public void Accessor_Registrations_Are_Idempotent_In_Any_Order(bool contextAcces Assert.Single(provider.GetServices()); Assert.Single(provider.GetServices()); } + + [Fact] + public void Accessor_Registrations_Throw_When_Options_Is_Null() + { + HttpUserAgentParserDependencyInjectionOptions options = null!; + + Assert.Throws(() => options.AddHttpUserAgentParserAccessor()); + Assert.Throws(() => options.AddHttpUserAgentParserContextAccessor()); + } } diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs index 8a2b5c4..77b2641 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpContextExtensionsTests.cs @@ -34,4 +34,12 @@ public void Accessor_Get_Returns_Null_When_Header_Missing() Assert.Null(accessor.Get(ctx)); provider.DidNotReceiveWithAnyArgs().Parse(default!); } + + [Fact] + public void GetUserAgentString_Throws_When_HttpContext_Is_Null() + { + HttpContext ctx = null!; + + Assert.Throws(() => ctx.GetUserAgentString()); + } } diff --git a/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs b/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs index 8183e95..0270912 100644 --- a/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs +++ b/tests/HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs @@ -41,4 +41,31 @@ public void AddHttpUserAgentMemoryCachedParser_Applies_Options() Assert.Equal(1024, options.CacheOptions.SizeLimit); Assert.Equal(TimeSpan.FromMinutes(60), options.CacheEntryOptions.SlidingExpiration); } + + [Fact] + public void AddHttpUserAgentMemoryCachedParser_Is_Idempotent() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentMemoryCachedParser(options => options.CacheOptions.SizeLimit = 512); + services.AddHttpUserAgentMemoryCachedParser(options => options.CacheOptions.SizeLimit = 2048); + + Assert.Equal(2, services.Count); + HttpUserAgentParserMemoryCachedProviderOptions options = Assert.IsType(services[0].ImplementationInstance); + Assert.Equal(512, options.CacheOptions.SizeLimit); + } + + [Fact] + public void AddHttpUserAgentMemoryCachedParser_Throws_When_Services_Is_Null() + { + IServiceCollection services = null!; + + Assert.Throws(() => services.AddHttpUserAgentMemoryCachedParser()); + } + + [Fact] + public void MemoryCachedProvider_Throws_When_Options_Is_Null() + { + Assert.Throws(() => new HttpUserAgentParserMemoryCachedProvider(null!)); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index c74c657..58d1a51 100644 --- a/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -54,4 +54,48 @@ public void AddHttpUserAgentParser_With_Generic() Assert.Equal(typeof(TestHttpUserAgentParserProvider), services[0].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime); } + + [Fact] + public void AddHttpUserAgentCachedParser_With_MaxCacheEntries() + { + ServiceCollection services = new(); + + HttpUserAgentParserDependencyInjectionOptions options = services.AddHttpUserAgentCachedParser(maxCacheEntries: 128); + + Assert.Same(services, options.Services); + Assert.Single(services); + + using ServiceProvider serviceProvider = services.BuildServiceProvider(); + HttpUserAgentParserCachedProvider provider = Assert.IsType( + serviceProvider.GetRequiredService()); + Assert.Equal(128, provider.MaxCacheEntries); + } + + [Fact] + public void AddHttpUserAgentParser_Is_Idempotent() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentParser(); + services.AddHttpUserAgentCachedParser(); + services.AddHttpUserAgentCachedParser(64); + services.AddHttpUserAgentParser(); + + Assert.Single(services); + Assert.Equal(typeof(HttpUserAgentParserDefaultProvider), services[0].ImplementationType); + } + + [Fact] + public void AddHttpUserAgentParser_Validates_Arguments() + { + IServiceCollection nullServices = null!; + ServiceCollection services = new(); + + Assert.Throws(() => nullServices.AddHttpUserAgentParser()); + Assert.Throws(() => nullServices.AddHttpUserAgentCachedParser()); + Assert.Throws(() => nullServices.AddHttpUserAgentCachedParser(10)); + Assert.Throws(() => nullServices.AddHttpUserAgentParser()); + Assert.Throws(() => services.AddHttpUserAgentCachedParser(0)); + Assert.Throws(() => services.AddHttpUserAgentCachedParser(-5)); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index aa48a7d..77d773d 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -453,4 +453,20 @@ public void GetRobot_Tells_YouBot_And_ShowyouBot_Apart() Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0+(compatible;+YouBot/1.0)")); Assert.Equal("YouBot", HttpUserAgentParser.GetRobot("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; YouBot/1.0; +https://docs.you.com/youbot; env:prod) Chrome/X.X.X.X Safari/537.36")); } + + [Fact] + public void Public_Methods_Throw_ArgumentNullException_When_UserAgent_Is_Null() + { + Assert.Throws(() => HttpUserAgentParser.Parse(null!)); + Assert.Throws(() => HttpUserAgentInformation.Parse(null!)); + Assert.Throws(() => HttpUserAgentParser.Cleanup(null!)); + Assert.Throws(() => HttpUserAgentParser.GetPlatform(null!)); + Assert.Throws(() => HttpUserAgentParser.TryGetPlatform(null!, out _)); + Assert.Throws(() => HttpUserAgentParser.GetBrowser(null!)); + Assert.Throws(() => HttpUserAgentParser.TryGetBrowser(null!, out _)); + Assert.Throws(() => HttpUserAgentParser.GetRobot(null!)); + Assert.Throws(() => HttpUserAgentParser.TryGetRobot(null!, out _)); + Assert.Throws(() => HttpUserAgentParser.GetMobileDevice(null!)); + Assert.Throws(() => HttpUserAgentParser.TryGetMobileDevice(null!, out _)); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index 76d4a51..2dbdfa6 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -68,12 +68,13 @@ private static readonly (string Token, string Name, HttpUserAgentPlatformType Ty ///
private static readonly (string Token, string Name)[] s_expectedBrowsers = [ - ("OPR", "Opera"), ("Silk", "Amazon Silk"), ("Flock", "Flock"), ("Edge", "Edge"), ("EdgA", "Edge"), ("Edg", "Edge"), ("Vivaldi", "Vivaldi"), - ("Brave Chrome", "Brave"), ("Chrome", "Chrome"), ("CriOS", "Chrome"), ("Opera.*?Version", "Opera"), ("Opera", "Opera"), - ("MSIE", "Internet Explorer"), ("Internet Explorer", "Internet Explorer"), ("Trident.* rv", "Internet Explorer"), - ("Shiira", "Shiira"), ("Firefox", "Firefox"), ("FxiOS", "Firefox"), ("Chimera", "Chimera"), ("Phoenix", "Phoenix"), - ("Firebird", "Firebird"), ("Camino", "Camino"), ("Netscape", "Netscape"), ("OmniWeb", "OmniWeb"), ("Version", "Safari"), - ("Mozilla", "Mozilla"), ("Konqueror", "Konqueror"), ("icab", "iCab"), ("Lynx", "Lynx"), ("Links", "Links"), + ("OPR", "Opera"), ("Silk", "Amazon Silk"), ("Flock", "Flock"), ("Edge", "Edge"), ("EdgA", "Edge"), ("Edg", "Edge"), ("EdgiOS", "Edge"), + ("Vivaldi", "Vivaldi"), ("Brave Chrome", "Brave"), ("SamsungBrowser", "Samsung Internet"), ("YaBrowser", "Yandex Browser"), + ("UCBrowser", "UC Browser"), ("UCMobile", "UC Browser"), ("Chrome", "Chrome"), ("CriOS", "Chrome"), ("HeadlessChrome", "Chrome"), + ("Opera.*?Version", "Opera"), ("Opera", "Opera"), ("MSIE", "Internet Explorer"), ("Internet Explorer", "Internet Explorer"), + ("Trident.* rv", "Internet Explorer"), ("Shiira", "Shiira"), ("Firefox", "Firefox"), ("FxiOS", "Firefox"), ("Chimera", "Chimera"), + ("Phoenix", "Phoenix"), ("Firebird", "Firebird"), ("Camino", "Camino"), ("Netscape", "Netscape"), ("OmniWeb", "OmniWeb"), + ("Version", "Safari"), ("Konqueror", "Konqueror"), ("icab", "iCab"), ("Lynx", "Lynx"), ("ELinks", "ELinks"), ("Links", "Links"), ("hotjava", "HotJava"), ("amaya", "Amaya"), ("IBrowse", "IBrowse"), ("Maxthon", "Maxthon"), ("ipod touch", "Apple iPod"), ("Ubuntu", "Ubuntu Web Browser"), ]; @@ -115,6 +116,25 @@ public void Browsers_Keep_Definitions() Assert.Equal(expected, actual); } + [Fact] + public void Browsers_Cover_All_Parser_Browser_Rules() + { + HashSet expectedNames = new(HttpUserAgentRules.Browsers.Select(static rule => rule.Name), StringComparer.Ordinal); + HashSet actualNames = new(HttpUserAgentStatics.Browsers.Values, StringComparer.Ordinal); + + Assert.Equal(expectedNames, actualNames); + + foreach ((string name, string detectToken, string? versionToken) in HttpUserAgentRules.Browsers) + { + string expectedToken = detectToken.TrimEnd('/'); + bool matched = HttpUserAgentStatics.Browsers.Any(entry => + string.Equals(entry.Value, name, StringComparison.Ordinal) + && entry.Key.ToString().StartsWith(expectedToken, StringComparison.Ordinal)); + + Assert.True(matched, $"HttpUserAgentStatics.Browsers is missing rule '{name}' ({detectToken}, {versionToken})."); + } + } + [Fact] public void Browsers_Use_Source_Generated_Regex_With_Previous_Options() { diff --git a/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs b/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs index dc2f87d..b29548b 100644 --- a/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs @@ -60,4 +60,54 @@ public void Keys_Are_Case_Sensitive() Assert.Equal(2, provider.CacheEntryCount); Assert.False(provider.HasCacheEntry("chrome/17")); } + + [Fact] + public void Default_Constructor_Uses_DefaultMaxCacheEntries() + { + HttpUserAgentParserCachedProvider provider = new(); + + Assert.Equal(HttpUserAgentParserCachedProvider.DefaultMaxCacheEntries, provider.MaxCacheEntries); + } + + [Theory] + [InlineData(0)] + [InlineData(-1)] + public void Constructor_Throws_When_MaxCacheEntries_Is_Not_Positive(int maxCacheEntries) + { + Assert.Throws(() => new HttpUserAgentParserCachedProvider(maxCacheEntries)); + } + + [Fact] + public void Cache_Rotates_When_MaxCacheEntries_Is_Reached() + { + HttpUserAgentParserCachedProvider provider = new(maxCacheEntries: 2); + + Assert.Equal(2, provider.MaxCacheEntries); + + _ = provider.Parse("Chrome/1"); + _ = provider.Parse("Chrome/2"); + Assert.Equal(2, provider.CacheEntryCount); + Assert.True(provider.HasCacheEntry("Chrome/1")); + Assert.True(provider.HasCacheEntry("Chrome/2")); + + // Cache hit does not rotate the cache. + Assert.Equal("1", provider.Parse("Chrome/1").Version); + Assert.Equal(2, provider.CacheEntryCount); + + // Next miss exceeds the limit and rotates the cache. + Assert.Equal("3", provider.Parse("Chrome/3").Version); + Assert.Equal(1, provider.CacheEntryCount); + Assert.True(provider.HasCacheEntry("Chrome/3")); + Assert.False(provider.HasCacheEntry("Chrome/1")); + Assert.False(provider.HasCacheEntry("Chrome/2")); + } + + [Fact] + public void Parse_Throws_ArgumentNullException_When_UserAgent_Is_Null() + { + HttpUserAgentParserCachedProvider provider = new(); + + Assert.Throws(() => provider.Parse(null!)); + Assert.Throws(() => provider.HasCacheEntry(null!)); + } } From 8619838b41fb5a392e3d2b266514561e996a2ab1 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:13:20 +0100 Subject: [PATCH 32/41] perf(parser): add 128-bit rule index, span overloads, and per-request caching - Expand UserAgentRuleIndex buckets to 128-bit masks (two Vector256 lanes) to eliminate bit aliasing across all built-in rule tables - Use UserAgentRuleIndex for standalone GetPlatform (and GetMobileDevice on net8.0; keep vectorized MobileMatcher on net9.0+) - Add public ReadOnlySpan overloads including zero-allocation TryGetBrowser(ReadOnlySpan, out string?, out ReadOnlySpan) - Guard ArrayPool.Shared.Return with try/finally in Detect - Cache parsed HttpUserAgentInformation per HttpContext in HttpUserAgentParserAccessor - Add unit tests (100% line/branch/method coverage) and DetectorWorkloadBenchmarks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../RealWorldUserAgentBenchmarks.cs | 113 +++++++++++++ .../HttpUserAgentParserAccessor.cs | 16 +- .../HttpUserAgentParser.cs | 151 +++++++++++++++--- .../HttpUserAgentRobotSet.cs | 12 +- src/HttpUserAgentParser/UserAgentRuleIndex.cs | 81 ++++++---- .../HttpUserAgentParserAccessorTests.cs | 28 ++++ .../HttpUserAgentParserTests.cs | 42 +++++ .../UserAgentRuleIndexTests.cs | 31 +++- 8 files changed, 410 insertions(+), 64 deletions(-) diff --git a/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs b/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs index c754ee0..968a58b 100644 --- a/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs +++ b/perf/HttpUserAgentParser.Benchmarks/RealWorldUserAgentBenchmarks.cs @@ -115,3 +115,116 @@ public int ParseBaseline() } #endif } + +/// +/// Benchmarks the standalone detector methods (GetPlatform, GetMobileDevice, GetBrowser and zero-allocation span TryGetBrowser) +/// over the mixed real-world workload. +/// +[MemoryDiagnoser] +public class DetectorWorkloadBenchmarks +{ + private const int OperationsPerInvoke = 5280; + + private string[] _userAgents; + + [GlobalSetup] + public void Setup() + { + IReadOnlyList source = UserAgentCatalog.All; + _userAgents = [.. Enumerable.Range(0, OperationsPerInvoke).Select(i => source[i % source.Count])]; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int GetPlatform() + { + int found = 0; + foreach (string userAgent in _userAgents) + { + if (Parser.GetPlatform(userAgent) is not null) + { + found++; + } + } + + return found; + } + +#if BENCHMARK_BASELINE + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int GetPlatformBaseline() + { + int found = 0; + foreach (string userAgent in _userAgents) + { + if (Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.GetPlatform(userAgent) is not null) + { + found++; + } + } + + return found; + } +#endif + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int GetMobileDevice() + { + int found = 0; + foreach (string userAgent in _userAgents) + { + if (Parser.GetMobileDevice(userAgent) is not null) + { + found++; + } + } + + return found; + } + +#if BENCHMARK_BASELINE + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int GetMobileDeviceBaseline() + { + int found = 0; + foreach (string userAgent in _userAgents) + { + if (Baseline::MyCSharp.HttpUserAgentParser.HttpUserAgentParser.GetMobileDevice(userAgent) is not null) + { + found++; + } + } + + return found; + } +#endif + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int GetBrowser() + { + int found = 0; + foreach (string userAgent in _userAgents) + { + if (Parser.GetBrowser(userAgent) is not null) + { + found++; + } + } + + return found; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public int TryGetBrowserSpan() + { + int found = 0; + foreach (string userAgent in _userAgents) + { + if (Parser.TryGetBrowser(userAgent.AsSpan(), out _, out _)) + { + found++; + } + } + + return found; + } +} diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs index 16690d9..fbe2150 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs @@ -18,6 +18,7 @@ public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAg : IHttpUserAgentParserAccessor { private readonly IHttpUserAgentParserProvider _httpUserAgentParser = httpUserAgentParser; + private readonly object _httpContextItemKey = new(); /// public string? GetHttpContextUserAgent(HttpContext httpContext) @@ -26,12 +27,19 @@ public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAg /// public HttpUserAgentInformation? Get(HttpContext httpContext) { - string? httpUserAgent = GetHttpContextUserAgent(httpContext); - if (string.IsNullOrWhiteSpace(httpUserAgent)) + ArgumentNullException.ThrowIfNull(httpContext); + + if (httpContext.Items.TryGetValue(_httpContextItemKey, out object? cached)) { - return null; + return (HttpUserAgentInformation?)cached; } - return _httpUserAgentParser.Parse(httpUserAgent); + string? httpUserAgent = GetHttpContextUserAgent(httpContext); + HttpUserAgentInformation? result = string.IsNullOrWhiteSpace(httpUserAgent) + ? null + : _httpUserAgentParser.Parse(httpUserAgent); + + httpContext.Items[_httpContextItemKey] = result; + return result; } } diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.cs b/src/HttpUserAgentParser/HttpUserAgentParser.cs index f38fe33..6f2ca8a 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.cs +++ b/src/HttpUserAgentParser/HttpUserAgentParser.cs @@ -61,14 +61,14 @@ private static HttpUserAgentInformation ParseInternal(string userAgent, HttpUser userAgent = Cleanup(userAgent); return robots.MatchFirst(userAgent) is { } first ? HttpUserAgentInformation.CreateForRobot(userAgent, first) - : Detect(userAgent, robots, AnalyzeUserAgent); + : Detect(userAgent.AsSpan(), (userAgent, robots), static (original, ua, state) => AnalyzeUserAgent(state.userAgent, original, ua, state.robots)); } - private static HttpUserAgentInformation AnalyzeUserAgent(string userAgent, ReadOnlySpan ua, HttpUserAgentRobotSet robots) + private static HttpUserAgentInformation AnalyzeUserAgent(string userAgent, ReadOnlySpan original, ReadOnlySpan ua, HttpUserAgentRobotSet robots) { UserAgentRuleIndex.RuleMasks candidates = UserAgentRuleIndex.BuiltIn.Find(ua); - ulong robotMask = ReferenceEquals(robots, HttpUserAgentRules.DefaultRobotSet) ? candidates.Robots : ulong.MaxValue; - if (robots.MatchAfterFirst(userAgent, ua, robotMask) is { } robotName) + UInt128 robotMask = ReferenceEquals(robots, HttpUserAgentRules.DefaultRobotSet) ? candidates.Robots : UInt128.MaxValue; + if (robots.MatchAfterFirst(original, ua, robotMask) is { } robotName) { return HttpUserAgentInformation.CreateForRobot(userAgent, robotName); } @@ -84,22 +84,19 @@ private static HttpUserAgentInformation AnalyzeUserAgent(string userAgent, ReadO return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType); } - private delegate T Detector(string original, ReadOnlySpan decoded, TState state); + private delegate T Detector(ReadOnlySpan original, ReadOnlySpan decoded, TState state); private delegate T ProductDetector(ReadOnlySpan products); - private static T DetectProduct(string userAgent, ProductDetector detector) + private static T DetectProduct(ReadOnlySpan userAgent, ProductDetector detector) => Detect(userAgent, detector, static (_, ua, detect) => detect(ua)); // IIS logs use '+' for spaces, including spaces inside product names. Keep the original // string in the result and share the decoded span across all detectors. - private static T Detect(string userAgent, TState state, Detector detect) + private static T Detect(ReadOnlySpan ua, TState state, Detector detect) { - ArgumentNullException.ThrowIfNull(userAgent); - - ReadOnlySpan ua = userAgent.AsSpan(); if (!ua.Contains('+')) { - return detect(userAgent, ua, state); + return detect(ua, ua, state); } // 512 chars are 1 KiB of stack. The parser runs at whatever stack depth the caller has already @@ -113,15 +110,20 @@ private static T Detect(string userAgent, TState state, Detector decoded = stackalloc char[MaxStackLength]; decoded = decoded[..ua.Length]; ua.Replace(decoded, '+', ' '); - return detect(userAgent, decoded, state); + return detect(ua, decoded, state); } char[] rented = ArrayPool.Shared.Rent(ua.Length); - Span rentedSpan = rented.AsSpan(0, ua.Length); - ua.Replace(rentedSpan, '+', ' '); - T result = detect(userAgent, rentedSpan, state); - ArrayPool.Shared.Return(rented); - return result; + try + { + Span rentedSpan = rented.AsSpan(0, ua.Length); + ua.Replace(rentedSpan, '+', ' '); + return detect(ua, rentedSpan, state); + } + finally + { + ArrayPool.Shared.Return(rented); + } } /// @@ -137,9 +139,18 @@ public static string Cleanup(string userAgent) /// returns the platform or null /// public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent) - => DetectProduct(userAgent, static ua => FindPlatform(ua, ulong.MaxValue)); + { + ArgumentNullException.ThrowIfNull(userAgent); + return GetPlatform(userAgent.AsSpan()); + } - private static HttpUserAgentPlatformInformation? FindPlatform(ReadOnlySpan ua, ulong mask) + /// + /// returns the platform or null + /// + public static HttpUserAgentPlatformInformation? GetPlatform(ReadOnlySpan userAgent) + => DetectProduct(userAgent, static ua => FindPlatform(ua, UserAgentRuleIndex.BuiltIn.Find(ua).Platforms)); + + private static HttpUserAgentPlatformInformation? FindPlatform(ReadOnlySpan ua, UInt128 mask) { (string Token, HttpUserAgentPlatformInformation Platform)[] rules = HttpUserAgentRules.Platforms; UserAgentRuleIndex.Candidates candidates = new(mask, rules.Length); @@ -181,6 +192,15 @@ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out Http return platform is not null; } + /// + /// returns true if platform was found + /// + public static bool TryGetPlatform(ReadOnlySpan userAgent, [NotNullWhen(true)] out HttpUserAgentPlatformInformation? platform) + { + platform = GetPlatform(userAgent); + return platform is not null; + } + /// /// returns the browser or null /// @@ -190,9 +210,26 @@ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out Http /// or after a space, tab, +, ;, (, ) or ,. /// public static (string Name, string? Version)? GetBrowser(string userAgent) + { + ArgumentNullException.ThrowIfNull(userAgent); + return GetBrowser(userAgent.AsSpan()); + } + + /// + /// returns the browser or null + /// + /// + /// Rules are evaluated in priority order (specific browsers before the browsers their user agents contain); the first rule + /// with a version wins. Browser and version tokens only count at the start of a token, i.e. at the beginning of the user agent + /// or after a space, tab, +, ;, (, ) or ,. + /// + public static (string Name, string? Version)? GetBrowser(ReadOnlySpan userAgent) => DetectProduct(userAgent, static ua => FindBrowser(ua, UserAgentRuleIndex.BuiltIn.Find(ua).Browsers)); - private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua, ulong mask) + private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua, UInt128 mask) + => FindBrowserRange(ua, mask) is { } match ? (match.Name, ua[match.Version].ToString()) : null; + + private static (string Name, Range Version)? FindBrowserRange(ReadOnlySpan ua, UInt128 mask) { (string Name, string DetectToken, string? VersionToken)[] rules = HttpUserAgentRules.Browsers; UserAgentRuleIndex.Candidates candidates = new(mask, rules.Length); @@ -207,7 +244,7 @@ private static (string Name, string? Version)? FindBrowser(ReadOnlySpan ua if (TryReadBrowserVersion(ua, detectToken, detectIndex, versionToken, out Range version)) { - return (name, ua[version].ToString()); + return (name, version); } } @@ -351,13 +388,46 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri return browser is not null; } + /// + /// returns true if browser was found + /// + public static bool TryGetBrowser(ReadOnlySpan userAgent, [NotNullWhen(true)] out (string Name, string? Version)? browser) + { + browser = GetBrowser(userAgent); + return browser is not null; + } + + /// + /// returns true if browser was found, slicing directly from without allocating a version string + /// + public static bool TryGetBrowser(ReadOnlySpan userAgent, [NotNullWhen(true)] out string? name, out ReadOnlySpan version) + { + if (DetectProduct(userAgent, static ua => FindBrowserRange(ua, UserAgentRuleIndex.BuiltIn.Find(ua).Browsers)) is { } match) + { + name = match.Name; + version = userAgent[match.Version]; + return true; + } + + name = null; + version = default; + return false; + } + /// /// returns the robot or null /// public static string? GetRobot(string userAgent) { ArgumentNullException.ThrowIfNull(userAgent); + return GetRobot(userAgent.AsSpan()); + } + /// + /// returns the robot or null + /// + public static string? GetRobot(ReadOnlySpan userAgent) + { HttpUserAgentRobotSet robots = HttpUserAgentRules.RobotSet; return robots.MatchFirst(userAgent) ?? Detect(userAgent, robots, static (original, decoded, rules) => rules.MatchAfterFirst(original, decoded)); @@ -372,15 +442,39 @@ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? return robotName is not null; } + /// + /// returns true if robot was found + /// + public static bool TryGetRobot(ReadOnlySpan userAgent, [NotNullWhen(true)] out string? robotName) + { + robotName = GetRobot(userAgent); + return robotName is not null; + } + /// /// returns the device or null /// public static string? GetMobileDevice(string userAgent) - => DetectProduct(userAgent, static ua => FindMobileDevice(ua, ulong.MaxValue)); + { + ArgumentNullException.ThrowIfNull(userAgent); + return GetMobileDevice(userAgent.AsSpan()); + } - private static string? FindMobileDevice(ReadOnlySpan ua, ulong mask) + /// + /// returns the device or null + /// + public static string? GetMobileDevice(ReadOnlySpan userAgent) +#if NET9_0_OR_GREATER + // On .NET 9+, MobileMatcher uses vectorized SearchValues, which is faster for a standalone + // device lookup than indexing all four tables in UserAgentRuleIndex. + => DetectProduct(userAgent, static ua => FindMobileDevice(ua, UInt128.MaxValue)); +#else + => DetectProduct(userAgent, static ua => FindMobileDevice(ua, UserAgentRuleIndex.BuiltIn.Find(ua).Devices)); +#endif + + private static string? FindMobileDevice(ReadOnlySpan ua, UInt128 mask) { - int index = mask != ulong.MaxValue + int index = mask != UInt128.MaxValue ? UserAgentRuleIndex.FindKey(ua, HttpUserAgentRules.MobileKeys, mask) : HttpUserAgentRules.MobileMatcher.Find(ua, 0); return index >= 0 ? HttpUserAgentRules.Mobiles[index].Value : null; @@ -395,6 +489,15 @@ public static bool TryGetMobileDevice(string userAgent, [NotNullWhen(true)] out return device is not null; } + /// + /// returns true if device was found + /// + public static bool TryGetMobileDevice(ReadOnlySpan userAgent, [NotNullWhen(true)] out string? device) + { + device = GetMobileDevice(userAgent); + return device is not null; + } + /// /// Finds the first ASCII digit and reads subsequent digits and dots within the current product token. /// diff --git a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs index 4ab04f6..a3f3312 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRobotSet.cs @@ -40,9 +40,15 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) /// /// Matches both IIS-encoded names and literal plus signs in custom keys, in configured priority order. /// - public string? MatchAfterFirst(string original, ReadOnlySpan decoded, ulong mask = ulong.MaxValue) + public string? MatchAfterFirst(ReadOnlySpan original, ReadOnlySpan decoded) + => MatchAfterFirst(original, decoded, UInt128.MaxValue); + + /// + /// Matches both IIS-encoded names and literal plus signs in custom keys, in configured priority order. + /// + public string? MatchAfterFirst(ReadOnlySpan original, ReadOnlySpan decoded, UInt128 mask) { - int index = mask != ulong.MaxValue + int index = mask != UInt128.MaxValue ? UserAgentRuleIndex.FindKey(decoded, Keys, mask) : FindAfterFirst(decoded); foreach (int literal in _literalPlusRules) @@ -52,7 +58,7 @@ public HttpUserAgentRobotSet((string Key, string Value)[] robots) break; } - if (original.AsSpan().Contains(Keys[literal], StringComparison.OrdinalIgnoreCase)) + if (original.Contains(Keys[literal], StringComparison.OrdinalIgnoreCase)) { return ReadOnlyEntries[literal].Value; } diff --git a/src/HttpUserAgentParser/UserAgentRuleIndex.cs b/src/HttpUserAgentParser/UserAgentRuleIndex.cs index 2404a29..9161d5f 100644 --- a/src/HttpUserAgentParser/UserAgentRuleIndex.cs +++ b/src/HttpUserAgentParser/UserAgentRuleIndex.cs @@ -13,18 +13,28 @@ internal sealed class UserAgentRuleIndex private const int BucketCount = 2048; // For longer headers the individual vectorized substring searches cost less than indexing the full input. private const int MaxIndexedLength = 255; - private readonly Vector256[] _buckets = new Vector256[BucketCount]; - private readonly Vector256 _always; + + [StructLayout(LayoutKind.Auto)] + private struct Bucket + { + public Vector256 Low; + public Vector256 High; + } + + private readonly Bucket[] _buckets = new Bucket[BucketCount]; + private readonly Bucket _always; // Built only when a shared filter is needed. The first robot rule can return before this point. public static UserAgentRuleIndex BuiltIn { get; } = new( HttpUserAgentRules.DefaultRobotSet.Keys, Array.ConvertAll(HttpUserAgentRules.Platforms, static r => r.Token), HttpUserAgentRules.MobileKeys, Array.ConvertAll(HttpUserAgentRules.Browsers, static r => r.DetectToken)); - // Each lane belongs to one rule table. Register both overlapping triples of the first four - // characters: one triple must start at an even offset, regardless of the key's position. + // Each lane belongs to one rule table, split across Low (rules 0..63) and High (rules 64..127) + // so every built-in rule table fits without bit aliasing. Register both overlapping triples of the + // first four characters: one triple must start at an even offset, regardless of the key's position. public UserAgentRuleIndex(string[] robots, string[] platforms, string[] devices, string[] browsers) { + Bucket always = default; string[][] tables = [robots, platforms, devices, browsers]; for (int table = 0; table < tables.Length; table++) { @@ -32,23 +42,33 @@ public UserAgentRuleIndex(string[] robots, string[] platforms, string[] devices, for (int rule = 0; rule < keys.Length; rule++) { string key = keys[rule]; - ulong bit = 1UL << (rule % 64); if (key.Length < 4 || !Ascii.IsValid(key)) { - _always = _always.WithElement(table, _always.GetElement(table) | bit); + AddBit(ref always, table, rule); continue; } - Add(Hash(key[0], key[1], key[2]), table, bit); - Add(Hash(key[1], key[2], key[3]), table, bit); + AddBit(ref _buckets[Hash(key[0], key[1], key[2])], table, rule); + AddBit(ref _buckets[Hash(key[1], key[2], key[3])], table, rule); } } + + _always = always; } - private void Add(int hash, int table, ulong bit) + private static void AddBit(ref Bucket target, int table, int rule) { - ref Vector256 bucket = ref _buckets[hash]; - bucket = bucket.WithElement(table, bucket.GetElement(table) | bit); + int slot = rule & 127; + if (slot < 64) + { + ulong bit = 1UL << slot; + target.Low = target.Low.WithElement(table, target.Low.GetElement(table) | bit); + } + else + { + ulong bit = 1UL << (slot - 64); + target.High = target.High.WithElement(table, target.High.GetElement(table) | bit); + } } // Fold ASCII letters to the same bucket. Punctuation and hash collisions can only add candidates. @@ -59,28 +79,32 @@ public RuleMasks Find(ReadOnlySpan input) if (input.Length > MaxIndexedLength || !Ascii.IsValid(input)) { // Non-ASCII headers also require the full ordinal case-folding semantics. - return new RuleMasks(Vector256.Create(ulong.MaxValue)); + Vector256 all = Vector256.Create(ulong.MaxValue); + return new RuleMasks(all, all); } - Vector256 candidates = _always; + Vector256 low = _always.Low; + Vector256 high = _always.High; for (int i = 2; i < input.Length; i += 2) { - candidates |= _buckets[Hash(input[i - 2], input[i - 1], input[i])]; + ref readonly Bucket bucket = ref _buckets[Hash(input[i - 2], input[i - 1], input[i])]; + low |= bucket.Low; + high |= bucket.High; } - return new RuleMasks(candidates); + return new RuleMasks(low, high); } [StructLayout(LayoutKind.Auto)] - internal readonly struct RuleMasks(Vector256 bits) + internal readonly struct RuleMasks(Vector256 low, Vector256 high) { - public ulong Robots => bits.GetElement(0); - public ulong Platforms => bits.GetElement(1); - public ulong Devices => bits.GetElement(2); - public ulong Browsers => bits.GetElement(3); + public UInt128 Robots => new(high.GetElement(0), low.GetElement(0)); + public UInt128 Platforms => new(high.GetElement(1), low.GetElement(1)); + public UInt128 Devices => new(high.GetElement(2), low.GetElement(2)); + public UInt128 Browsers => new(high.GetElement(3), low.GetElement(3)); } - public static int FindKey(ReadOnlySpan input, string[] keys, ulong mask) + public static int FindKey(ReadOnlySpan input, string[] keys, UInt128 mask) { Candidates candidates = new(mask, keys.Length); for (int i = candidates.Next(); i >= 0; i = candidates.Next()) @@ -94,25 +118,26 @@ public static int FindKey(ReadOnlySpan input, string[] keys, ulong mask) return -1; } - // The same 64 bits cover each successive block of rules. The full key confirms the match. + // The 128 bits cover each successive block of 128 rules. The full key confirms the match. [StructLayout(LayoutKind.Auto)] - internal struct Candidates(ulong mask, int count) + internal struct Candidates(UInt128 mask, int count) { - private readonly ulong _mask = mask; - private ulong _remaining = mask; + private readonly ulong _lowMask = (ulong)mask; + private readonly ulong _highMask = (ulong)(mask >> 64); + private ulong _remaining = (ulong)mask; private int _offset; public int Next() { - if (_remaining == 0) + while (_remaining == 0) { _offset += 64; - if (_mask == 0 || _offset >= count) + if (_offset >= count) { return -1; } - _remaining = _mask; + _remaining = (_offset & 64) != 0 ? _highMask : _lowMask; } int index = _offset + BitOperations.TrailingZeroCount(_remaining); diff --git a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs index af7e5cb..ff26e4a 100644 --- a/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs +++ b/tests/HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs @@ -43,4 +43,32 @@ public void Get_Returns_Null_For_An_Empty_User_Agent(string userAgent) Assert.Null(accessor.Get(HttpContextTestHelpers.GetHttpContext(userAgent))); _parserMock.DidNotReceiveWithAnyArgs().Parse(default!); } + + [Fact] + public void Get_Caches_Result_Per_HttpContext() + { + const string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0"; + HttpUserAgentInformation expected = HttpUserAgentInformation.Parse(userAgent); + _parserMock.Parse(userAgent).Returns(expected); + + HttpContext httpContext = HttpContextTestHelpers.GetHttpContext(userAgent); + HttpUserAgentParserAccessor accessor = new(_parserMock); + + Assert.Equal(expected, accessor.Get(httpContext)); + Assert.Equal(expected, accessor.Get(httpContext)); + _parserMock.Received(1).Parse(userAgent); + + DefaultHttpContext emptyContext = new(); + Assert.Null(accessor.Get(emptyContext)); + Assert.Null(accessor.Get(emptyContext)); + _parserMock.Received(1).Parse(Arg.Any()); + } + + [Fact] + public void Get_Throws_When_HttpContext_Is_Null() + { + HttpUserAgentParserAccessor accessor = new(_parserMock); + + Assert.Throws(() => accessor.Get(null!)); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 77d773d..74cf5bb 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -469,4 +469,46 @@ public void Public_Methods_Throw_ArgumentNullException_When_UserAgent_Is_Null() Assert.Throws(() => HttpUserAgentParser.GetMobileDevice(null!)); Assert.Throws(() => HttpUserAgentParser.TryGetMobileDevice(null!, out _)); } + + [Fact] + public void Span_Overloads_Match_String_Overloads_Including_Zero_Alloc_Browser_Version() + { + ReadOnlySpan ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1"; + + Assert.Equal("iOS", HttpUserAgentParser.GetPlatform(ua)?.Name); + Assert.True(HttpUserAgentParser.TryGetPlatform(ua, out HttpUserAgentPlatformInformation? platform)); + Assert.Equal("iOS", platform.Value.Name); + + Assert.Equal(("Chrome", "90.0.4430.78"), HttpUserAgentParser.GetBrowser(ua)); + Assert.True(HttpUserAgentParser.TryGetBrowser(ua, out (string Name, string? Version)? browser)); + Assert.Equal(("Chrome", "90.0.4430.78"), browser); + + Assert.True(HttpUserAgentParser.TryGetBrowser(ua, out string? browserName, out ReadOnlySpan browserVersion)); + Assert.Equal("Chrome", browserName); + Assert.Equal("90.0.4430.78", browserVersion.ToString()); + + Assert.Equal("Apple iPhone", HttpUserAgentParser.GetMobileDevice(ua)); + Assert.True(HttpUserAgentParser.TryGetMobileDevice(ua, out string? device)); + Assert.Equal("Apple iPhone", device); + Assert.Equal("Apple iPhone", HttpUserAgentParser.GetMobileDevice(new string('x', 260) + " iPhone")); + + ReadOnlySpan iisUa = "Mozilla/5.0+(Windows+NT+10.0)+Brave+Chrome/99.1"; + Assert.True(HttpUserAgentParser.TryGetBrowser(iisUa, out string? iisName, out ReadOnlySpan iisVersion)); + Assert.Equal("Brave", iisName); + Assert.Equal("99.1", iisVersion.ToString()); + + ReadOnlySpan robotUa = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; + Assert.Equal("Googlebot", HttpUserAgentParser.GetRobot(robotUa)); + Assert.True(HttpUserAgentParser.TryGetRobot(robotUa, out string? robotName)); + Assert.Equal("Googlebot", robotName); + + ReadOnlySpan unknown = "CustomClient"; + Assert.False(HttpUserAgentParser.TryGetPlatform(unknown, out _)); + Assert.False(HttpUserAgentParser.TryGetBrowser(unknown, out _)); + Assert.False(HttpUserAgentParser.TryGetBrowser(unknown, out string? noName, out ReadOnlySpan noVersion)); + Assert.Null(noName); + Assert.True(noVersion.IsEmpty); + Assert.False(HttpUserAgentParser.TryGetRobot(unknown, out _)); + Assert.False(HttpUserAgentParser.TryGetMobileDevice(unknown, out _)); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs b/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs index 68ef69b..74eaf6f 100644 --- a/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/UserAgentRuleIndexTests.cs @@ -24,24 +24,45 @@ public void Built_In_Keys_Are_Candidates_At_Either_Alignment() { string header = prefix + keys[i].ToUpperInvariant(); UserAgentRuleIndex.RuleMasks masks = UserAgentRuleIndex.BuiltIn.Find(header); - ulong[] lanes = [masks.Robots, masks.Platforms, masks.Devices, masks.Browsers]; + UInt128[] lanes = [masks.Robots, masks.Platforms, masks.Devices, masks.Browsers]; int expected = Array.FindIndex(keys, key => header.Contains(key, StringComparison.OrdinalIgnoreCase)); - Assert.NotEqual(0UL, lanes[table] & (1UL << (i % 64))); + Assert.NotEqual(UInt128.Zero, lanes[table] & ((UInt128)1 << (i % 128))); Assert.Equal(expected, UserAgentRuleIndex.FindKey(header, keys, lanes[table])); } } } } + [Fact] + public void Built_In_Rule_Tables_Fit_In_128_Bits_Without_Aliasing() + { + Assert.True(HttpUserAgentRules.DefaultRobotSet.Keys.Length <= 128); + Assert.True(HttpUserAgentRules.Platforms.Length <= 128); + Assert.True(HttpUserAgentRules.MobileKeys.Length <= 128); + Assert.True(HttpUserAgentRules.Browsers.Length <= 128); + } + + [Fact] + public void Rule_Tables_Beyond_128_Entries_Match_Exact_Key() + { + string[] keys = [.. Enumerable.Range(0, 130).Select(static i => $"RuleKey{i:D3}")]; + UserAgentRuleIndex index = new(keys, [], [], []); + + Assert.Equal(129, UserAgentRuleIndex.FindKey("RuleKey129", keys, index.Find("RuleKey129").Robots)); + Assert.Equal(65, UserAgentRuleIndex.FindKey("RuleKey065", keys, index.Find("RuleKey065").Robots)); + Assert.Equal(-1, UserAgentRuleIndex.FindKey("NoMatchHere", keys, index.Find("NoMatchHere").Robots)); + } + [Fact] public void Long_Headers_Use_All_Rules_At_The_Length_Threshold() { UserAgentRuleIndex index = new(["Safari"], [], [], []); - Assert.Equal(0UL, index.Find(new string('x', 255)).Robots); + Assert.Equal(UInt128.Zero, index.Find(new string('x', 255)).Robots); string header = new string('x', 250) + "Safari"; - ulong mask = index.Find(header).Robots; - Assert.Equal(ulong.MaxValue, mask); + UInt128 mask = index.Find(header).Robots; + Assert.Equal(UInt128.MaxValue, mask); Assert.Equal(0, UserAgentRuleIndex.FindKey(header, ["Safari"], mask)); + Assert.Equal(-1, UserAgentRuleIndex.FindKey(new string('x', 260), ["Safari"], UInt128.MaxValue)); } [Fact] From e803502e32f208a2176db8057be669850b03637a Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:17:51 +0100 Subject: [PATCH 33/41] feat(parser): add equality operators to HttpUserAgentInformation and HttpUserAgentPlatformInformation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/HttpUserAgentParser/HttpUserAgentInformation.cs | 10 ++++++++++ .../HttpUserAgentPlatformInformation.cs | 10 ++++++++++ .../HttpUserAgentInformationTests.cs | 4 ++++ .../HttpUserAgentPlatformInformationTests.cs | 7 ++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/HttpUserAgentParser/HttpUserAgentInformation.cs b/src/HttpUserAgentParser/HttpUserAgentInformation.cs index 05ccbc3..ac1a80f 100644 --- a/src/HttpUserAgentParser/HttpUserAgentInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentInformation.cs @@ -89,4 +89,14 @@ public bool Equals(HttpUserAgentInformation other) /// public override int GetHashCode() => HashCode.Combine(UserAgent, Type, Name, Version); + + /// + /// Returns if both instances are equal. + /// + public static bool operator ==(HttpUserAgentInformation left, HttpUserAgentInformation right) => left.Equals(right); + + /// + /// Returns if both instances are not equal. + /// + public static bool operator !=(HttpUserAgentInformation left, HttpUserAgentInformation right) => !left.Equals(right); } diff --git a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs index 022bcad..7aef16b 100644 --- a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs @@ -64,4 +64,14 @@ public bool Equals(HttpUserAgentPlatformInformation other) /// public override int GetHashCode() => HashCode.Combine(Name, PlatformType); + + /// + /// Returns if both instances are equal. + /// + public static bool operator ==(HttpUserAgentPlatformInformation left, HttpUserAgentPlatformInformation right) => left.Equals(right); + + /// + /// Returns if both instances are not equal. + /// + public static bool operator !=(HttpUserAgentPlatformInformation left, HttpUserAgentPlatformInformation right) => !left.Equals(right); } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs index 6abd216..3f2907a 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs @@ -75,6 +75,8 @@ public void Equals_Same_Values() Assert.True(first.Equals(second)); Assert.True(first.Equals((object)second)); + Assert.True(first == second); + Assert.False(first != second); Assert.Equal(first.GetHashCode(), second.GetHashCode()); } @@ -100,6 +102,8 @@ public void Not_Equals_When_Any_Property_Differs(int property) Assert.False(info.Equals(other)); Assert.False(info.Equals((object)other)); + Assert.False(info == other); + Assert.True(info != other); } [Fact] diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs index 9c497e9..d7bc04d 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs @@ -47,6 +47,8 @@ public void Equals_Same_Regex_Name_And_Type() Assert.True(lazy.Equals(eager)); Assert.True(lazy.Equals((object)eager)); + Assert.True(lazy == eager); + Assert.False(lazy != eager); Assert.Equal(lazy.GetHashCode(), eager.GetHashCode()); } @@ -56,7 +58,10 @@ public void Not_Equals_When_Any_Property_Differs() Regex regex = EmptyRegex(); HttpUserAgentPlatformInformation info = new(regex, "Android", HttpUserAgentPlatformType.Android); - Assert.False(info.Equals(new HttpUserAgentPlatformInformation(regex, "Android", HttpUserAgentPlatformType.Linux))); + HttpUserAgentPlatformInformation differentType = new(regex, "Android", HttpUserAgentPlatformType.Linux); + Assert.False(info.Equals(differentType)); + Assert.False(info == differentType); + Assert.True(info != differentType); Assert.False(info.Equals(new HttpUserAgentPlatformInformation(regex, "android", HttpUserAgentPlatformType.Android))); Assert.False(info.Equals(new HttpUserAgentPlatformInformation(OtherRegex(), "Android", HttpUserAgentPlatformType.Android))); Assert.False(info.Equals((object?)null)); From 355a44dca9fdfb877cef9a7f2a1e63acc84d3562 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:22:08 +0100 Subject: [PATCH 34/41] chore(build): enable package validation, deterministic CI builds, and NuGet package source mapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Directory.Build.props | 3 +++ NuGet.config | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index 5bd35c6..aa7be99 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -52,6 +52,9 @@ true 2.12 true + true + true + true HTTP User Agent Parser for .NET https://github.com/mycsharp/HttpUserAgentParser diff --git a/NuGet.config b/NuGet.config index 5368ac4..fa8a1cb 100644 --- a/NuGet.config +++ b/NuGet.config @@ -6,4 +6,10 @@ + + + + + + \ No newline at end of file From 407bc2f17dc804c12c3f8b4ab2fd788c1708515f Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:22:08 +0100 Subject: [PATCH 35/41] feat(parser): add IsUnknown, ToString, Macintosh fallback, and modern browsers/WebViews MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add IsUnknown() extension method and ToString() overrides on HttpUserAgentInformation and HttpUserAgentPlatformInformation - Recognize Macintosh without OS X as MacOS fallback - Add DuckDuckGo, Whale, QQ Browser, Huawei Browser, Miui Browser, Instagram, and Facebook (FBAV) browser rules and source-generated regexes - Update tests and catalog (100% line/branch/method coverage across net8.0–net11.0) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../HttpUserAgentInformation.cs | 8 ++++++++ .../HttpUserAgentInformationExtensions.cs | 5 +++++ .../HttpUserAgentPlatformInformation.cs | 4 ++++ .../HttpUserAgentRegexes.cs | 11 ++++++++++ src/HttpUserAgentParser/HttpUserAgentRules.cs | 9 +++++++++ .../HttpUserAgentStatics.cs | 8 ++++++++ .../UserAgentCatalog.cs | 4 ++-- ...HttpUserAgentInformationExtensionsTests.cs | 1 + .../HttpUserAgentInformationTests.cs | 8 ++++++++ .../HttpUserAgentParserTests.cs | 20 +++++++++++++++++++ .../HttpUserAgentPlatformInformationTests.cs | 9 +++++++++ .../HttpUserAgentStaticsTests.cs | 5 ++++- 12 files changed, 89 insertions(+), 3 deletions(-) diff --git a/src/HttpUserAgentParser/HttpUserAgentInformation.cs b/src/HttpUserAgentParser/HttpUserAgentInformation.cs index ac1a80f..72aca42 100644 --- a/src/HttpUserAgentParser/HttpUserAgentInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentInformation.cs @@ -99,4 +99,12 @@ public bool Equals(HttpUserAgentInformation other) /// Returns if both instances are not equal. ///
public static bool operator !=(HttpUserAgentInformation left, HttpUserAgentInformation right) => !left.Equals(right); + + /// + public override string ToString() => (Name, Version) switch + { + ({ } name, { } version) => $"{Type}: {name} {version}", + ({ } name, null) => $"{Type}: {name}", + _ => Type.ToString(), + }; } diff --git a/src/HttpUserAgentParser/HttpUserAgentInformationExtensions.cs b/src/HttpUserAgentParser/HttpUserAgentInformationExtensions.cs index 409bafd..64fa350 100644 --- a/src/HttpUserAgentParser/HttpUserAgentInformationExtensions.cs +++ b/src/HttpUserAgentParser/HttpUserAgentInformationExtensions.cs @@ -22,6 +22,11 @@ public static class HttpUserAgentInformationExtensions ///
public static bool IsBrowser(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Browser); + /// + /// Tests if is of type + /// + public static bool IsUnknown(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Unknown); + /// /// returns true if agent is a mobile device /// diff --git a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs index 7aef16b..d19b053 100644 --- a/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs +++ b/src/HttpUserAgentParser/HttpUserAgentPlatformInformation.cs @@ -74,4 +74,8 @@ public bool Equals(HttpUserAgentPlatformInformation other) /// Returns if both instances are not equal. /// public static bool operator !=(HttpUserAgentPlatformInformation left, HttpUserAgentPlatformInformation right) => !left.Equals(right); + + /// + public override string ToString() + => string.IsNullOrEmpty(Name) ? PlatformType.ToString() : $"{Name} ({PlatformType})"; } diff --git a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs index 3bc154e..85d29cb 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRegexes.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRegexes.cs @@ -57,6 +57,7 @@ internal enum HttpUserAgentPlatformRegexId : byte Gnu, Unix, Symbian, + Macintosh, } /// @@ -123,6 +124,7 @@ internal static partial class HttpUserAgentRegexes HttpUserAgentPlatformRegexId.Gnu => Gnu(), HttpUserAgentPlatformRegexId.Unix => Unix(), HttpUserAgentPlatformRegexId.Symbian => Symbian(), + HttpUserAgentPlatformRegexId.Macintosh => Macintosh(), _ => null, }; @@ -170,6 +172,7 @@ internal static partial class HttpUserAgentRegexes [GeneratedRegex(@"gnu", Options, MatchTimeoutMilliseconds)] private static partial Regex Gnu(); [GeneratedRegex(@"unix", Options, MatchTimeoutMilliseconds)] private static partial Regex Unix(); [GeneratedRegex(@"symbian", Options, MatchTimeoutMilliseconds)] private static partial Regex Symbian(); + [GeneratedRegex(@"macintosh", Options, MatchTimeoutMilliseconds)] private static partial Regex Macintosh(); // Browsers: pattern = "{token}.*?([0-9\.]+)" // The numbered group is public behavior: consumers read the version from Groups[1], so ExplicitCapture must not be used. @@ -216,5 +219,13 @@ internal static partial class HttpUserAgentRegexes [GeneratedRegex(@"UCBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserUCBrowser(); [GeneratedRegex(@"UCMobile.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserUCMobile(); [GeneratedRegex(@"HeadlessChrome.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserHeadlessChrome(); + [GeneratedRegex(@"DuckDuckGo.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserDuckDuckGo(); + [GeneratedRegex(@"Whale.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserWhale(); + [GeneratedRegex(@"QQBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserQQBrowser(); + [GeneratedRegex(@"HuaweiBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserHuaweiBrowser(); + [GeneratedRegex(@"XiaoMi/MiuiBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserXiaoMiMiuiBrowser(); + [GeneratedRegex(@"MiuiBrowser.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserMiuiBrowser(); + [GeneratedRegex(@"Instagram.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserInstagram(); + [GeneratedRegex(@"FBAV.*?([0-9\.]+)", Options, MatchTimeoutMilliseconds)] internal static partial Regex BrowserFbav(); #pragma warning restore MA0023 } diff --git a/src/HttpUserAgentParser/HttpUserAgentRules.cs b/src/HttpUserAgentParser/HttpUserAgentRules.cs index 0107360..9f7dfbe 100644 --- a/src/HttpUserAgentParser/HttpUserAgentRules.cs +++ b/src/HttpUserAgentParser/HttpUserAgentRules.cs @@ -72,6 +72,7 @@ internal static class HttpUserAgentRules ("bsdi", new(HttpUserAgentPlatformRegexId.Bsdi, "BSDi", HttpUserAgentPlatformType.Unix)), ("unix", new(HttpUserAgentPlatformRegexId.Unix, "Unknown Unix OS", HttpUserAgentPlatformType.Unix)), ("ppc", new(HttpUserAgentPlatformRegexId.Ppc, "Macintosh", HttpUserAgentPlatformType.MacOS)), + ("macintosh", new(HttpUserAgentPlatformRegexId.Macintosh, "Macintosh", HttpUserAgentPlatformType.MacOS)), ]; /// @@ -97,6 +98,14 @@ internal static class HttpUserAgentRules ("Yandex Browser", "YaBrowser", null), ("UC Browser", "UCBrowser", null), ("UC Browser", "UCMobile", null), + ("DuckDuckGo", "DuckDuckGo", null), + ("Whale", "Whale", null), + ("QQ Browser", "QQBrowser", null), + ("Huawei Browser", "HuaweiBrowser", null), + ("Miui Browser", "XiaoMi/MiuiBrowser", null), + ("Miui Browser", "MiuiBrowser", null), + ("Instagram", "Instagram", "Instagram"), + ("Facebook", "FBAV", null), ("Maxthon", "Maxthon", null), // Common browsers ("Chrome", "Chrome", null), diff --git a/src/HttpUserAgentParser/HttpUserAgentStatics.cs b/src/HttpUserAgentParser/HttpUserAgentStatics.cs index be0e469..8bd4fd6 100644 --- a/src/HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/HttpUserAgentParser/HttpUserAgentStatics.cs @@ -45,6 +45,14 @@ public static class HttpUserAgentStatics { HttpUserAgentRegexes.BrowserYaBrowser(), "Yandex Browser" }, { HttpUserAgentRegexes.BrowserUCBrowser(), "UC Browser" }, { HttpUserAgentRegexes.BrowserUCMobile(), "UC Browser" }, + { HttpUserAgentRegexes.BrowserDuckDuckGo(), "DuckDuckGo" }, + { HttpUserAgentRegexes.BrowserWhale(), "Whale" }, + { HttpUserAgentRegexes.BrowserQQBrowser(), "QQ Browser" }, + { HttpUserAgentRegexes.BrowserHuaweiBrowser(), "Huawei Browser" }, + { HttpUserAgentRegexes.BrowserXiaoMiMiuiBrowser(), "Miui Browser" }, + { HttpUserAgentRegexes.BrowserMiuiBrowser(), "Miui Browser" }, + { HttpUserAgentRegexes.BrowserInstagram(), "Instagram" }, + { HttpUserAgentRegexes.BrowserFbav(), "Facebook" }, { HttpUserAgentRegexes.BrowserChrome(), "Chrome" }, { HttpUserAgentRegexes.BrowserCriOS(), "Chrome" }, { HttpUserAgentRegexes.BrowserHeadlessChrome(), "Chrome" }, diff --git a/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs b/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs index 129a86d..2e9a9c0 100644 --- a/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs +++ b/tests/HttpUserAgentParser.TestHelpers/UserAgentCatalog.cs @@ -134,8 +134,8 @@ public static class UserAgentCatalog new("UC Browser 11 Android", "Mozilla/5.0 (Linux; U; Android 6.0.1; zh-CN; F5121 Build/34.0.A.1.247) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.5.1.944 Mobile Safari/537.36", "UC Browser", "11.5.1.944", "Android", Android, "Android"), // DuckDuckGo browser (WebKit on iOS, WebView on Android) - new("DuckDuckGo iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 DuckDuckGo/7 Safari/605.1.15", "Safari", "26.0", "iOS", IOS, "Apple iPhone"), - new("DuckDuckGo Android", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/151.0.7922.199 Mobile DuckDuckGo/5 Safari/537.36", "Chrome", "151.0.7922.199", "Android", Android, "Android"), + new("DuckDuckGo iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 DuckDuckGo/7 Safari/605.1.15", "DuckDuckGo", "7", "iOS", IOS, "Apple iPhone"), + new("DuckDuckGo Android", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/151.0.7922.199 Mobile DuckDuckGo/5 Safari/537.36", "DuckDuckGo", "5", "Android", Android, "Android"), ]; /// diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs index f7fb155..01f5375 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs @@ -20,6 +20,7 @@ public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobi Assert.Equal(expectedType == HttpUserAgentType.Unknown, info.IsType(HttpUserAgentType.Unknown)); Assert.Equal(expectedType == HttpUserAgentType.Browser, info.IsBrowser()); Assert.Equal(expectedType == HttpUserAgentType.Robot, info.IsRobot()); + Assert.Equal(expectedType == HttpUserAgentType.Unknown, info.IsUnknown()); Assert.Equal(isMobile, info.IsMobile()); } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs index 3f2907a..8211792 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs @@ -115,6 +115,14 @@ public void Not_Equals_Other_Types() Assert.False(info.Equals("ua")); } + [Fact] + public void ToString_Formats_Type_Name_And_Version() + { + Assert.Equal("Browser: Chrome 131.0", HttpUserAgentInformation.CreateForBrowser("ua", platform: null, "Chrome", "131.0", deviceName: null).ToString()); + Assert.Equal("Robot: Googlebot", HttpUserAgentInformation.CreateForRobot("ua", "Googlebot").ToString()); + Assert.Equal("Unknown", HttpUserAgentInformation.CreateForUnknown("ua", platform: null, deviceName: null).ToString()); + } + [GeneratedRegex("", RegexOptions.None, matchTimeoutMilliseconds: 1000)] private static partial Regex TextRegex(); } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index 74cf5bb..f2e0d60 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -511,4 +511,24 @@ public void Span_Overloads_Match_String_Overloads_Including_Zero_Alloc_Browser_V Assert.False(HttpUserAgentParser.TryGetRobot(unknown, out _)); Assert.False(HttpUserAgentParser.TryGetMobileDevice(unknown, out _)); } + + [Theory] + [InlineData("Mozilla/5.0 (Macintosh; U; Intel) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", "Chrome", "131.0.0.0", "Macintosh", HttpUserAgentPlatformType.MacOS)] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Whale/3.24.223.21 Safari/537.36", "Whale", "3.24.223.21", "Windows 10", HttpUserAgentPlatformType.Windows)] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 QQBrowser/13.1", "QQ Browser", "13.1", "Windows 10", HttpUserAgentPlatformType.Windows)] + [InlineData("Mozilla/5.0 (Linux; Android 12; HUAWEI) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88 HuaweiBrowser/14.0.1.302 Mobile Safari/537.36", "Huawei Browser", "14.0.1.302", "Android", HttpUserAgentPlatformType.Android)] + [InlineData("Mozilla/5.0 (Linux; U; Android 13; 2210132G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/112.0.0.0 Mobile Safari/537.36 XiaoMi/MiuiBrowser/17.3.12", "Miui Browser", "17.3.12", "Android", HttpUserAgentPlatformType.Android)] + [InlineData("Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 MiuiBrowser/17.3.12 Mobile Safari/537.36", "Miui Browser", "17.3.12", "Android", HttpUserAgentPlatformType.Android)] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21A329 Instagram 302.0.0.23.108", "Instagram", "302.0.0.23.108", "iOS", HttpUserAgentPlatformType.IOS)] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21A329 [FBAN/FBIOS;FBAV/436.0.0.42.111;FBBV/526455120]", "Facebook", "436.0.0.42.111", "iOS", HttpUserAgentPlatformType.IOS)] + public void Parse_Recognizes_Modern_Browsers_WebViews_And_Macintosh(string ua, string expectedName, string expectedVersion, string expectedPlatform, HttpUserAgentPlatformType expectedPlatformType) + { + HttpUserAgentInformation info = HttpUserAgentParser.Parse(ua); + + Assert.Equal(HttpUserAgentType.Browser, info.Type); + Assert.Equal(expectedName, info.Name); + Assert.Equal(expectedVersion, info.Version); + Assert.Equal(expectedPlatform, info.Platform?.Name); + Assert.Equal(expectedPlatformType, info.Platform?.PlatformType); + } } diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs index d7bc04d..7cc9786 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs @@ -76,6 +76,15 @@ public void Parse_Results_Are_Equal_To_Published_Platforms() Assert.Contains(platform, HttpUserAgentStatics.Platforms); } + [Fact] + public void ToString_Formats_Name_And_PlatformType() + { + HttpUserAgentPlatformInformation platform = new(HttpUserAgentPlatformRegexId.Android, "Android", HttpUserAgentPlatformType.Android); + + Assert.Equal("Android (Android)", platform.ToString()); + Assert.Equal("Unknown", default(HttpUserAgentPlatformInformation).ToString()); + } + [GeneratedRegex("", RegexOptions.None, matchTimeoutMilliseconds: 1000)] private static partial Regex EmptyRegex(); diff --git a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs index 2dbdfa6..cd57515 100644 --- a/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs +++ b/tests/HttpUserAgentParser.UnitTests/HttpUserAgentStaticsTests.cs @@ -61,6 +61,7 @@ private static readonly (string Token, string Name, HttpUserAgentPlatformType Ty ("gnu", "GNU/Linux", HttpUserAgentPlatformType.Linux), ("unix", "Unknown Unix OS", HttpUserAgentPlatformType.Unix), ("symbian", "Symbian OS", HttpUserAgentPlatformType.Symbian), + ("macintosh", "Macintosh", HttpUserAgentPlatformType.MacOS), ]; /// @@ -70,7 +71,9 @@ private static readonly (string Token, string Name)[] s_expectedBrowsers = [ ("OPR", "Opera"), ("Silk", "Amazon Silk"), ("Flock", "Flock"), ("Edge", "Edge"), ("EdgA", "Edge"), ("Edg", "Edge"), ("EdgiOS", "Edge"), ("Vivaldi", "Vivaldi"), ("Brave Chrome", "Brave"), ("SamsungBrowser", "Samsung Internet"), ("YaBrowser", "Yandex Browser"), - ("UCBrowser", "UC Browser"), ("UCMobile", "UC Browser"), ("Chrome", "Chrome"), ("CriOS", "Chrome"), ("HeadlessChrome", "Chrome"), + ("UCBrowser", "UC Browser"), ("UCMobile", "UC Browser"), ("DuckDuckGo", "DuckDuckGo"), ("Whale", "Whale"), ("QQBrowser", "QQ Browser"), + ("HuaweiBrowser", "Huawei Browser"), ("XiaoMi/MiuiBrowser", "Miui Browser"), ("MiuiBrowser", "Miui Browser"), + ("Instagram", "Instagram"), ("FBAV", "Facebook"), ("Chrome", "Chrome"), ("CriOS", "Chrome"), ("HeadlessChrome", "Chrome"), ("Opera.*?Version", "Opera"), ("Opera", "Opera"), ("MSIE", "Internet Explorer"), ("Internet Explorer", "Internet Explorer"), ("Trident.* rv", "Internet Explorer"), ("Shiira", "Shiira"), ("Firefox", "Firefox"), ("FxiOS", "Firefox"), ("Chimera", "Chimera"), ("Phoenix", "Phoenix"), ("Firebird", "Firebird"), ("Camino", "Camino"), ("Netscape", "Netscape"), ("OmniWeb", "OmniWeb"), From 092f4feda3a6cc8994a948514b1db8eb917c25fa Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:27:13 +0100 Subject: [PATCH 36/41] docs: update README and add 2026-11-26 benchmark results Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/benchmarks/2026-11-26.md | 45 +++++++++++++++++++++++++++++++++++ readme.md | 39 +++++++++++++++++++----------- 2 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 docs/benchmarks/2026-11-26.md diff --git a/docs/benchmarks/2026-11-26.md b/docs/benchmarks/2026-11-26.md new file mode 100644 index 0000000..cf720fa --- /dev/null +++ b/docs/benchmarks/2026-11-26.md @@ -0,0 +1,45 @@ +# Parser benchmarks on November 26, 2026 + +Release builds ran on Windows 10 x64 with an AMD Ryzen 9 9950X, .NET SDK 11.0.100 and BenchmarkDotNet 0.16.0-preview.2. Each case ran with three warm-up iterations and five measurement iterations targeting 250 ms. Percentages compare mean time per uncached header within the same run. Negative values indicate less time. [Reproduction command](../../readme.md#run-the-benchmarks) + +## Compared with main (`be56445`) on .NET 11 + +Each mixed workload repeats its inputs in catalog order, with equal weight per header. + +| Workload | Main | Current parser | Time change | Allocated per parse | +| --- | ---: | ---: | ---: | ---: | +| Catalog browsers (44) | 314.93 ns | 233.07 ns | −26.0% | 37 B | +| Catalog crawlers (48) | 366.10 ns | 83.96 ns | −77.1% | 0 B | +| Full catalog (96) | 372.54 ns | 143.52 ns | −61.5% | 17 B | +| API snapshot (60) | 424.54 ns | 198.03 ns | −53.4% | 29 B | +| Googlebot | 15.16 ns | 12.64 ns | −16.6% | 0 B | +| OAI-AdsBot | 812.68 ns | 132.55 ns | −83.7% | 0 B | + +## Standalone detectors on .NET 11 (`DetectorWorkloadBenchmarks`, full catalog) + +| Method | Main (`be56445`) | Current parser | Time change | Allocated per call | +| --- | ---: | ---: | ---: | ---: | +| `GetPlatform` | 106.55 ns | 78.06 ns | −26.7% | 0 B | +| `GetMobileDevice` | 151.35 ns | 118.87 ns | −21.5% | 0 B | +| `GetBrowser` | — | 89.06 ns | — | 18 B | +| `TryGetBrowser` (`ReadOnlySpan`) | — | 121.78 ns | — | 0 B | + +## Standalone detectors on .NET 8 & .NET 10 (vs. 64-bit index baseline) + +Measured with BenchmarkDotNet ShortRun (three warm-up and three measurement iterations): + +| Method | Runtime | Previous (64-bit / linear) | Current (128-bit / indexed) | Time change | Allocated | +| --- | --- | ---: | ---: | ---: | ---: | +| `GetPlatform` | .NET 10.0.15 | 134.97 ns | 76.11 ns | −43.6% | 0 B | +| `GetPlatform` | .NET 8.0.34 | 166.69 ns | 79.46 ns | −52.3% | 0 B | +| `GetMobileDevice` | .NET 10.0.15 | 115.34 ns | 106.70 ns | −7.5% | 0 B | +| `GetMobileDevice` | .NET 8.0.34 | 393.66 ns | 133.54 ns | −66.1% | 0 B | +| `TryGetBrowser` (`ReadOnlySpan`) vs. `GetBrowser` | .NET 10.0.15 | 92.98 ns (18 B) | 89.30 ns (0 B) | −100% alloc | 0 B | + +## Reproduction + +Build `origin/main` in Release for `net11.0` with `-p:AssemblyName=MyCSharp.HttpUserAgentParser.Baseline` and set the `BenchmarkBaselineAssembly` environment variable to the absolute path of that DLL. Then run: + +```shell +dotnet run --project perf/HttpUserAgentParser.Benchmarks -c Release -f net11.0 -- --filter "*MixedWorkloadBenchmarks.Parse*" "*HttpUserAgentParserBenchmarks.Parse*Googlebot*" "*HttpUserAgentParserBenchmarks.Parse*OAI-AdsBot*" "*DetectorWorkloadBenchmarks*" --job short --warmupCount 3 --iterationCount 5 --iterationTime 250 --launchCount 1 +``` diff --git a/readme.md b/readme.md index e3c788f..f251f58 100644 --- a/readme.md +++ b/readme.md @@ -55,6 +55,15 @@ Version = "90.0.4430.212" MobileDeviceType = null ``` +`ReadOnlySpan` overloads are also available for `GetPlatform`, `TryGetPlatform`, `GetBrowser`, `TryGetBrowser`, `GetRobot`, `TryGetRobot`, `GetMobileDevice`, and `TryGetMobileDevice` — including a zero-allocation browser lookup that slices the version directly from the input span: + +```csharp +if (HttpUserAgentParser.TryGetBrowser(userAgent.AsSpan(), out string? name, out ReadOnlySpan version)) +{ + // zero allocations +} +``` + ### Dependency Injection and Caching For dependency injection mechanisms, the `IHttpUserAgentParserProvider` interface exists, for which built-in or custom caching mechanisms can be used. The use is always: @@ -81,13 +90,15 @@ Likewise, an in-process cache based on a `ConcurrentDictionary` is provided. ```csharp public void ConfigureServices(IServiceCollection services) { - services.AddHttpUserAgentCachedParser(); // uses `HttpUserAgentParserCachedProvider` + services.AddHttpUserAgentCachedParser(); // uses HttpUserAgentParserCachedProvider (default limit: 10,000 entries) + // or with a custom entry limit: + // services.AddHttpUserAgentCachedParser(maxCacheEntries: 4096); // or // services.AddHttpUserAgentParser(); } ``` -This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. Both caches use the exact user agent string as key (ordinal), because the result contains the user agent. Clients choose the `User-Agent` header freely, so use it only for a known, limited set of user agents, e.g. in tests. For web applications, use the `IMemoryCache` implementation, which limits the number of entries and expires them. +`HttpUserAgentParserCachedProvider` bounds memory usage by rotating the cache atomically once `MaxCacheEntries` (default: `HttpUserAgentParserCachedProvider.DefaultMaxCacheEntries` = `10_000`) is reached; it does not support sliding/absolute expiration. Both caches use the exact user agent string as key (ordinal), because the result contains the user agent. For web applications that need sliding/absolute expiration or fine-grained eviction policies, use the `IMemoryCache` implementation. All DI registration extensions are idempotent (`TryAddSingleton`). The package [MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache) is required to use the IMemoryCache. This enables the registration of the `IMemoryCache` implementation: @@ -152,16 +163,16 @@ public void MyMethod(IHttpUserAgentParserContextAccessor parserAccessor) } ``` -If you only need the raw header value, use `httpContext.GetUserAgentString()`. +If you only need the raw header value, use `httpContext.GetUserAgentString()`. `HttpUserAgentParserAccessor.Get(httpContext)` caches the parsed result per request in `HttpContext.Items`, so repeated calls within the same request neither re-parse nor emit duplicate telemetry events. ## Detection rules `HttpUserAgentParser.Parse` checks, in this order: 1. **Robots**: search engine crawlers (e.g. Googlebot, Bingbot, Applebot, Bravebot, DuckDuckBot, YandexBot), SEO crawlers (e.g. AhrefsBot, SemrushBot, Screaming Frog) and AI crawlers and AI user agents (e.g. GPTBot, ChatGPT-User, OAI-SearchBot, OAI-AdsBot, ClaudeBot, PerplexityBot, KimiBot, DeepSeekBot, ChatGLM-Spider, Amazonbot, Bytespider, CCBot) -2. **Platform**: Windows, macOS, iOS, Android, ChromeOS, Linux and others +2. **Platform**: Windows, macOS (`Mac OS X` / `Macintosh`), iOS, Android, ChromeOS, Linux and others 3. **Mobile device**: devices and manufacturers before operating systems before mobile browsers before generic tokens (e.g. a Samsung phone reports `Samsung`, an Android phone without manufacturer token `Android`) -4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Amazon Silk, Yandex Browser, UC Browser and others +4. **Browser and version**: Chrome, Edge, Firefox, Safari, Opera, Samsung Internet, Amazon Silk, Yandex Browser, UC Browser, DuckDuckGo, Whale, QQ Browser, Huawei Browser, Miui Browser, Instagram, Facebook (`FBAV`) and others In every list the first matching entry wins. Browser and version tokens only count at the start of a token: at the beginning of the user agent or after a space, tab, `+`, `;`, `(`, `)` or `,`, so `Knowledge/1.0` is no Edge and `VendorVersion/1.0` no version token. The version is read from the browser's own product token (`Chrome/131.0.0.0`), which ends at the next of these characters; Opera and Internet Explorer also accept `Opera 9.50` and `MSIE 6.0`; their separate version tokens (`Version/`, `rv:`) only count after the browser token. If a token has no version, later occurrences of the token are checked, then the next rule. `+` stands for a space as in URL-encoded logs (IIS); decode other encodings such as `%20` before parsing, e.g. with `WebUtility.UrlDecode`. @@ -468,18 +479,18 @@ Notes: ### Parser performance on .NET 11 -Mean time per uncached header on Windows 10 x64, AMD Ryzen 9 9950X, .NET 11.0.0. Each mixed workload processes 5,280 headers per invocation, with equal weight per distinct header. The API snapshot contains 60 captured user agents. [Test inputs and measurements](docs/benchmarks/2026-11-24.md) +Mean time per uncached header on Windows 10 x64, AMD Ryzen 9 9950X, .NET 11.0.0. Each mixed workload processes 5,280 headers per invocation, with equal weight per distinct header. The API snapshot contains 60 captured user agents. [Test inputs and measurements](docs/benchmarks/2026-11-26.md) | Workload | v3.1.9 | Current parser | Time change | Allocated per current parse | | --- | ---: | ---: | ---: | ---: | -| Catalog browsers (44) | 318.05 ns | 234.69 ns | −26.2% | 38 B | -| Catalog crawlers (48) | 378.70 ns | 82.12 ns | −78.3% | 0 B | -| Full catalog (96) | 373.01 ns | 157.98 ns | −57.6% | 18 B | -| API snapshot (60) | 398.19 ns | 202.41 ns | −49.2% | 29 B | -| Googlebot | 8.537 ns | 6.915 ns | −19.0% | 0 B | -| OAI-AdsBot | 842.291 ns | 139.364 ns | −83.5% | 0 B | - -Full-catalog means on the other supported runtimes were 191.49 ns (.NET 8), 196.83 ns (.NET 9) and 166.70 ns (.NET 10). The first Chrome parse on .NET 11 took 13.43 ms and allocated 193,792 B on the calling thread (medians across nine fresh processes). +| Catalog browsers (44) | 314.93 ns | 233.07 ns | −26.0% | 37 B | +| Catalog crawlers (48) | 366.10 ns | 83.96 ns | −77.1% | 0 B | +| Full catalog (96) | 372.54 ns | 143.52 ns | −61.5% | 17 B | +| API snapshot (60) | 424.54 ns | 198.03 ns | −53.4% | 29 B | +| Googlebot | 15.16 ns | 12.64 ns | −16.6% | 0 B | +| OAI-AdsBot | 812.68 ns | 132.55 ns | −83.7% | 0 B | + +Standalone detectors on .NET 11 (`DetectorWorkloadBenchmarks`, full catalog): `GetPlatform` improved from 106.55 ns to **78.06 ns** (−26.7%, 0 B), `GetMobileDevice` from 151.35 ns to **118.87 ns** (−21.5%, 0 B), and the `ReadOnlySpan` `TryGetBrowser` overload allocates **0 B** (vs. 18 B for `GetBrowser`). On .NET 8, `GetPlatform` improved by **−52.3%** and `GetMobileDevice` by **−66.1%**. ### Library comparison on .NET 11 From f44e87792424c4ed7c51bf49f84369998df15a64 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:33:02 +0100 Subject: [PATCH 37/41] docs: update library comparison SVGs, root README, and package READMEs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../library-comparison-net11-dark.svg | 38 +++++++++---------- docs/benchmarks/library-comparison-net11.svg | 38 +++++++++---------- readme.md | 10 ++--- src/HttpUserAgentParser.AspNetCore/readme.md | 2 +- src/HttpUserAgentParser/readme.md | 15 ++++---- 5 files changed, 52 insertions(+), 51 deletions(-) diff --git a/docs/benchmarks/library-comparison-net11-dark.svg b/docs/benchmarks/library-comparison-net11-dark.svg index 8a58d28..7abc20e 100644 --- a/docs/benchmarks/library-comparison-net11-dark.svg +++ b/docs/benchmarks/library-comparison-net11-dark.svg @@ -1,6 +1,6 @@ Library comparison on .NET 11 -Linear column charts of mean time per call. Single parse with setup: MyCSharp 241 ns and 106 ns, UAParser 9.77 ms and 9.32 ms, DeviceDetector.NET 5.83 ms and 7.38 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 17.8 ns and 12.7 ns, UAParser reused compiled parser 125 µs and 110 µs. +Linear column charts of mean time per call. Single parse with setup: MyCSharp 258 ns and 101 ns, UAParser 10.0 ms and 9.32 ms, DeviceDetector.NET 6.20 ms and 7.76 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 19.2 ns and 13.0 ns, UAParser reused compiled parser 124 µs and 107 µs. Mean time per call on .NET 11 Linear scale, lower is better. Each panel has its own axis. @@ -21,27 +21,27 @@ 10 ms -241 ns +258 ns -106 ns +101 ns MyCSharp Parse Bars too short to draw at this scale: -24,000× to 88,000× +24,000× to 92,000× faster - -9.77 ms - -9.32 ms + +10.0 ms + +9.32 ms UAParser GetDefault + Parse - -5.83 ms - -7.38 ms + +6.20 ms + +7.76 ms DeviceDetector.NET New detector + Parse @@ -60,21 +60,21 @@ 150 µs -17.8 ns +19.2 ns -12.7 ns +13.0 ns MyCSharp Result cache hit Bars too short to draw at this scale: -7,000× to 8,700× +6,400× to 8,200× faster - -125 µs - -110 µs + +124 µs + +107 µs UAParser Reused compiled parser diff --git a/docs/benchmarks/library-comparison-net11.svg b/docs/benchmarks/library-comparison-net11.svg index 7f94426..4ea2682 100644 --- a/docs/benchmarks/library-comparison-net11.svg +++ b/docs/benchmarks/library-comparison-net11.svg @@ -1,6 +1,6 @@ Library comparison on .NET 11 -Linear column charts of mean time per call. Single parse with setup: MyCSharp 241 ns and 106 ns, UAParser 9.77 ms and 9.32 ms, DeviceDetector.NET 5.83 ms and 7.38 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 17.8 ns and 12.7 ns, UAParser reused compiled parser 125 µs and 110 µs. +Linear column charts of mean time per call. Single parse with setup: MyCSharp 258 ns and 101 ns, UAParser 10.0 ms and 9.32 ms, DeviceDetector.NET 6.20 ms and 7.76 ms, for Chrome on Windows and APIs-Google. Repeated parse with reused state: MyCSharp result cache hit 19.2 ns and 13.0 ns, UAParser reused compiled parser 124 µs and 107 µs. Mean time per call on .NET 11 Linear scale, lower is better. Each panel has its own axis. @@ -21,27 +21,27 @@ 10 ms -241 ns +258 ns -106 ns +101 ns MyCSharp Parse Bars too short to draw at this scale: -24,000× to 88,000× +24,000× to 92,000× faster - -9.77 ms - -9.32 ms + +10.0 ms + +9.32 ms UAParser GetDefault + Parse - -5.83 ms - -7.38 ms + +6.20 ms + +7.76 ms DeviceDetector.NET New detector + Parse @@ -60,21 +60,21 @@ 150 µs -17.8 ns +19.2 ns -12.7 ns +13.0 ns MyCSharp Result cache hit Bars too short to draw at this scale: -7,000× to 8,700× +6,400× to 8,200× faster - -125 µs - -110 µs + +124 µs + +107 µs UAParser Reused compiled parser diff --git a/readme.md b/readme.md index f251f58..d14c3ba 100644 --- a/readme.md +++ b/readme.md @@ -503,11 +503,11 @@ BenchmarkDotNet ShortRun, three warm-ups and three measured iterations. UAParser | Library | Measured operation | Chrome on Windows | Allocated | APIs-Google | Allocated | | --- | --- | ---: | ---: | ---: | ---: | -| MyCSharp | Parse | 241.39 ns | 48 B | 106.15 ns | 0 B | -| UAParser | GetDefault + Parse | 9,769,158.85 ns | 11,653,583 B | 9,323,358.33 ns | 12,010,118 B | -| DeviceDetector.NET | New detector + Parse | 5,826,561.20 ns | 5,529,304 B | 7,377,367.19 ns | 10,123,039 B | -| MyCSharp | Result cache hit | 17.84 ns | 0 B | 12.69 ns | 0 B | -| UAParser | Reused compiled parser | 125,258.05 ns | 37,400 B | 110,313.30 ns | 45,832 B | +| MyCSharp | Parse | 257.80 ns | 48 B | 101.34 ns | 0 B | +| UAParser | GetDefault + Parse | 10,004,667.19 ns | 11,653,583 B | 9,319,852.60 ns | 12,010,118 B | +| DeviceDetector.NET | New detector + Parse | 6,198,998.44 ns | 5,529,304 B | 7,764,429.43 ns | 10,123,039 B | +| MyCSharp | Result cache hit | 19.24 ns | 0 B | 13.03 ns | 0 B | +| UAParser | Reused compiled parser | 124,078.83 ns | 37,400 B | 106,577.78 ns | 45,832 B | ### Run the benchmarks diff --git a/src/HttpUserAgentParser.AspNetCore/readme.md b/src/HttpUserAgentParser.AspNetCore/readme.md index ff35298..c7e7a09 100644 --- a/src/HttpUserAgentParser.AspNetCore/readme.md +++ b/src/HttpUserAgentParser.AspNetCore/readme.md @@ -15,7 +15,7 @@ dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore Register a provider (any of the available ones) and then add the accessor: -The accessor reads the `User-Agent` header of a request and parses it using the registered provider. There are two options: +The accessor reads the `User-Agent` header of a request, parses it using the registered provider, and caches the result per request in `HttpContext.Items` (so repeated calls within the same request neither re-parse nor emit duplicate telemetry events). There are two options: - `AddHttpUserAgentParserAccessor()` registers `IHttpUserAgentParserAccessor`: you pass the `HttpContext` (`Get(httpContext)`). Recommended. - `AddHttpUserAgentParserContextAccessor()` registers `IHttpUserAgentParserContextAccessor` and `IHttpContextAccessor`: `Get()` uses the current request, `Get(httpContext)` works as well. Useful in services without access to the `HttpContext`; `IHttpContextAccessor` has a small cost on every request. diff --git a/src/HttpUserAgentParser/readme.md b/src/HttpUserAgentParser/readme.md index dcfc239..c325338 100644 --- a/src/HttpUserAgentParser/readme.md +++ b/src/HttpUserAgentParser/readme.md @@ -2,10 +2,9 @@ Fast HTTP User-Agent parsing for .NET. -- Allocation-free detection with vectorized searches (`SearchValues` on .NET 9+); for a user agent without surrounding - white space only the version string is allocated; no regular expressions in the parser +- Allocation-free detection with vectorized searches (`SearchValues` on .NET 9+) and a 128-bit shared rule index; `ReadOnlySpan` overloads including zero-allocation `TryGetBrowser(ReadOnlySpan, out string?, out ReadOnlySpan)`; no regular expressions in the parser - Trimming and Native AOT compatible -- Detects browsers including Amazon Silk, and search, SEO and AI crawlers including Bravebot, Screaming Frog SEO Spider, KimiBot, DeepSeekBot, ChatGLM-Spider and OAI-AdsBot +- Detects browsers and in-app WebViews including Amazon Silk, DuckDuckGo, Whale, QQ Browser, Huawei Browser, Miui Browser, Instagram and Facebook (`FBAV`), and search, SEO and AI crawlers including Bravebot, Screaming Frog SEO Spider, KimiBot, DeepSeekBot, ChatGLM-Spider and OAI-AdsBot Repository: https://github.com/mycsharp/HttpUserAgentParser @@ -51,14 +50,16 @@ services ```csharp services - .AddHttpUserAgentCachedParser(); + .AddHttpUserAgentCachedParser(); // default limit: 10,000 entries +// or: .AddHttpUserAgentCachedParser(maxCacheEntries: 4096); // or: .AddHttpUserAgentParser(); ``` -This cache has no size limit and no expiration: every distinct user agent string stays in memory as long as the provider lives. -The key is the exact user agent string (ordinal). -Use it only for a known, limited set of user agents (e.g. in tests); for web applications use +`HttpUserAgentParserCachedProvider` bounds memory usage by rotating the cache atomically once `MaxCacheEntries` +(default: `HttpUserAgentParserCachedProvider.DefaultMaxCacheEntries` = `10_000`) is reached; it has no sliding/absolute expiration. +The key is the exact user agent string (ordinal). For web applications that need expiration or fine-grained eviction policies, use [MyCSharp.HttpUserAgentParser.MemoryCache](https://www.nuget.org/packages/MyCSharp.HttpUserAgentParser.MemoryCache). +All DI registration extensions are idempotent (`TryAddSingleton`). ## Telemetry (EventCounters) From 4aa93c982e02dd13bf3e43c152bf9aa7d625b0fc Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 14:35:04 +0100 Subject: [PATCH 38/41] docs: scale left Y-axis to 12 ms in library comparison SVGs to avoid label overlap Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../library-comparison-net11-dark.svg | 36 ++++++++++--------- docs/benchmarks/library-comparison-net11.svg | 36 ++++++++++--------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/docs/benchmarks/library-comparison-net11-dark.svg b/docs/benchmarks/library-comparison-net11-dark.svg index 7abc20e..3accdbf 100644 --- a/docs/benchmarks/library-comparison-net11-dark.svg +++ b/docs/benchmarks/library-comparison-net11-dark.svg @@ -10,16 +10,18 @@ APIs-Google Single parse, including each library's setup 0 - -2 ms - -4 ms - -6 ms - -8 ms + +2 ms + +4 ms + +6 ms + +8 ms + +10 ms -10 ms +12 ms 258 ns @@ -32,16 +34,16 @@ 24,000× to 92,000× faster - -10.0 ms - -9.32 ms + +10.0 ms + +9.32 ms UAParser GetDefault + Parse - -6.20 ms - -7.76 ms + +6.20 ms + +7.76 ms DeviceDetector.NET New detector + Parse diff --git a/docs/benchmarks/library-comparison-net11.svg b/docs/benchmarks/library-comparison-net11.svg index 4ea2682..37c2324 100644 --- a/docs/benchmarks/library-comparison-net11.svg +++ b/docs/benchmarks/library-comparison-net11.svg @@ -10,16 +10,18 @@ APIs-Google Single parse, including each library's setup 0 - -2 ms - -4 ms - -6 ms - -8 ms + +2 ms + +4 ms + +6 ms + +8 ms + +10 ms -10 ms +12 ms 258 ns @@ -32,16 +34,16 @@ 24,000× to 92,000× faster - -10.0 ms - -9.32 ms + +10.0 ms + +9.32 ms UAParser GetDefault + Parse - -6.20 ms - -7.76 ms + +6.20 ms + +7.76 ms DeviceDetector.NET New detector + Parse From fbf63f5a1072a3cf5134d00bad1a1b4085af1d10 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 16:51:12 +0100 Subject: [PATCH 39/41] chore(sln): remove unused Visual Studio solution file --- MyCSharp.HttpUserAgentParser.sln | 105 ------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 MyCSharp.HttpUserAgentParser.sln diff --git a/MyCSharp.HttpUserAgentParser.sln b/MyCSharp.HttpUserAgentParser.sln deleted file mode 100644 index 32a8aa1..0000000 --- a/MyCSharp.HttpUserAgentParser.sln +++ /dev/null @@ -1,105 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.32804.182 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{008A2BAB-78B4-42EB-A5D4-DE434438CEF0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.AspNetCore", "src\HttpUserAgentParser.AspNetCore\HttpUserAgentParser.AspNetCore.csproj", "{45927CF7-1BF4-479B-BBAA-8AD9CA901AE4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser", "src\HttpUserAgentParser\HttpUserAgentParser.csproj", "{3357BEC0-8216-409E-A539-F9A71DBACB81}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.UnitTests", "tests\HttpUserAgentParser.UnitTests\HttpUserAgentParser.UnitTests.csproj", "{F16697F7-74B4-441D-A0C0-1A0572AC3AB0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.AspNetCore.UnitTests", "tests\HttpUserAgentParser.AspNetCore.UnitTests\HttpUserAgentParser.AspNetCore.UnitTests.csproj", "{75960783-8BF9-479C-9ECF-E9653B74C9A2}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F54C9296-4EF7-40F0-9F20-F23A2270ABC9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.MemoryCache", "src\HttpUserAgentParser.MemoryCache\HttpUserAgentParser.MemoryCache.csproj", "{3C8CCD44-F47C-4624-8997-54C42F02E376}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.MemoryCache.UnitTests", "tests\HttpUserAgentParser.MemoryCache.UnitTests\HttpUserAgentParser.MemoryCache.UnitTests.csproj", "{39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{5738CE0D-5E6E-47CB-BFF5-08F45A2C33AD}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - .gitignore = .gitignore - .github\workflows\ci.yml = .github\workflows\ci.yml - Directory.Build.props = Directory.Build.props - Directory.Packages.props = Directory.Packages.props - global.json = global.json - Justfile = Justfile - LICENSE = LICENSE - NuGet.config = NuGet.config - readme.md = readme.md - version.json = version.json - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{FAAD18A0-E1B8-448D-B611-AFBDA8A89808}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.Benchmarks", "perf\HttpUserAgentParser.Benchmarks\HttpUserAgentParser.Benchmarks.csproj", "{A0D213E9-6408-46D1-AFAF-5096C2F6E027}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.TestHelpers", "tests\HttpUserAgentParser.TestHelpers\HttpUserAgentParser.TestHelpers.csproj", "{165EE915-1A4F-4875-90CE-1A2AE1540AE7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpUserAgentParser.NativeAot.Smoke", "tests\HttpUserAgentParser.NativeAot.Smoke\HttpUserAgentParser.NativeAot.Smoke.csproj", "{4E55304E-6429-429E-BBB6-7C096C38C96E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {45927CF7-1BF4-479B-BBAA-8AD9CA901AE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {45927CF7-1BF4-479B-BBAA-8AD9CA901AE4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {45927CF7-1BF4-479B-BBAA-8AD9CA901AE4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {45927CF7-1BF4-479B-BBAA-8AD9CA901AE4}.Release|Any CPU.Build.0 = Release|Any CPU - {3357BEC0-8216-409E-A539-F9A71DBACB81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3357BEC0-8216-409E-A539-F9A71DBACB81}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3357BEC0-8216-409E-A539-F9A71DBACB81}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3357BEC0-8216-409E-A539-F9A71DBACB81}.Release|Any CPU.Build.0 = Release|Any CPU - {F16697F7-74B4-441D-A0C0-1A0572AC3AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F16697F7-74B4-441D-A0C0-1A0572AC3AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F16697F7-74B4-441D-A0C0-1A0572AC3AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F16697F7-74B4-441D-A0C0-1A0572AC3AB0}.Release|Any CPU.Build.0 = Release|Any CPU - {75960783-8BF9-479C-9ECF-E9653B74C9A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {75960783-8BF9-479C-9ECF-E9653B74C9A2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {75960783-8BF9-479C-9ECF-E9653B74C9A2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {75960783-8BF9-479C-9ECF-E9653B74C9A2}.Release|Any CPU.Build.0 = Release|Any CPU - {3C8CCD44-F47C-4624-8997-54C42F02E376}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3C8CCD44-F47C-4624-8997-54C42F02E376}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3C8CCD44-F47C-4624-8997-54C42F02E376}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3C8CCD44-F47C-4624-8997-54C42F02E376}.Release|Any CPU.Build.0 = Release|Any CPU - {39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E}.Release|Any CPU.Build.0 = Release|Any CPU - {A0D213E9-6408-46D1-AFAF-5096C2F6E027}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A0D213E9-6408-46D1-AFAF-5096C2F6E027}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A0D213E9-6408-46D1-AFAF-5096C2F6E027}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A0D213E9-6408-46D1-AFAF-5096C2F6E027}.Release|Any CPU.Build.0 = Release|Any CPU - {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {165EE915-1A4F-4875-90CE-1A2AE1540AE7}.Release|Any CPU.Build.0 = Release|Any CPU - {4E55304E-6429-429E-BBB6-7C096C38C96E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4E55304E-6429-429E-BBB6-7C096C38C96E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4E55304E-6429-429E-BBB6-7C096C38C96E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4E55304E-6429-429E-BBB6-7C096C38C96E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {45927CF7-1BF4-479B-BBAA-8AD9CA901AE4} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0} - {3357BEC0-8216-409E-A539-F9A71DBACB81} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0} - {F16697F7-74B4-441D-A0C0-1A0572AC3AB0} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} - {75960783-8BF9-479C-9ECF-E9653B74C9A2} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} - {3C8CCD44-F47C-4624-8997-54C42F02E376} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0} - {39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} - {A0D213E9-6408-46D1-AFAF-5096C2F6E027} = {FAAD18A0-E1B8-448D-B611-AFBDA8A89808} - {165EE915-1A4F-4875-90CE-1A2AE1540AE7} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} - {4E55304E-6429-429E-BBB6-7C096C38C96E} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E8B0C994-0BF2-4692-9E22-E48B265B2804} - EndGlobalSection -EndGlobal From 27c5f234055bcc308bb27498bdf8e32fa1604cf1 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 16:51:22 +0100 Subject: [PATCH 40/41] feat(ci): enhance CI workflows and add package validation --- .github/dependabot.yml | 13 ++++ .github/workflows/build-and-test.yml | 65 ++++++++++++----- .github/workflows/main-build.yml | 14 ++-- .github/workflows/release-publish.yml | 32 ++++++--- .vscode/tasks.json | 21 ------ Directory.Build.props | 70 ++++++++++++++++--- Justfile | 3 +- MyCSharp.HttpUserAgentParser.slnx | 50 +++++++++++++ eng/Get-PackageValidationBaseline.ps1 | 45 ++++++++++++ global.json | 4 ++ .../HttpUserAgentParser.AspNetCore.csproj | 3 + .../HttpUserAgentParser.MemoryCache.csproj | 2 + .../HttpUserAgentParser.csproj | 7 ++ ...HttpUserAgentParser.NativeAot.Smoke.csproj | 3 + .../Program.cs | 2 +- 15 files changed, 272 insertions(+), 62 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 MyCSharp.HttpUserAgentParser.slnx create mode 100644 eng/Get-PackageValidationBaseline.ps1 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7105dc1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + # The workflows pin actions to commit SHAs; Dependabot updates the SHAs and their version comments + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly + groups: + github-actions: + patterns: + - "*" + commit-message: + prefix: "chore(ci)" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f10a581..d4dc976 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -13,8 +13,8 @@ on: required: false type: boolean default: false - create-pack: - description: 'Whether to pack NuGet packages' + upload-packages: + description: 'Whether to upload the NuGet packages as artifacts' required: false type: boolean default: false @@ -23,6 +23,7 @@ on: description: 'The calculated version from NBGV' value: ${{ jobs.build.outputs.version }} +# Actions are pinned to commit SHAs; Dependabot keeps them up to date. jobs: build: name: Build and Test @@ -34,12 +35,13 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - fetch-depth: 0 # Required for GitVersion + fetch-depth: 0 # Required for NBGV + persist-credentials: false - name: Setup .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: dotnet-version: | 8.0.x @@ -49,11 +51,25 @@ jobs: global-json-file: ./global.json - name: Calculate Version with NBGV - uses: dotnet/nbgv@master + uses: dotnet/nbgv@705dad19ab067f12f4e9eeaa60812e01edef5d25 # v0.5.2 id: nbgv with: setAllVars: true + # Latest nuget.org release of the major version in version.json; none for a new major version. + # Set for all following steps: the restore downloads the baseline package, the pack validates against it. + - name: Determine package validation baseline + shell: pwsh + run: | + $baseline = ./eng/Get-PackageValidationBaseline.ps1 + if ($baseline) { + "PackageValidationBaselineVersion=$baseline" >> $env:GITHUB_ENV + Write-Output "Package validation baseline: $baseline" + } + else { + Write-Output "No package validation baseline: the major version has no release yet" + } + - name: Restore dependencies run: dotnet restore @@ -67,41 +83,55 @@ jobs: - name: Upload test results if: always() && inputs.upload-test-results - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: test-results path: | **/TestResults/**/*.trx TestResults/coverage/**/*.cobertura.xml + # Always packs to validate the packages (breaking changes against the baseline); also creates the .snupkg symbol packages - name: Pack NuGet packages - if: inputs.create-pack env: PACKAGE_VERSION: ${{ steps.nbgv.outputs.SemVer2 }} run: dotnet pack --configuration "$CONFIGURATION" --no-build --output ./artifacts "-p:PackageVersion=$PACKAGE_VERSION" - name: Upload NuGet packages - if: inputs.create-pack - uses: actions/upload-artifact@v6 + if: inputs.upload-packages + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: nuget-packages - path: ./artifacts/*.nupkg + path: | + ./artifacts/*.nupkg + ./artifacts/*.snupkg + if-no-files-found: error retention-days: 30 native-aot: - name: Native AOT (${{ matrix.framework }}) - runs-on: ubuntu-latest + name: Native AOT (${{ matrix.os }}, ${{ matrix.framework }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 20 strategy: fail-fast: false matrix: + os: [ubuntu-latest, windows-latest] framework: [net8.0, net9.0, net10.0, net11.0] + include: + - os: ubuntu-latest + rid: linux-x64 + extension: '' + - os: windows-latest + rid: win-x64 + extension: '.exe' steps: - name: Checkout code - uses: actions/checkout@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: dotnet-version: | 8.0.x @@ -111,11 +141,12 @@ jobs: global-json-file: ./global.json - name: Install Native AOT prerequisites + if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev # The libraries are rooted completely: every trimming or AOT warning fails the publish. - name: Publish smoke test with Native AOT - run: dotnet publish tests/HttpUserAgentParser.NativeAot.Smoke --configuration Release --framework ${{ matrix.framework }} --runtime linux-x64 --output ./artifacts/aot + run: dotnet publish tests/HttpUserAgentParser.NativeAot.Smoke --configuration Release --framework ${{ matrix.framework }} --runtime ${{ matrix.rid }} --output ./artifacts/aot - name: Run smoke test - run: ./artifacts/aot/MyCSharp.HttpUserAgentParser.NativeAot.Smoke + run: ./artifacts/aot/MyCSharp.HttpUserAgentParser.NativeAot.Smoke${{ matrix.extension }} diff --git a/.github/workflows/main-build.yml b/.github/workflows/main-build.yml index 9c52366..a3ae89f 100644 --- a/.github/workflows/main-build.yml +++ b/.github/workflows/main-build.yml @@ -13,7 +13,7 @@ jobs: name: Build, Test and Pack uses: ./.github/workflows/build-and-test.yml with: - create-pack: true + upload-packages: true create-draft-release: name: Create Draft Release @@ -28,12 +28,14 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false + # Packages and their .snupkg symbol packages - name: Download NuGet packages - uses: actions/download-artifact@v4 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: nuget-packages path: ./artifacts @@ -57,7 +59,7 @@ jobs: - name: Generate release notes id: notes if: steps.release.outputs.state == 'new' - uses: release-drafter/release-drafter@v7 + uses: release-drafter/release-drafter@d1a19e60e81a7e650d00a7de9277f87e439117ea # v7.11.0 with: version: ${{ needs.build-and-test.outputs.version }} tag: ${{ env.TAG }} @@ -71,11 +73,11 @@ jobs: RELEASE_NOTES: ${{ steps.notes.outputs.body }} run: | printf '%s\n' "$RELEASE_NOTES" > "$RUNNER_TEMP/release-notes.md" - gh release create "$TAG" ./artifacts/*.nupkg --draft --target "$GITHUB_SHA" \ + gh release create "$TAG" ./artifacts/*.nupkg ./artifacts/*.snupkg --draft --target "$GITHUB_SHA" \ --title "Version ${TAG#v}" --notes-file "$RUNNER_TEMP/release-notes.md" - name: Refresh packages on a rerun of the same draft if: steps.release.outputs.state == 'draft' env: GH_TOKEN: ${{ github.token }} - run: gh release upload "$TAG" ./artifacts/*.nupkg --clobber + run: gh release upload "$TAG" ./artifacts/*.nupkg ./artifacts/*.snupkg --clobber diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 73f9639..2b89f73 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -7,10 +7,14 @@ on: permissions: contents: read +# Actions are pinned to commit SHAs; Dependabot keeps them up to date. jobs: publish-nuget: name: Publish to NuGet.org runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # NuGet Trusted Publishing (OIDC) steps: - name: Download release assets @@ -20,11 +24,12 @@ jobs: run: | gh release download "$TAG" \ --pattern "*.nupkg" \ + --pattern "*.snupkg" \ --dir ./artifacts \ --repo "$GITHUB_REPOSITORY" - name: Setup .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: dotnet-version: '11.0.x' @@ -40,10 +45,11 @@ jobs: version = os.environ["TAG"].removeprefix("v") ids = ["MyCSharp.HttpUserAgentParser" + suffix for suffix in ("", ".AspNetCore", ".MemoryCache")] - packages = {Path("artifacts", f"{id_}.{version}.nupkg"): id_ for id_ in ids} - if set(Path("artifacts").glob("*.nupkg")) != packages.keys(): - raise SystemExit(f"Expected the three release packages for version {version}") - for path, package_id in packages.items(): + packages = {Path("artifacts", f"{id_}.{version}.{extension}"): id_ for id_ in ids for extension in ("nupkg", "snupkg")} + found = set(Path("artifacts").glob("*.nupkg")) | set(Path("artifacts").glob("*.snupkg")) + if found != packages.keys(): + raise SystemExit(f"Expected the three release packages and their symbol packages for version {version}, found {sorted(map(str, found))}") + for path, package_id in sorted(packages.items()): with ZipFile(path) as archive: manifests = [name for name in archive.namelist() if "/" not in name and name.endswith(".nuspec")] if len(manifests) != 1: @@ -53,10 +59,18 @@ jobs: if identity != (package_id, version): raise SystemExit(f"{path} declares {identity}, expected {(package_id, version)}") + # Exchanges the GitHub OIDC token for a short-lived NuGet API key; requires a Trusted Publishing policy on nuget.org + - name: NuGet login + uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0 + id: login + with: + user: ${{ secrets.NUGET_USER }} + - name: Publish to NuGet.org env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} run: | + # dotnet nuget push also pushes the .snupkg symbol package next to each .nupkg for package in ./artifacts/*.nupkg; do echo "Publishing $package to NuGet.org..." dotnet nuget push "$package" \ @@ -68,8 +82,10 @@ jobs: echo "All packages published successfully!" - name: Upload published packages as artifacts - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: published-nuget-packages - path: ./artifacts/*.nupkg + path: | + ./artifacts/*.nupkg + ./artifacts/*.snupkg retention-days: 90 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index dcefe9b..6164c86 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -52,27 +52,6 @@ "showReuseMessage": false } }, - { - "label": "test", - "type": "shell", - "command": "dotnet test --nologo", - "args": [], - "isBackground": false - }, - { - "label": "test", - "type": "shell", - "command": "dotnet test --nologo", - "args": [], - "isBackground": false - }, - { - "label": "test", - "type": "shell", - "command": "dotnet test --nologo", - "args": [], - "isBackground": false - }, { "label": "test", "type": "shell", diff --git a/Directory.Build.props b/Directory.Build.props index aa7be99..c154fe9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -34,26 +34,25 @@ 15.0 - embedded + + portable enable en-US enable true - - - true - true - - false - true 2.12 true true true + true + snupkg + true HTTP User Agent Parser for .NET @@ -79,6 +78,61 @@ true + + + + + + + + + + + + + + item.ItemSpec).ToArray(); + var document = XDocument.Load(DocumentationFile); + var excluded = document.Descendants("member").Where(member => + { + var name = (string)member.Attribute("name") ?? string.Empty; + var id = name.Length > 2 && name[1] == ':' ? name.Substring(2) : name; + return exclusions.Any(exclusion => id == exclusion || id.StartsWith(exclusion + ".", StringComparison.Ordinal)); + }).ToList(); + + if (excluded.Count > 0) + { + excluded.ForEach(member => member.Remove()); + document.Save(DocumentationFile); + Log.LogMessage(MessageImportance.Normal, "Removed {0} excluded members from {1}", excluded.Count, DocumentationFile); + } + ]]> + + + + + + + + + + + + + + + + + true diff --git a/Justfile b/Justfile index 6b4e250..bb62cf9 100644 --- a/Justfile +++ b/Justfile @@ -53,8 +53,9 @@ test-filter QUERY: dotnet test --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal --filter "{{QUERY}}" # ===== Packaging / Release ===== +# Validates against the latest nuget.org release of the major version in version.json (none for a new major version) pack *ARGS: - dotnet pack --configuration "{{CONFIG}}" --nologo --verbosity minimal -o "./artifacts/packages" {{ARGS}} + dotnet pack --configuration "{{CONFIG}}" --nologo --verbosity minimal -o "./artifacts/packages" "-p:PackageValidationBaselineVersion=$(./eng/Get-PackageValidationBaseline.ps1)" {{ARGS}} publish PROJECT *ARGS: dotnet publish "{{PROJECT}}" --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}" {{ARGS}} diff --git a/MyCSharp.HttpUserAgentParser.slnx b/MyCSharp.HttpUserAgentParser.slnx new file mode 100644 index 0000000..5b5604b --- /dev/null +++ b/MyCSharp.HttpUserAgentParser.slnx @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eng/Get-PackageValidationBaseline.ps1 b/eng/Get-PackageValidationBaseline.ps1 new file mode 100644 index 0000000..f135578 --- /dev/null +++ b/eng/Get-PackageValidationBaseline.ps1 @@ -0,0 +1,45 @@ +# Determines the package validation baseline from version.json and the versions published on nuget.org: +# the latest stable release of the major version in version.json that all packages share. +# Prints nothing while the major version has no release yet: a new major version may contain breaking changes. +# Usage: dotnet pack "-p:PackageValidationBaselineVersion=$(./eng/Get-PackageValidationBaseline.ps1)" + +[CmdletBinding()] +param( + [ValidateNotNullOrEmpty()] + [string] $VersionFile = (Join-Path $PSScriptRoot '..' 'version.json'), + + [ValidateNotNullOrEmpty()] + [string[]] $PackageIds = @( + 'MyCSharp.HttpUserAgentParser', + 'MyCSharp.HttpUserAgentParser.AspNetCore', + 'MyCSharp.HttpUserAgentParser.MemoryCache' + ), + + [ValidateNotNullOrEmpty()] + [string] $FeedUrl = 'https://api.nuget.org/v3-flatcontainer' +) + +$ErrorActionPreference = 'Stop' + +# ConvertFrom-Json accepts the comments of version.json; a prerelease suffix ("4.1-preview") does not change the major version +$versionJson = Get-Content -Path $VersionFile -Raw | ConvertFrom-Json +$major = ([version](($versionJson.version -split '-')[0])).Major + +$shared = $null +foreach ($packageId in $PackageIds) { + try { + $published = @((Invoke-RestMethod -Uri "$FeedUrl/$($packageId.ToLowerInvariant())/index.json").versions) + } + catch [Microsoft.PowerShell.Commands.HttpResponseException] { + if ($_.Exception.Response.StatusCode -ne [System.Net.HttpStatusCode]::NotFound) { throw } + $published = @() # never published + } + + $releases = @($published | Where-Object { $_ -notmatch '-' -and ([version]$_).Major -eq $major }) + $shared = if ($null -eq $shared) { $releases } else { @($shared | Where-Object { $releases -contains $_ }) } +} + +$baseline = $shared | Sort-Object -Property { [version]$_ } -Descending | Select-Object -First 1 +if ($baseline) { + Write-Output $baseline +} diff --git a/global.json b/global.json index 147d0eb..210272f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,10 @@ { "sdk": { "version": "11.0.100", + "rollForward": "disable", "allowPrerelease": false + }, + "test": { + "runner": "VSTest" } } diff --git a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj index 8a27dc0..0b245ba 100644 --- a/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj +++ b/src/HttpUserAgentParser.AspNetCore/HttpUserAgentParser.AspNetCore.csproj @@ -7,6 +7,9 @@ true + + false diff --git a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj index 3a072ca..c3a8568 100644 --- a/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj +++ b/src/HttpUserAgentParser.MemoryCache/HttpUserAgentParser.MemoryCache.csproj @@ -7,6 +7,8 @@ true + + true diff --git a/src/HttpUserAgentParser/HttpUserAgentParser.csproj b/src/HttpUserAgentParser/HttpUserAgentParser.csproj index fcfa165..ba862c4 100644 --- a/src/HttpUserAgentParser/HttpUserAgentParser.csproj +++ b/src/HttpUserAgentParser/HttpUserAgentParser.csproj @@ -7,6 +7,8 @@ true + + true @@ -18,6 +20,11 @@ + + + + + diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj b/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj index 99808f0..9e8095b 100644 --- a/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/HttpUserAgentParser.NativeAot.Smoke.csproj @@ -15,6 +15,9 @@ true false + + true + true false diff --git a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs index 7e2555c..2a181d1 100644 --- a/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs +++ b/tests/HttpUserAgentParser.NativeAot.Smoke/Program.cs @@ -46,7 +46,7 @@ void Check(bool condition, string description) // Source-generated regular expressions Regex? windows10 = chrome.Platform?.Regex; Check(windows10 is not null && windows10.IsMatch(Chrome), "platform regex"); -Check(HttpUserAgentStatics.Platforms.Count == 43 && HttpUserAgentStatics.Platforms.All(static p => p.Regex is not null), "platform regexes"); +Check(HttpUserAgentStatics.Platforms.Count == 44 && HttpUserAgentStatics.Platforms.All(static p => p.Regex is not null), "platform regexes"); Regex chromeRegex = HttpUserAgentStatics.Browsers.First(static b => b.Key.ToString().StartsWith("Chrome", StringComparison.Ordinal)).Key; Check(string.Equals(chromeRegex.Match(Chrome).Groups[1].Value, "158.0.0.0", StringComparison.Ordinal), "browser regex version group"); From af2ff6c3efea2e8c1f2b00c09df5ddd6c6180796 Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Thu, 26 Nov 2026 17:00:07 +0100 Subject: [PATCH 41/41] feat(tests): update test configurations and commands for coverage --- .github/copilot-instructions.md | 4 +- .github/workflows/build-and-test.yml | 6 +-- .vscode/tasks.json | 4 +- Directory.Build.props | 37 ++++--------------- Directory.Packages.props | 14 +++---- Justfile | 9 ++--- global.json | 2 +- .../testconfig.json | 14 +++++++ .../testconfig.json | 14 +++++++ .../testconfig.json | 14 +++++++ 10 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 tests/HttpUserAgentParser.AspNetCore.UnitTests/testconfig.json create mode 100644 tests/HttpUserAgentParser.MemoryCache.UnitTests/testconfig.json create mode 100644 tests/HttpUserAgentParser.UnitTests/testconfig.json diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 62ffd87..2471337 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -51,10 +51,10 @@ Use these commands consistently: `dotnet build --nologo` - Test (all): - `dotnet test --nologo` + `dotnet test --no-logo` - Test (single project): - `dotnet test --nologo` + `dotnet test --project --no-logo` --- diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d4dc976..fce686e 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -79,7 +79,7 @@ jobs: run: dotnet build --configuration "$CONFIGURATION" --no-restore "-p:Version=$PACKAGE_VERSION" - name: Test - run: dotnet test --configuration "$CONFIGURATION" --no-build --verbosity normal --logger "trx;LogFilePrefix=test-results" + run: dotnet test --configuration "$CONFIGURATION" --no-build --output Normal --report-trx --coverlet --results-directory ./TestResults --results-directory-layout per-module - name: Upload test results if: always() && inputs.upload-test-results @@ -87,8 +87,8 @@ jobs: with: name: test-results path: | - **/TestResults/**/*.trx - TestResults/coverage/**/*.cobertura.xml + TestResults/**/*.trx + TestResults/**/coverage.cobertura.*.xml # Always packs to validate the packages (breaking changes against the baseline); also creates the .snupkg symbol packages - name: Pack NuGet packages diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6164c86..5066709 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -41,7 +41,7 @@ "args": [ "test", "--no-build", - "--nologo" + "--no-logo" ], "problemMatcher": "$msCompile", "dependsOn": "dotnet: build", @@ -55,7 +55,7 @@ { "label": "test", "type": "shell", - "command": "dotnet test --nologo", + "command": "dotnet test --no-logo", "args": [], "isBackground": false } diff --git a/Directory.Build.props b/Directory.Build.props index c154fe9..d26d80d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -144,41 +144,18 @@ low - - - true - lcov,opencover,cobertura - $(MSBuildThisFileDirectory)TestResults/coverage/$(TargetFramework)/$(MSBuildProjectName). - GeneratedCodeAttribute - true - - 100 - line,branch,method - total + + + true - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + - - - [MyCSharp.HttpUserAgentParser]* - - - [MyCSharp.HttpUserAgentParser.MemoryCache]* - - - [MyCSharp.HttpUserAgentParser.AspNetCore]* - -