添加了授权
This commit is contained in:
63
BITKit/Scripts/Net/HttpListener_GodotBased.cs
Normal file
63
BITKit/Scripts/Net/HttpListener_GodotBased.cs
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user