Compare commits

...

4 commits

Author SHA1 Message Date
uwaa
c675cd221e http: add OnException 2024-12-02 16:18:56 +00:00
uwaa
210c8de1ed http: output a Task on Websocket.Close 2024-12-02 16:18:14 +00:00
uwaa
de1f3f756a http: always send content-length in response 2024-12-02 16:17:53 +00:00
uwaa
48bd35d20b csproj cleanups 2024-12-02 16:17:26 +00:00
9 changed files with 80 additions and 63 deletions

10
Common.targets Normal file
View file

@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
</PropertyGroup>
</Project>

View file

@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>false</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug</Configurations>
<RootNamespace>Uwaa.HTTP.Example</RootNamespace>
<AssemblyName>Uwaa.HTTP.Example</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<ImplicitUsings>false</ImplicitUsings>
<Configurations>Debug</Configurations>
<RootNamespace>Uwaa.HTTP.Example</RootNamespace>
<AssemblyName>Uwaa.HTTP.Example</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\HTTP\HTTP.csproj" />
<Import Project="../Common.targets"/>
<None Update="certs\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="www-static\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HTTP\HTTP.csproj" />
<None Update="certs\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="www-static\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Uwaa.HTTP</RootNamespace>
<AssemblyName>Uwaa.HTTP</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Uwaa.HTTP</RootNamespace>
<AssemblyName>Uwaa.HTTP</AssemblyName>
</PropertyGroup>
<Import Project="../Common.targets"/>
</Project>

View file

@ -97,7 +97,7 @@ public class HttpResponse
}
else
{
Fields.ContentLength = null;
Fields.ContentLength = 0;
Fields.ContentType = null;
}

View file

@ -50,6 +50,11 @@ public sealed class HttpServer
/// </summary>
public event Action<HttpRequest, HttpResponse>? OnResponse;
/// <summary>
/// Called when a request causes an exception.
/// </summary>
public event Action<IPEndPoint, Exception>? OnException;
/// <summary>
/// The maximum time the socket may be inactive before it is presumed dead and closed.
/// </summary>
@ -179,12 +184,12 @@ public sealed class HttpServer
await new HttpResponse(400, e.Message).WriteTo(httpStream).WaitAsync(Timeout);
}
catch { }
break;
throw;
}
catch (TimeoutException)
{
//Timeout
break;
throw;
}
catch (IOException)
{
@ -203,10 +208,11 @@ public sealed class HttpServer
}
}
}
catch (Exception)
catch (Exception e)
{
//Swallow exceptions to prevent the server from crashing.
//When debugging, use a debugger to break on exceptions.
OnException?.Invoke(endpoint, e);
}
finally
{

View file

@ -250,7 +250,7 @@ public class Websocket
}
}
internal async void Close(CloseStatus status = CloseStatus.NormalClosure)
internal async Task Close(CloseStatus status = CloseStatus.NormalClosure)
{
var pool = ArrayPool<byte>.Shared;
byte[] closeBuf = pool.Rent(2);

View file

@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Uwaa.PNG</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Uwaa.PNG</RootNamespace>
<AssemblyName>Uwaa.PNG</AssemblyName>
</PropertyGroup>
<Import Project="../Common.targets"/>
</Project>

View file

@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Uwaa.Pleroma.Test</RootNamespace>
<AssemblyName>Uwaa.Pleroma.Test</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<ImplicitUsings>disable</ImplicitUsings>
<RootNamespace>Uwaa.Pleroma.Test</RootNamespace>
<AssemblyName>Uwaa.Pleroma.Test</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Pleroma\Pleroma.csproj" />
</ItemGroup>
<Import Project="../Common.targets"/>
<ItemGroup>
<ProjectReference Include="..\Pleroma\Pleroma.csproj" />
</ItemGroup>
</Project>

View file

@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Uwaa.Pleroma</RootNamespace>
<AssemblyName>Uwaa.Pleroma</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<ImplicitUsings>disable</ImplicitUsings>
<RootNamespace>Uwaa.Pleroma</RootNamespace>
<AssemblyName>Uwaa.Pleroma</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\HTTP\HTTP.csproj" />
</ItemGroup>
<Import Project="../Common.targets"/>
<ItemGroup>
<Using Include="System" />
<Using Include="System.Collections.Generic" />
<Using Include="System.IO" />
<Using Include="System.Linq" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HTTP\HTTP.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="System" />
<Using Include="System.Collections.Generic" />
<Using Include="System.IO" />
<Using Include="System.Linq" />
</ItemGroup>
</Project>