Skip to content

Commit

Permalink
Merge pull request #110 from Cysharp/feature/ThrowUDSNotSupportedOnWi…
Browse files Browse the repository at this point in the history
…ndows

Throw PlatformNotSupportedException when trying to use UDS on Windows
  • Loading branch information
mayuki authored Dec 19, 2024
2 parents 940d96d + a8e6fc5 commit 8e999b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/YetAnotherHttpHandler/NativeHttpHandlerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ private unsafe void Initialize(YahaNativeContext* ctx, NativeClientSettings sett
if (settings.UnixDomainSocketPath is { } unixDomainSocketPath)
{
if (YahaEventSource.Log.IsEnabled()) YahaEventSource.Log.Info($"Option '{nameof(settings.UnixDomainSocketPath)}' = {unixDomainSocketPath}");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
throw new PlatformNotSupportedException("Unix domain socket is not supported on Windows.");
}
var strBytes = Encoding.UTF8.GetBytes(unixDomainSocketPath);
fixed (byte* buffer = strBytes)
{
Expand Down
21 changes: 21 additions & 0 deletions test/YetAnotherHttpHandler.Test/UdsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,25 @@ protected override Task<TestWebAppServer> LaunchServerAsyncCore<T>(Action<WebApp
configure?.Invoke(builder);
});
}
}

[OSSkipCondition(OperatingSystems.MacOSX | OperatingSystems.Linux)]
public class UdsNotSupportedTest
{
[ConditionalFact]
public async Task Throw()
{
// Arrange
var handler = new YetAnotherHttpHandler()
{
UnixDomainSocketPath = "/path/to/socket",
};
var httpClient = new HttpClient(handler);

// Act & Assert
await Assert.ThrowsAsync<PlatformNotSupportedException>(async () =>
{
await httpClient.GetAsync("http://localhost/");
});
}
}

0 comments on commit 8e999b4

Please sign in to comment.