-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestWebAppServer> LaunchServerAsyncCore<T>(Action<WebApplicationBuilder>? configure = null) | ||
{ | ||
return LaunchServerAsync<T>(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); | ||
}); | ||
} | ||
} |