«Aggiungi account» ha una sola casella: mentre Alberto scrive compaiono subito i suggerimenti locali, poi i profili di Instagram con la foto, come chiesto in #37. Il browser di Febe scrive nella casella «Cerca» di Instagram con tasti veri da una mappa chiusa (mai Invio, Tab o Esc), controlla prima il fuoco, legge la risposta della pagina e non clicca mai un risultato. La ricerca ha una categoria propria nel Governatore, con tetti larghi che non consumano quelli della raccolta, e si dà il turno con il motore sull'unica pagina; a fine sessione la pagina torna comunque al riposo. Le foto passano dal CDN con un permesso ciascuna e restano solo in memoria. Le risposte di Alberto del 15 novembre (controllo del fuoco, turni, evento requestWillBeSent, niente foto dei seguiti per ora) sono in §6.1 e in docs/decisioni.md. Su Instagram vero la ricerca parte quando i bersagli search-open e search-box saranno raccolti dal vivo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
6.0 KiB
C#
144 lines
6.0 KiB
C#
using System.Text.Json;
|
|
|
|
namespace Febe.Core.Collection;
|
|
|
|
/// <summary>Which kind of host served a response (spec §14.5: only the site/CDN distinction is kept).</summary>
|
|
public enum HostKind
|
|
{
|
|
/// <summary>The site itself (Instagram pages and data, or the local test site).</summary>
|
|
Site,
|
|
|
|
/// <summary>The content delivery network that serves photos and videos.</summary>
|
|
Cdn,
|
|
|
|
/// <summary>Anything else the page happens to contact.</summary>
|
|
Other,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sanitized description of a response seen by the page: never the query string, never headers, never the body.
|
|
/// </summary>
|
|
/// <param name="RequestId">Browser request identifier (opaque, only meaningful inside one browser session).</param>
|
|
/// <param name="HostKind">Site, CDN or other.</param>
|
|
/// <param name="Url">Scheme, host and path, without query string and fragment (see <see cref="UrlSanitizer"/>).
|
|
/// For CDN responses it must not be logged: it identifies files (spec §13.2).</param>
|
|
/// <param name="Host">Host name, with the port when it is not the default one.</param>
|
|
/// <param name="Path">Path without query string and fragment.</param>
|
|
/// <param name="Status">HTTP status code.</param>
|
|
/// <param name="MimeType">MIME type declared by the response, lower case, without parameters.</param>
|
|
/// <param name="ResourceType">Browser resource type (Document, XHR, Fetch, Image, ...), when known.</param>
|
|
/// <param name="IsMainFrameDocument">True for the document of the main frame (a page load).</param>
|
|
/// <param name="At">When the response was seen.</param>
|
|
/// <param name="RequestOrder">
|
|
/// Order in which the page started the request among the site's requests (from 1, <c>Network.requestWillBeSent</c>);
|
|
/// 0 when unknown. The profile search (issue #37) tells answers to texts typed before the last key from the answer to
|
|
/// the text in the box with it.
|
|
/// </param>
|
|
public sealed record ResponseDescriptor(
|
|
string RequestId,
|
|
HostKind HostKind,
|
|
string Url,
|
|
string Host,
|
|
string Path,
|
|
int Status,
|
|
string MimeType,
|
|
string? ResourceType,
|
|
bool IsMainFrameDocument,
|
|
DateTimeOffset At,
|
|
long RequestOrder = 0);
|
|
|
|
/// <summary>A main-frame navigation: a new document, or a route change inside a single-page site.</summary>
|
|
/// <param name="HostKind">Site, CDN or other.</param>
|
|
/// <param name="Url">Address without query string and fragment.</param>
|
|
/// <param name="Host">Host name (with port when not default); empty for about:blank and similar.</param>
|
|
/// <param name="Path">Path without query string and fragment.</param>
|
|
/// <param name="At">When the navigation was seen.</param>
|
|
/// <param name="SameDocument">True for a route change without a new document (history.pushState).</param>
|
|
public sealed record NavigationDescriptor(HostKind HostKind, string Url, string Host, string Path, DateTimeOffset At, bool SameDocument = false);
|
|
|
|
/// <summary>
|
|
/// Receives the JSON bodies captured by the response tap (spec §6.2): readers and signal detection.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The <see cref="JsonDocument"/> is owned by the caller and disposed right after the call returns:
|
|
/// consumers must not keep references to it or to its elements. Bodies live only in memory and are never logged.
|
|
/// </remarks>
|
|
public interface IResponseConsumer
|
|
{
|
|
ValueTask ConsumeAsync(ResponseDescriptor response, JsonDocument body, CancellationToken ct);
|
|
}
|
|
|
|
/// <summary>Receives metadata of every response and every main-frame navigation (no bodies).</summary>
|
|
/// <remarks>Called on the browser event thread: implementations must be quick and must not block.</remarks>
|
|
public interface IResponseObserver
|
|
{
|
|
void OnResponse(ResponseDescriptor response);
|
|
|
|
void OnNavigation(NavigationDescriptor navigation);
|
|
|
|
/// <summary>
|
|
/// The body of a data response announced by <see cref="OnResponse"/> will not reach the consumers: it failed to
|
|
/// load, was too large, was not JSON after all (Instagram's «for (;;);» answers), or the page moved on. Observers
|
|
/// that wait for bodies stop waiting for this one.
|
|
/// </summary>
|
|
void OnBodyDropped(string requestId)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// The same as <see cref="OnBodyDropped(string)"/>, with the reason (for the diagnostic report, issue #39). The tap
|
|
/// calls this one; by default it forwards to the overload without a reason.
|
|
/// </summary>
|
|
void OnBodyDropped(string requestId, BodyDropReason reason) => OnBodyDropped(requestId);
|
|
|
|
/// <summary>
|
|
/// A response announced by <see cref="OnResponse"/> finished loading: <paramref name="encodedBytes"/> is what
|
|
/// crossed the network (the browser's encodedDataLength). Called for every response, whether its body is read or not.
|
|
/// </summary>
|
|
void OnLoadingFinished(string requestId, long encodedBytes)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// The page started a request to the site: <paramref name="order"/> is its <see cref="ResponseDescriptor.RequestOrder"/>.
|
|
/// Nothing else of the request is passed (no address, no body).
|
|
/// </summary>
|
|
void OnRequestStarted(long order)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>Why the body of a response did not reach the consumers (closed list: a report may show it).</summary>
|
|
public enum BodyDropReason
|
|
{
|
|
/// <summary>Over the size the tap reads (memory guard).</summary>
|
|
TooLarge,
|
|
|
|
/// <summary>The browser says the request failed.</summary>
|
|
LoadingFailed,
|
|
|
|
/// <summary>The page moved to another document before the body finished.</summary>
|
|
FrameNavigated,
|
|
|
|
/// <summary>The browser was restarted or reconnected.</summary>
|
|
Reconnected,
|
|
|
|
/// <summary>Nobody was listening for bodies.</summary>
|
|
NoConsumers,
|
|
|
|
/// <summary>The browser no longer had the body (evicted from its buffer) or gave none.</summary>
|
|
Unavailable,
|
|
|
|
/// <summary>The body did not arrive in time.</summary>
|
|
Timeout,
|
|
|
|
/// <summary>Declared as data, but not JSON after all.</summary>
|
|
NotJson,
|
|
|
|
/// <summary>A page document without any embedded JSON block.</summary>
|
|
NoJsonBlock,
|
|
|
|
/// <summary>An unexpected error while reading it.</summary>
|
|
Unexpected,
|
|
}
|