using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text; namespace Apewer.Web { /// 请求。 public sealed class MiniRequest : IToJson { /// 上下文。 public MiniContext Context { get; private set; } #region connection internal bool Http11 = false; /// 要求保持连接。 public bool KeepAlive { get; internal set; } #endregion #region headers StringPairs _headers = new StringPairs(); /// 头部。 public StringPairs Headers { get => _headers; } /// 统一资源定位。 public Uri Url { get; internal set; } /// 请求方法。 public string Method { get; internal set; } /// URL 路径。 public string Path { get; internal set; } /// HTTP 协议版本。 public string Version { get; internal set; } /// 客户端可接受 Brotli 压缩。 public bool Brotli { get; internal set; } /// 客户端可接受 Gzip 压缩。 public bool Gzip { get; internal set; } /// 内容长度,单位:字节。 public long ContentLength { get => _headers.GetValue("Content-Length", true).Int64(); } #endregion #region /// 请求体的流。 public Stream Body { get => Context.Connection.GetRequestStream(); } #endregion /// internal MiniRequest(MiniContext context) { Context = context; } /// 专用的序列化方法。 public Json ToJson() { var json = new Json(); json.SetProperty("Method", Method); json.SetProperty("Path", Path); json.SetProperty("Url", Url?.OriginalString); json.SetProperty("Headers", Json.From(Headers)); return json; } } }