42
42
import okhttp3 .Request ;
43
43
import okhttp3 .RequestBody ;
44
44
import okhttp3 .Response ;
45
- import org .apache .commons .validator .routines .UrlValidator ;
46
45
import org .json .JSONException ;
47
46
import org .json .JSONObject ;
48
47
@@ -74,17 +73,14 @@ public class FirebaseFunctions {
74
73
private final String projectId ;
75
74
76
75
// The region to use for all function references.
77
- @ Nullable private final String region ;
76
+ private final String region ;
78
77
79
78
// A custom domain for the http trigger, such as "https://mydomain.com"
80
79
@ Nullable private final String customDomain ;
81
80
82
81
// The format to use for constructing urls from region, projectId, and name.
83
82
private String urlFormat = "https://%1$s-%2$s.cloudfunctions.net/%3$s" ;
84
83
85
- // Allowed custom domain protocols.
86
- private String [] customDomainSchemes = {"http" , "https" };
87
-
88
84
// Emulator settings
89
85
@ Nullable private EmulatedServiceSettings emulatorSettings ;
90
86
@@ -100,13 +96,20 @@ public class FirebaseFunctions {
100
96
this .contextProvider = Preconditions .checkNotNull (contextProvider );
101
97
this .projectId = Preconditions .checkNotNull (projectId );
102
98
103
- UrlValidator validator = new UrlValidator (customDomainSchemes );
104
- if (validator .isValid (regionOrCustomDomain )) {
105
- this .region = null ;
106
- this .customDomain = regionOrCustomDomain ;
107
- } else {
99
+ boolean isRegion ;
100
+ try {
101
+ new URL (regionOrCustomDomain );
102
+ isRegion = false ;
103
+ } catch (MalformedURLException malformedURLException ) {
104
+ isRegion = true ;
105
+ }
106
+
107
+ if (isRegion ) {
108
108
this .region = regionOrCustomDomain ;
109
109
this .customDomain = null ;
110
+ } else {
111
+ this .region = "us-central1" ;
112
+ this .customDomain = regionOrCustomDomain ;
110
113
}
111
114
112
115
maybeInstallProviders (context );
@@ -209,21 +212,22 @@ public HttpsCallableReference getHttpsCallable(@NonNull String name) {
209
212
*/
210
213
@ VisibleForTesting
211
214
URL getURL (String function ) {
212
- String str ;
213
- if (customDomain != null ) {
215
+ EmulatedServiceSettings emulatorSettings = this .emulatorSettings ;
216
+ if (emulatorSettings != null ) {
217
+ urlFormat =
218
+ "http://"
219
+ + emulatorSettings .getHost ()
220
+ + ":"
221
+ + emulatorSettings .getPort ()
222
+ + "/%2$s/%1$s/%3$s" ;
223
+ }
224
+
225
+ String str = String .format (urlFormat , region , projectId , function );
226
+
227
+ if (customDomain != null && emulatorSettings == null ) {
214
228
str = customDomain + "/" + function ;
215
- } else {
216
- EmulatedServiceSettings emulatorSettings = this .emulatorSettings ;
217
- if (emulatorSettings != null ) {
218
- urlFormat =
219
- "http://"
220
- + emulatorSettings .getHost ()
221
- + ":"
222
- + emulatorSettings .getPort ()
223
- + "/%2$s/%1$s/%3$s" ;
224
- }
225
- str = String .format (urlFormat , region , projectId , function );
226
229
}
230
+
227
231
try {
228
232
return new URL (str );
229
233
} catch (MalformedURLException mfe ) {
0 commit comments