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

@@ -99,6 +99,15 @@ public sealed class BrowserFileFetcher : IFileFetcher
return new FetchResult(FetchOutcome.NetworkError, 0, status, "Il browser non ha aperto il flusso dei dati.");
}
// The browser hands out the stream only once the whole resource has been loaded: a file over the limit has
// already crossed the network. When its length is declared, nothing is read and the real transfer is counted.
var declared = DeclaredLength(resource);
if (options?.MaxBytes is { } limit && declared > limit)
{
await CloseQuietlyAsync(handle).ConfigureAwait(false);
return new FetchResult(FetchOutcome.TooLarge, 0, status, "Il file supera la dimensione massima ammessa.") { TransferredBytes = declared };
}
long written = 0;
try
{
@@ -122,7 +131,10 @@ public sealed class BrowserFileFetcher : IFileFetcher
var allowed = (int)Math.Max(0, max - written);
await destination.WriteAsync(bytes.AsMemory(0, allowed), ct).ConfigureAwait(false);
written += allowed;
return new FetchResult(FetchOutcome.TooLarge, written, status, "Il file supera la dimensione massima ammessa.");
return new FetchResult(FetchOutcome.TooLarge, written, status, "Il file supera la dimensione massima ammessa.")
{
TransferredBytes = declared > written ? declared : null,
};
}
await destination.WriteAsync(bytes, ct).ConfigureAwait(false);
@@ -147,6 +159,27 @@ public sealed class BrowserFileFetcher : IFileFetcher
: new FetchResult(FetchOutcome.Completed, written, status, null);
}
/// <summary>The Content-Length the response declared (header names are case-insensitive), or null.</summary>
private static long? DeclaredLength(JsonElement resource)
{
if (!resource.TryGetProperty("headers", out var headers) || headers.ValueKind != JsonValueKind.Object)
{
return null;
}
foreach (var header in headers.EnumerateObject())
{
if (string.Equals(header.Name, "content-length", StringComparison.OrdinalIgnoreCase)
&& header.Value.ValueKind == JsonValueKind.String
&& long.TryParse(header.Value.GetString(), System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out var length))
{
return length;
}
}
return null;
}
private async Task CloseQuietlyAsync(string handle)
{
try
@@ -168,7 +168,8 @@ public sealed class CollectionPipeline : IAsyncDisposable
options.DataBudget,
options.Clock,
options.Random,
new DownloadOptions { StagingFolder = options.StagingFolder });
new DownloadOptions { StagingFolder = options.StagingFolder },
signals);
var pipeline = new CollectionPipeline(tap, signals, capture, driver, runner, downloads, siteMap, targets);
pipeline._subscriptions.Add(tap.AddObserver(signals));