febe-sonda legge un HAR troncato senza perdere la parte buona

Chrome ha troncato due esportazioni del giro A quater (a 200 000 byte e a
57 MB, a meta di un corpo di risposta) e la sonda le rifiutava come file
sbagliati. Ora da-har e richieste tengono le voci complete, scartano quella
dentro cui il file finisce e lo dicono; un file rotto in qualunque altro
modo resta rifiutato.

Per richieste la voce scartata conta comunque come dati: si chiude dove si
ferma e passa per le stesse regole di una voce intera, e ogni stringa JSON
del testo interrotto conta come valore, cosi un nome che e un dato solo li
non arriva nel file delle forme.

In A quater: come esportare senza che il file si tronchi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-13 00:19:24 +01:00
1 parent 8d2f85693c
commit 78aa32bdb2
8 files changed
+831 -41

No files matched your search

+10 -20
View File
@@ -20,6 +20,13 @@ namespace Febe.Sonda;
/// <param name="DocumentsWithoutData">Left out: page documents that embed no JSON.</param>
public sealed record HarImportReport(int Entries, int DataResponses, int Documents, int DocumentBlocks, int OtherHosts, int NotData, int WithoutBody, int NotJson, int DocumentsWithoutData)
{
/// <summary>The file ends before its JSON does: <see cref="Entries"/> counts the complete entries only, the one the
/// file ends inside is left out (<see cref="HarFile"/>).</summary>
public bool Truncated { get; init; }
/// <summary>The file ends inside an entry, which is left out (not counted in <see cref="Entries"/>).</summary>
public bool DroppedEntry { get; init; }
public int Written => DataResponses + DocumentBlocks;
}
@@ -67,26 +74,9 @@ public static partial class HarImporter
throw new InvalidOperationException($"La cartella «{folder}» non è vuota: indica una cartella nuova, solo per questa conversione.");
}
JsonDocument document;
try
using (var file = HarFile.Open(har, BodyOptions.MaxDepth))
{
using var stream = File.OpenRead(har);
document = JsonDocument.Parse(stream);
}
catch (JsonException ex)
{
throw new InvalidDataException($"{Path.GetFileName(har)}: non è un file HAR valido (riga {ex.LineNumber + 1}).", ex);
}
using (document)
{
if (document.RootElement.ValueKind != JsonValueKind.Object
|| !document.RootElement.TryGetProperty("log", out var log) || log.ValueKind != JsonValueKind.Object
|| !log.TryGetProperty("entries", out var entries) || entries.ValueKind != JsonValueKind.Array)
{
throw new InvalidDataException($"{Path.GetFileName(har)}: non è un file HAR (manca «log.entries»).");
}
var entries = file.Entries;
Directory.CreateDirectory(folder);
File.WriteAllText(
Path.Combine(folder, "LEGGIMI.txt"),
@@ -147,7 +137,7 @@ public static partial class HarImporter
}
}
return new HarImportReport(count, data, documents, blocks, otherHosts, notData, withoutBody, notJson, documentsWithoutData);
return new HarImportReport(count, data, documents, blocks, otherHosts, notData, withoutBody, notJson, documentsWithoutData) { Truncated = file.Truncated, DroppedEntry = file.DroppedAnEntry };
}
}