Skip to content

Commit

Permalink
🚸 automatically add /rpc suffix for ws protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Dec 9, 2024
1 parent c959e9d commit 583cc10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions SurrealDb.Net.Tests/ConstructorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public void ShouldSupportWssProtocol()
func().AbsoluteUri.Should().Be("wss://cloud.surrealdb.com/rpc");
}

[Theory]
[InlineData("ws://127.0.0.1:8000", "ws://127.0.0.1:8000/rpc")]
[InlineData("wss://cloud.SurrealDb.com", "wss://cloud.surrealdb.com/rpc")]
[InlineData("ws://127.0.0.1:8000/", "ws://127.0.0.1:8000/rpc")]
[InlineData("wss://cloud.SurrealDb.com/", "wss://cloud.surrealdb.com/rpc")]
public void ShouldAutomaticallyAddRpcSuffixForWsProtocols(string endpoint, string expected)
{
Func<Uri> func = () => new SurrealDbClient(endpoint).Uri;

func.Should().NotThrow();
func().AbsoluteUri.Should().Be(expected);
}

[Fact]
public void ShouldRequireDependencyInjectionForMemoryProtocol()
{
Expand Down
5 changes: 5 additions & 0 deletions SurrealDb.Net/SurrealDbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ internal SurrealDbClient(
throw new ArgumentNullException(nameof(configuration), "The endpoint is required.");

Uri = new Uri(configuration.Endpoint);
if (Uri.Scheme is "ws" or "wss")
{
Uri = new Uri(Uri, "/rpc");
}

NamingPolicy = configuration.NamingPolicy;

var protocol = Uri.Scheme;
Expand Down

0 comments on commit 583cc10

Please sign in to comment.