using System.Collections.Generic; namespace FileShare_Services.Core { /// /// 抽象的请求上下文,屏蔽不同宿主(ASP.NET Core / Desktop WebView)的差异。 /// public class ServiceEndpointContext { /// /// 请求路径,例如 "api/wData" /// public string Path { get; init; } = string.Empty; /// /// HTTP 方法(GET, POST, PUT, DELETE 等) /// public string Method { get; init; } = "GET"; /// /// 请求头 /// public Dictionary Headers { get; init; } = new(StringComparer.OrdinalIgnoreCase); /// /// 请求体(原始字符串) /// public string? Body { get; set; } /// /// 查询参数 /// public Dictionary Query { get; init; } = new(StringComparer.OrdinalIgnoreCase); /// /// 路由路径参数。 /// public Dictionary RouteValues { get; init; } = new(StringComparer.OrdinalIgnoreCase); /// /// 响应状态码 /// public int StatusCode { get; set; } = 200; /// /// 响应状态描述 /// public string StatusMessage { get; set; } = "OK"; /// /// 响应头 /// public Dictionary ResponseHeaders { get; set; } = new(StringComparer.OrdinalIgnoreCase) { ["Content-Type"] = "application/json; charset=utf-8" }; /// /// 响应体 /// public object? ResponseBody { get; set; } /// /// 存储在请求生命周期中的任意数据(由中间件/过滤器使用) /// public Dictionary Items { get; init; } = new(); /// /// 获取请求头值 /// public string? GetHeader(string key) { return Headers.TryGetValue(key, out var value) ? value : null; } /// /// 设置响应头 /// public void SetResponseHeader(string key, string value) { ResponseHeaders[key] = value; } } }