Skip to content

Commit 1b9d998

Browse files
committed
#184 allow additional path on final WebSocket as well.
1 parent 3adecf7 commit 1b9d998

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

Assets/Colyseus/Runtime/Scripts/ColyseusRequest.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public async Task<string> Request(string uriMethod, string uriPath, string uriQu
2929
{
3030
req.method = uriMethod;
3131
req.url = GetWebRequestURL(uriPath, uriQuery);
32+
3233
// Send JSON on request body
3334
if (data != null)
3435
{
@@ -132,22 +133,28 @@ public async Task<string> Request(string uriMethod, string uriPath, Dictionary<s
132133
};
133134
}
134135

135-
private string GetWebRequestURL(string path, string query = "")
136-
{
137-
string forwardSlash = "";
136+
public UriBuilder GetUriBuilder(string path, string query = "")
137+
{
138+
string forwardSlash = "";
139+
140+
if (!_serverSettings.WebRequestEndpoint.EndsWith("/"))
141+
{
142+
forwardSlash = "/";
143+
}
138144

139-
if (!_serverSettings.WebRequestEndpoint.EndsWith("/"))
140-
{
141-
forwardSlash = "/";
142-
}
145+
// WebRequestEndpoint will include any path that is included with the server address field of the server settings object so we need to add the request specific path to the WebRequestEndpoint value
146+
UriBuilder uriBuilder = new UriBuilder($"{_serverSettings.WebRequestEndpoint}{forwardSlash}{path}");
143147

144-
// WebRequestEndpoint will include any path that is included with the server address field of the server settings object so we need to add the request specific path to the WebRequestEndpoint value
145-
UriBuilder uriBuilder = new UriBuilder($"{_serverSettings.WebRequestEndpoint}{forwardSlash}{path}");
148+
uriBuilder.Port = _serverSettings.DetermineServerPort();
149+
uriBuilder.Query = query;
146150

147-
uriBuilder.Port = _serverSettings.DetermineServerPort();
148-
uriBuilder.Query = query;
151+
return uriBuilder;
152+
}
153+
154+
private string GetWebRequestURL(string path, string query = "")
155+
{
149156

150-
return uriBuilder.ToString();
157+
return GetUriBuilder(path, query).ToString();
151158
}
152159
}
153160
}

Assets/Colyseus/Runtime/Scripts/Models/ColyseusClient.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,8 @@ protected ColyseusConnection CreateConnection(string path = "", Dictionary<strin
389389
list.Add(item.Key + "=" + (item.Value != null ? Convert.ToString(item.Value) : "null"));
390390
}
391391

392-
UriBuilder uriBuilder = new UriBuilder(Endpoint.Uri)
393-
{
394-
Path = path,
395-
Query = string.Join("&", list.ToArray())
396-
};
392+
var uriBuilder = colyseusRequest.GetUriBuilder(path, string.Join("&", list.ToArray()));
393+
uriBuilder.Scheme = Endpoint.Scheme;
397394

398395
return new ColyseusConnection(uriBuilder.ToString(), headers);
399396
}

0 commit comments

Comments
 (0)