Skip to content

Commit 0ec5f4a

Browse files
Merge pull request #1057 from appwrite/pla-2706
chore: update setting of realtime endpoint
2 parents d34efe8 + 7f1de24 commit 0ec5f4a

File tree

33 files changed

+203
-44
lines changed

33 files changed

+203
-44
lines changed

templates/android/library/src/main/java/io/package/Client.kt.twig

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import java.io.BufferedReader
2525
import java.io.File
2626
import java.io.RandomAccessFile
2727
import java.io.IOException
28+
import java.lang.IllegalArgumentException
2829
import java.net.CookieManager
2930
import java.net.CookiePolicy
3031
import 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
}

templates/apple/Sources/Client.swift.twig

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ open class Client {
135135
/// @return Client
136136
///
137137
open func setEndpoint(_ endPoint: String) -> Client {
138-
self.endPoint = endPoint
139-
140-
if (self.endPointRealtime == nil && endPoint.starts(with: "http")) {
141-
self.endPointRealtime = endPoint
142-
.replacingOccurrences(of: "http://", with: "ws://")
143-
.replacingOccurrences(of: "https://", with: "wss://")
138+
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
139+
fatalError("Invalid endpoint URL: \(endPoint)")
144140
}
145141

142+
self.endPoint = endPoint
143+
self.endPointRealtime = endPoint
144+
.replacingOccurrences(of: "http://", with: "ws://")
145+
.replacingOccurrences(of: "https://", with: "wss://")
146+
146147
return self
147148
}
148149

@@ -154,8 +155,11 @@ open class Client {
154155
/// @return Client
155156
///
156157
open func setEndpointRealtime(_ endPoint: String) -> Client {
157-
self.endPointRealtime = endPoint
158+
if !endPoint.hasPrefix("ws://") && !endPoint.hasPrefix("wss://") {
159+
fatalError("Invalid realtime endpoint URL: \(endPoint)")
160+
}
158161

162+
self.endPointRealtime = endPoint
159163
return self
160164
}
161165

templates/cli/lib/client.js.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ class Client {
7979
* @return this
8080
*/
8181
setEndpoint(endpoint) {
82-
this.endpoint = endpoint;
82+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
83+
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
84+
}
8385

86+
this.endpoint = endpoint;
8487
return this;
8588
}
8689

templates/dart/lib/src/client_browser.dart.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ClientBrowser extends ClientBase with ClientMixin {
6767

6868
@override
6969
ClientBrowser setEndpoint(String endPoint) {
70+
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
71+
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
72+
}
73+
7074
_endPoint = endPoint;
7175
return this;
7276
}

templates/dart/lib/src/client_io.dart.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class ClientIO extends ClientBase with ClientMixin {
7979

8080
@override
8181
ClientIO setEndpoint(String endPoint) {
82+
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
83+
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
84+
}
85+
8286
_endPoint = endPoint;
8387
return this;
8488
}

templates/deno/src/client.ts.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ export class Client {
4646
* @return this
4747
*/
4848
setEndpoint(endpoint: string): this {
49-
this.endpoint = endpoint;
49+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
50+
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
51+
}
5052

53+
this.endpoint = endpoint;
5154
return this;
5255
}
5356

templates/dotnet/Package/Client.cs.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ namespace {{ spec.title | caseUcfirst }}
106106

107107
public Client SetEndpoint(string endpoint)
108108
{
109-
_endpoint = endpoint;
109+
if (!endpoint.StartsWith("http://") && !endpoint.StartsWith("https://")) {
110+
throw new {{spec.title | caseUcfirst}}Exception("Invalid endpoint URL: " + endpoint);
111+
}
110112

113+
_endpoint = endpoint;
111114
return this;
112115
}
113116

templates/flutter/lib/src/client_browser.dart.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,24 @@ class ClientBrowser extends ClientBase with ClientMixin {
7878

7979
@override
8080
ClientBrowser setEndpoint(String endPoint) {
81+
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
82+
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
83+
}
84+
8185
_endPoint = endPoint;
8286
_endPointRealtime = endPoint
8387
.replaceFirst('https://', 'wss://')
8488
.replaceFirst('http://', 'ws://');
89+
8590
return this;
8691
}
8792

8893
@override
8994
ClientBrowser setEndPointRealtime(String endPoint) {
95+
if (!endPoint.startsWith('ws://') && !endPoint.startsWith('wss://')) {
96+
throw {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: $endPoint');
97+
}
98+
9099
_endPointRealtime = endPoint;
91100
return this;
92101
}

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,24 @@ class ClientIO extends ClientBase with ClientMixin {
110110

111111
@override
112112
ClientIO setEndpoint(String endPoint) {
113+
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
114+
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
115+
}
116+
113117
_endPoint = endPoint;
114118
_endPointRealtime = endPoint
115119
.replaceFirst('https://', 'wss://')
116120
.replaceFirst('http://', 'ws://');
121+
117122
return this;
118123
}
119124

120125
@override
121126
ClientIO setEndPointRealtime(String endPoint) {
127+
if (!endPoint.startsWith('ws://') && !endPoint.startsWith('wss://')) {
128+
throw {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: $endPoint');
129+
}
130+
122131
_endPointRealtime = endPoint;
123132
return this;
124133
}

templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.io.BufferedReader
2121
import java.io.File
2222
import java.io.RandomAccessFile
2323
import java.io.IOException
24+
import java.lang.IllegalArgumentException
2425
import java.security.SecureRandom
2526
import java.security.cert.X509Certificate
2627
import javax.net.ssl.HostnameVerifier
@@ -152,7 +153,12 @@ class Client @JvmOverloads constructor(
152153
*
153154
* @return this
154155
*/
156+
@Throws(IllegalArgumentException::class)
155157
fun setEndpoint(endPoint: String): Client {
158+
require(endPoint.startsWith("http://") || endPoint.startsWith("https://")) {
159+
"Invalid endpoint URL: $endPoint"
160+
}
161+
156162
this.endPoint = endPoint
157163
return this
158164
}

0 commit comments

Comments
 (0)