@@ -25,6 +25,7 @@ import java.io.BufferedReader
2525import java.io.File
2626import java.io.RandomAccessFile
2727import java.io.IOException
28+ import java.lang.IllegalArgumentException
2829import java.net.CookieManager
2930import java.net.CookiePolicy
3031import java.security.SecureRandom
@@ -176,24 +177,31 @@ class Client @JvmOverloads constructor(
176177 *
177178 * @return this
178179 */
180+ @Throws(IllegalArgumentException::class)
179181 fun setEndpoint(endpoint: String): Client {
180- this.endpoint = endpoint
181-
182- if (this.endpointRealtime == null && endpoint.startsWith("http")) {
183- this.endpointRealtime = endpoint.replaceFirst("http", "ws")
182+ require(endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
183+ "Invalid endpoint URL: $endpoint"
184184 }
185185
186+ this.endpoint = endpoint
187+ this.endpointRealtime = endpoint.replaceFirst("http", "ws")
188+
186189 return this
187190 }
188191
189192 /**
190- * Set realtime endpoint
191- *
192- * @param endpoint
193- *
194- * @return this
195- */
193+ * Set realtime endpoint
194+ *
195+ * @param endpoint
196+ *
197+ * @return this
198+ */
199+ @Throws(IllegalArgumentException::class)
196200 fun setEndpointRealtime(endpoint: String): Client {
201+ require(endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
202+ "Invalid realtime endpoint URL: $endpoint"
203+ }
204+
197205 this.endpointRealtime = endpoint
198206 return this
199207 }
0 commit comments