添加了授权

This commit is contained in:
CortexCore
2023-09-21 03:49:27 +08:00
parent c59d513cca
commit c65fe87a6c
10 changed files with 317 additions and 20 deletions

View File

@@ -0,0 +1,63 @@
using Godot;
using System;
using System.Net;
using System.Net.Http;
using BITKit.Net.Http;
using Microsoft.Extensions.DependencyInjection;
namespace BITKit.Net.Http;
public partial class HttpListener_GodotBased : EntityComponent,IHttpListenerService
{
[Export] private bool autoStart;
[Export]
private int port
{
get => _httpListenerServiceImplementation.Port;
set => _httpListenerServiceImplementation.Port = value;
}
private readonly IHttpListenerService _httpListenerServiceImplementation = new HttpListenerService();
public override void BuildService(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IHttpListenerService>(this);
}
public override void _Ready()
{
if (autoStart)
{
Start();
}
}
public override void _ExitTree()
{
if(IsListening)
{
Stop();
}
}
public bool IsListening => _httpListenerServiceImplementation.IsListening;
int IHttpListenerService.Port
{
get => _httpListenerServiceImplementation.Port;
set => _httpListenerServiceImplementation.Port = value;
}
event Func<HttpListenerRequest, HttpContent> IHttpListenerService.OnRequest
{
add => _httpListenerServiceImplementation.OnRequest += value;
remove => _httpListenerServiceImplementation.OnRequest -= value;
}
public void Start()
{
_httpListenerServiceImplementation.Start();
}
public void Stop()
{
_httpListenerServiceImplementation.Stop();
}
}