diff --git a/test/YetAnotherHttpHandler.Test/UdsTest.cs b/test/YetAnotherHttpHandler.Test/UdsTest.cs new file mode 100644 index 0000000..b8fbe7d --- /dev/null +++ b/test/YetAnotherHttpHandler.Test/UdsTest.cs @@ -0,0 +1,41 @@ +using System.Security.Cryptography.X509Certificates; +using Cysharp.Net.Http; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Xunit.Abstractions; + +namespace _YetAnotherHttpHandler.Test; + +public class UdsTest(ITestOutputHelper testOutputHelper) : Http2TestBase(testOutputHelper) +{ + private readonly string _udsPath = Path.Combine(Path.GetTempPath(), $"yaha-uds-test-{Guid.NewGuid()}"); + protected override YetAnotherHttpHandler CreateHandler() + { + return new YetAnotherHttpHandler() + { + UnixDomainSocketPath = _udsPath, + Http2Only = true, + }; + } + + protected override Task LaunchServerAsyncCore(Action? configure = null) + { + return LaunchServerAsync(TestWebAppServerListenMode.SecureHttp2Only, builder => + { + builder.WebHost.ConfigureKestrel(options => + { + options.ListenUnixSocket(_udsPath, listenOptions => + { + listenOptions.Protocols = HttpProtocols.Http2; + }); + + // hyperlocal uses the 'unix' scheme and passes the URI to hyper. As a result, the ':scheme' header in the request is set to 'unix'. + // By default, Kestrel does not accept non-HTTP schemes. To allow non-HTTP schemes, we need to set 'AllowAlternateSchemes' to true. + options.AllowAlternateSchemes = true; + }); + + configure?.Invoke(builder); + }); + } +} \ No newline at end of file