Unione delle correzioni della raccolta

This commit is contained in:
Claude committed 2026-10-14 01:39:42 +00:00
commit 7d208f6030
28 files changed
+2619 -200

No files matched your search

+31 -2
View File
@@ -57,6 +57,35 @@ public sealed class SignalDetector : IResponseObserver, IResponseConsumer, IStop
public Signal? ObserveResponse(ResponseDescriptor response)
{
ArgumentNullException.ThrowIfNull(response);
return MatchResponse(response, statusOnly: false) is { } rule ? Raise(rule.Level, rule.Code, response.Url) : null;
}
/// <summary>
/// The HTTP status of a file the download queue asked the CDN for (spec §6.5). The browser serves
/// <c>Network.loadNetworkResource</c> outside the page, so the page's network events never show these responses:
/// the queue reports them here, and the status rules for the CDN apply (e.g. 429, «vale per sito e CDN»).
/// Returns the level of the matching rule — also when the same signal was already reported within
/// <see cref="DedupeWindow"/>, so the caller stops every time — or null when no rule matches.
/// </summary>
/// <remarks>The incident keeps only scheme and host: the path of a CDN address identifies a file (spec §13.2).</remarks>
public SignalLevel? ObserveDownload(Uri address, int status)
{
ArgumentNullException.ThrowIfNull(address);
var sanitized = UrlSanitizer.Sanitize(address.AbsoluteUri);
var origin = $"{sanitized.Scheme}://{sanitized.Host}/";
var response = new ResponseDescriptor("download", HostKind.Cdn, origin, sanitized.Host, "/", status, string.Empty, "Other", false, _clock.Now);
if (MatchResponse(response, statusOnly: true) is not { } rule)
{
return null;
}
Raise(rule.Level, rule.Code, origin);
return rule.Level;
}
/// <summary>The first status or path rule for <paramref name="response"/>; path rules describe pages, not files.</summary>
private SignalRule? MatchResponse(ResponseDescriptor response, bool statusOnly)
{
var scope = response.IsMainFrameDocument ? SignalScope.Document : SignalScope.Subresource;
var paths = !UserIsOnPage();
foreach (var rule in _rules.Rules)
@@ -67,9 +96,9 @@ public sealed class SignalDetector : IResponseObserver, IResponseConsumer, IStop
}
if ((rule.Statuses.Count > 0 && rule.Statuses.Contains(response.Status))
|| (paths && rule.Path is not null && SafeIsMatch(rule.Path, response.Path)))
|| (!statusOnly && paths && rule.Path is not null && SafeIsMatch(rule.Path, response.Path)))
{
return Raise(rule.Level, rule.Code, response.Url);
return rule;
}
}