Skip to content

Commit 43a9e43

Browse files
authored
Fix FIRFunctions.useEmulatorWithHost scheme (#7545)
1 parent 1af5002 commit 43a9e43

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Functions/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [fixed] Fixed missing "http://" prefix when using Functions with the emulator. (#7537, #7538)
3+
14
# v7.2.0
25
- [added] Made emulator connection API consistent between Auth, Database, Firestore, and Functions (#5916).
36

Functions/Example/Tests/FIRFunctionsTests.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ - (void)testRegionWithEmulator {
6060
[_functionsCustomDomain useEmulatorWithHost:@"localhost" port:5005];
6161
NSLog(@"%@", _functionsCustomDomain.emulatorOrigin);
6262
NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
63-
XCTAssertEqualObjects(@"localhost:5005/my-project/my-region/my-endpoint", url);
63+
XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
64+
}
65+
66+
- (void)testRegionWithEmulatorWithScheme {
67+
[_functionsCustomDomain useEmulatorWithHost:@"http://localhost" port:5005];
68+
NSLog(@"%@", _functionsCustomDomain.emulatorOrigin);
69+
NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
70+
XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
6471
}
6572

6673
- (void)testCustomDomain {
@@ -71,12 +78,12 @@ - (void)testCustomDomain {
7178
- (void)testCustomDomainWithEmulator {
7279
[_functionsCustomDomain useEmulatorWithHost:@"localhost" port:5005];
7380
NSString *url = [_functionsCustomDomain URLWithName:@"my-endpoint"];
74-
XCTAssertEqualObjects(@"localhost:5005/my-project/my-region/my-endpoint", url);
81+
XCTAssertEqualObjects(@"http://localhost:5005/my-project/my-region/my-endpoint", url);
7582
}
7683

7784
- (void)testSetEmulatorSettings {
7885
[_functions useEmulatorWithHost:@"localhost" port:1000];
79-
XCTAssertEqualObjects(@"localhost:1000", _functions.emulatorOrigin);
86+
XCTAssertEqualObjects(@"http://localhost:1000", _functions.emulatorOrigin);
8087
}
8188

8289
@end

Functions/FirebaseFunctions/FIRFunctions.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ - (instancetype)initWithProjectID:(NSString *)projectID
149149
}
150150

151151
- (void)useLocalhost {
152-
[self useEmulatorWithHost:@"http://localhost" port:5005];
152+
[self useEmulatorWithHost:@"localhost" port:5005];
153153
}
154154

155155
- (void)useEmulatorWithHost:(NSString *)host port:(NSInteger)port {
156156
NSAssert(host.length > 0, @"Cannot connect to nil or empty host");
157-
NSString *origin = [NSString stringWithFormat:@"%@:%li", host, (long)port];
157+
NSString *prefix = [host hasPrefix:@"http"] ? @"" : @"http://";
158+
NSString *origin = [NSString stringWithFormat:@"%@%@:%li", prefix, host, (long)port];
158159
_emulatorOrigin = origin;
159160
}
160161

0 commit comments

Comments
 (0)