XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFESystem.Browser;

/// <summary>
/// Platform HTTP/TLS boundary. Implementations must bound bytes, time and redirects
/// and validate HTTPS chain, hostname and certificate validity before returning.
/// </summary>
public interface IWebTransport
{
    WebResponse Get(Uri address, BrowserLimits limits);
}
/// <summary>Optional explicit same-origin script-request headers. Implementations
/// reject cross-origin redirects before forwarding these author-supplied values.</summary>
public interface IWebRequestTransport : IWebTransport
{
    WebResponse Get(Uri address, BrowserLimits limits, IReadOnlyDictionary<string, string> headers);
}

public interface IBrowserRandomSource { void FillRandom(Span<byte> bytes); }
public delegate void BrowserRandomFill(Span<byte> bytes);

/// <summary>
/// Optional declaration of the explicitly injected backend's implementation.
/// These flags do not assert that a link, IP address, peer or certificate is ready.
/// Each request must still check its platform prerequisites and HTTPS validation.
/// </summary>
public interface IWebTransportCapabilities
{
    bool IsNative { get; }
    bool SupportsHttp { get; }
    bool SupportsHttps { get; }
}

public sealed record WebResponse(Uri Address, int StatusCode, string ContentType, string Body,
    bool CertificateValidated = false, string? ContentSecurityPolicy = null, string? BodySha256 = null, byte[]? BinaryBody = null, bool NoSniff = false);

public sealed class UnavailableWebTransport : IWebTransport, IWebTransportCapabilities
{
    public bool IsNative => false;
    public bool SupportsHttp => false;
    public bool SupportsHttps => false;

    public WebResponse Get(Uri address, BrowserLimits limits) =>
        throw new NotSupportedException("This runtime has no HTTP/TLS transport. Offline pages and JavaScript are available.");
}