Skip to content

Commit 0237675

Browse files
authored
fix: respect the relative path in base uri (#19)
* support relative path in baseUri * add tests * add test case
1 parent cfa28a8 commit 0237675

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/FeatBit.ServerSdk/Events/DefaultEventSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal partial class DefaultEventSender : IEventSender
1818
private static readonly TimeSpan DefaultTimeout = DefaultConnectTimeout + DefaultReadTimeout;
1919

2020
private readonly Uri _eventUri;
21-
private const string EventPath = "/api/public/insight/track";
21+
private const string EventPath = "api/public/insight/track";
2222
private readonly int _maxAttempts;
2323
private readonly TimeSpan _retryInterval;
2424

src/FeatBit.ServerSdk/Transport/FbWebSocket.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,8 @@ private WebSocketTransport DefaultWebSocketTransportFactory()
116116
private static Uri DefaultWebSocketUriResolver(FbOptions options)
117117
{
118118
var token = ConnectionToken.New(options.EnvSecret);
119-
var webSocketUri = new UriBuilder(options.StreamingUri)
120-
{
121-
Path = "streaming",
122-
Query = $"type=server&token={token}"
123-
}.Uri;
124-
125-
return webSocketUri;
119+
var websocketUri = new Uri(options.StreamingUri, $"streaming?type=server&token={token}");
120+
return websocketUri;
126121
}
127122

128123
private async Task ReceiveLoop()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace FeatBit.Sdk.Server;
2+
3+
public class UriTests
4+
{
5+
// According to the documentation: https://learn.microsoft.com/en-us/dotnet/api/system.uri.-ctor?view=net-6.0#system-uri-ctor(system-uri-system-string)
6+
// if the relative part of baseUri is to be preserved in the constructed Uri,
7+
// the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/)
8+
[Theory]
9+
[InlineData("https://contoso.com/featbit/", "relative", "https://contoso.com/featbit/relative")]
10+
[InlineData("https://contoso.com/featbit/", "/relative", "https://contoso.com/relative")]
11+
[InlineData("https://contoso.com/featbit/", "relative?type=server", "https://contoso.com/featbit/relative?type=server")]
12+
[InlineData("https://contoso.com", "relative", "https://contoso.com/relative")]
13+
[InlineData("https://contoso.com", "/relative", "https://contoso.com/relative")]
14+
[InlineData("https://contoso.com/", "/relative", "https://contoso.com/relative")]
15+
public void CreateUri(string @base, string relative, string expected)
16+
{
17+
var baseUri = new Uri(@base);
18+
var uri = new Uri(baseUri, relative);
19+
20+
Assert.Equal(expected, uri.ToString());
21+
}
22+
}

0 commit comments

Comments
 (0)