1
This commit is contained in:
@@ -11,6 +11,7 @@ namespace BITKit.Net.Http
|
||||
public int Port { get; set; }
|
||||
private readonly HttpListener _httpListener = new();
|
||||
public event Func<HttpListenerRequest,HttpContent> OnRequest;
|
||||
public event Action<byte[]> OnRequestBytes;
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
private CancellationToken _cancellationToken=>_cancellationTokenSource.Token;
|
||||
|
||||
@@ -69,7 +70,6 @@ namespace BITKit.Net.Http
|
||||
|
||||
var response = context.Response;
|
||||
|
||||
|
||||
var output = response.OutputStream;
|
||||
|
||||
if (request.RawUrl is "/favicon.ico")
|
||||
@@ -83,11 +83,16 @@ namespace BITKit.Net.Http
|
||||
response.Headers.Add("Access-Control-Allow-Origin", "*"); // 允许任何来源访问,生产环境应更具体设置
|
||||
response.Headers.Add("Access-Control-Allow-Methods", "*"); // 允许的HTTP方法
|
||||
response.Headers.Add("Access-Control-Allow-Headers", "*"); // 允许的标头
|
||||
|
||||
|
||||
var content = OnRequest?.Invoke(request);
|
||||
//添加返回的文本为utf-8
|
||||
response.ContentType = "application/json;charset=utf-8";
|
||||
response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
|
||||
|
||||
|
||||
var buffer = StringHelper.GetBytes(ContextModel.Error("没有注册请求事件"));
|
||||
|
||||
var content = OnRequest?.Invoke(request);
|
||||
if (content is not null)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
|
Reference in New Issue
Block a user