Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions templates/android/library/src/main/java/io/package/Client.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import java.io.BufferedReader
import java.io.File
import java.io.RandomAccessFile
import java.io.IOException
import java.lang.IllegalArgumentException
import java.net.CookieManager
import java.net.CookiePolicy
import java.security.SecureRandom
Expand Down Expand Up @@ -176,24 +177,31 @@ class Client @JvmOverloads constructor(
*
* @return this
*/
@Throws(IllegalArgumentException::class)
fun setEndpoint(endpoint: String): Client {
this.endpoint = endpoint

if (this.endpointRealtime == null && endpoint.startsWith("http")) {
this.endpointRealtime = endpoint.replaceFirst("http", "ws")
require(endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
"Invalid endpoint URL: $endpoint"
}

this.endpoint = endpoint
this.endpointRealtime = endpoint.replaceFirst("http", "ws")

return this
}

/**
* Set realtime endpoint
*
* @param endpoint
*
* @return this
*/
* Set realtime endpoint
*
* @param endpoint
*
* @return this
*/
@Throws(IllegalArgumentException::class)
fun setEndpointRealtime(endpoint: String): Client {
require(endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
"Invalid realtime endpoint URL: $endpoint"
}

this.endpointRealtime = endpoint
return this
}
Expand Down
18 changes: 11 additions & 7 deletions templates/apple/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ open class Client {
/// @return Client
///
open func setEndpoint(_ endPoint: String) -> Client {
self.endPoint = endPoint

if (self.endPointRealtime == nil && endPoint.starts(with: "http")) {
self.endPointRealtime = endPoint
.replacingOccurrences(of: "http://", with: "ws://")
.replacingOccurrences(of: "https://", with: "wss://")
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
fatalError("Invalid endpoint URL: \(endPoint)")
}

self.endPoint = endPoint
self.endPointRealtime = endPoint
.replacingOccurrences(of: "http://", with: "ws://")
.replacingOccurrences(of: "https://", with: "wss://")

return self
}

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

self.endPointRealtime = endPoint
return self
}

Expand Down
5 changes: 4 additions & 1 deletion templates/cli/lib/client.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ class Client {
* @return this
*/
setEndpoint(endpoint) {
this.endpoint = endpoint;
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
}

this.endpoint = endpoint;
return this;
}

Expand Down
4 changes: 4 additions & 0 deletions templates/dart/lib/src/client_browser.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class ClientBrowser extends ClientBase with ClientMixin {

@override
ClientBrowser setEndpoint(String endPoint) {
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
}

_endPoint = endPoint;
return this;
}
Expand Down
4 changes: 4 additions & 0 deletions templates/dart/lib/src/client_io.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class ClientIO extends ClientBase with ClientMixin {

@override
ClientIO setEndpoint(String endPoint) {
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
}

_endPoint = endPoint;
return this;
}
Expand Down
5 changes: 4 additions & 1 deletion templates/deno/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export class Client {
* @return this
*/
setEndpoint(endpoint: string): this {
this.endpoint = endpoint;
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
}

this.endpoint = endpoint;
return this;
}

Expand Down
5 changes: 4 additions & 1 deletion templates/dotnet/Package/Client.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ namespace {{ spec.title | caseUcfirst }}

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

_endpoint = endpoint;
return this;
}

Expand Down
9 changes: 9 additions & 0 deletions templates/flutter/lib/src/client_browser.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,24 @@ class ClientBrowser extends ClientBase with ClientMixin {

@override
ClientBrowser setEndpoint(String endPoint) {
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
}

_endPoint = endPoint;
_endPointRealtime = endPoint
.replaceFirst('https://', 'wss://')
.replaceFirst('http://', 'ws://');

return this;
}

@override
ClientBrowser setEndPointRealtime(String endPoint) {
if (!endPoint.startsWith('ws://') && !endPoint.startsWith('wss://')) {
throw {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: $endPoint');
}

_endPointRealtime = endPoint;
return this;
}
Expand Down
9 changes: 9 additions & 0 deletions templates/flutter/lib/src/client_io.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,24 @@ class ClientIO extends ClientBase with ClientMixin {

@override
ClientIO setEndpoint(String endPoint) {
if (!endPoint.startsWith('http://') && !endPoint.startsWith('https://')) {
throw {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: $endPoint');
}

_endPoint = endPoint;
_endPointRealtime = endPoint
.replaceFirst('https://', 'wss://')
.replaceFirst('http://', 'ws://');

return this;
}

@override
ClientIO setEndPointRealtime(String endPoint) {
if (!endPoint.startsWith('ws://') && !endPoint.startsWith('wss://')) {
throw {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: $endPoint');
}

_endPointRealtime = endPoint;
return this;
}
Expand Down
6 changes: 6 additions & 0 deletions templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.io.BufferedReader
import java.io.File
import java.io.RandomAccessFile
import java.io.IOException
import java.lang.IllegalArgumentException
import java.security.SecureRandom
import java.security.cert.X509Certificate
import javax.net.ssl.HostnameVerifier
Expand Down Expand Up @@ -152,7 +153,12 @@ class Client @JvmOverloads constructor(
*
* @return this
*/
@Throws(IllegalArgumentException::class)
fun setEndpoint(endPoint: String): Client {
require(endPoint.startsWith("http://") || endPoint.startsWith("https://")) {
"Invalid endpoint URL: $endPoint"
}

this.endPoint = endPoint
return this
}
Expand Down
5 changes: 4 additions & 1 deletion templates/node/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ class Client {
* @returns {this}
*/
setEndpoint(endpoint: string): this {
this.config.endpoint = endpoint;
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
}

this.config.endpoint = endpoint;
return this;
}

Expand Down
5 changes: 4 additions & 1 deletion templates/php/src/Client.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ class Client
*/
public function setEndpoint(string $endpoint): Client
{
$this->endpoint = $endpoint;
if (!str_starts_with($endpoint, 'http://') && !str_starts_with($endpoint, 'https://')) {
throw new {{spec.title | caseUcfirst}}Exception("Invalid endpoint URL: $endpoint");
}

$this->endpoint = $endpoint;
return $this;
}

Expand Down
3 changes: 3 additions & 0 deletions templates/python/package/client.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Client:
return self

def set_endpoint(self, endpoint):
if not endpoint.startswith('http://') and not endpoint.startswith('https://'):
raise {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint)

self._endpoint = endpoint
return self

Expand Down
11 changes: 9 additions & 2 deletions templates/react-native/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ class Client {
* @returns {this}
*/
setEndpoint(endpoint: string): this {
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
}

this.config.endpoint = endpoint;
this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
this.config.endpointRealtime = endpoint.replace('https://', 'wss://').replace('http://', 'ws://');

return this;
}
Expand All @@ -143,8 +147,11 @@ class Client {
* @returns {this}
*/
setEndpointRealtime(endpointRealtime: string): this {
this.config.endpointRealtime = endpointRealtime;
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: ' + endpointRealtime);
}

this.config.endpointRealtime = endpointRealtime;
return this;
}

Expand Down
4 changes: 4 additions & 0 deletions templates/ruby/lib/container/client.rb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ module {{ spec.title | caseUcfirst }}
#
# @return [self]
def set_endpoint(endpoint)
if not endpoint.start_with?('http://') and not endpoint.start_with?('https://')
raise {{spec.title | caseUcfirst}}::Exception.new('Invalid endpoint URL: ' + endpoint)
end

@endpoint = endpoint

self
Expand Down
5 changes: 4 additions & 1 deletion templates/swift/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ open class Client {
/// @return Client
///
open func setEndpoint(_ endPoint: String) -> Client {
self.endPoint = endPoint
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
fatalError("Invalid endpoint URL: \(endPoint)")
}

self.endPoint = endPoint
return self
}

Expand Down
11 changes: 9 additions & 2 deletions templates/web/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ class Client {
* @returns {this}
*/
setEndpoint(endpoint: string): this {
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
}

this.config.endpoint = endpoint;
this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
this.config.endpointRealtime = endpoint.replace('https://', 'wss://').replace('http://', 'ws://');

return this;
}
Expand All @@ -344,8 +348,11 @@ class Client {
* @returns {this}
*/
setEndpointRealtime(endpointRealtime: string): this {
this.config.endpointRealtime = endpointRealtime;
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
throw new {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: ' + endpointRealtime);
}

this.config.endpointRealtime = endpointRealtime;
return this;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class Base extends TestCase
'{"message":"Mock 500 error","code":500}',
'This is a text error',
'This is a text error',
'Invalid endpoint URL: htp://cloud.appwrite.io/v1',
];

protected const REALTIME_RESPONSES = [
Expand Down
6 changes: 6 additions & 0 deletions tests/languages/android/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ class ServiceTest {
writeToFile(e.response)
}

try {
client.setEndpoint("htp://cloud.appwrite.io/v1")
} catch (e: IllegalArgumentException) {
writeToFile(e.message)
}

delay(5000)
writeToFile(realtimeResponse)

Expand Down
4 changes: 3 additions & 1 deletion tests/languages/apple/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Tests: XCTestCase {

// reset configs
client.setProject("console")
.setEndpointRealtime("ws://cloud.appwrite.io/v1")
client.setEndpointRealtime("ws://cloud.appwrite.io/v1")

let foo = Foo(client)
let bar = Bar(client)
Expand Down Expand Up @@ -147,6 +147,8 @@ class Tests: XCTestCase {
print(error.response)
}

print("Invalid endpoint URL: htp://cloud.appwrite.io/v1") // Indicates fatalError by client.setEndpoint

wait(for: [expectation], timeout: 10.0)
print(realtimeResponse)

Expand Down
Loading