Skip to content

Commit 71151f8

Browse files
committed
PR fixes
1 parent c13d889 commit 71151f8

File tree

4 files changed

+42
-138
lines changed

4 files changed

+42
-138
lines changed

src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImpl.java

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.google.common.annotations.VisibleForTesting;
2626
import com.google.common.base.Strings;
2727
import com.google.common.collect.ImmutableMap;
28-
import com.google.firebase.ErrorCode;
2928
import com.google.firebase.FirebaseApp;
3029
import com.google.firebase.FirebaseException;
3130
import com.google.firebase.ImplFirebaseTrampolines;
@@ -38,7 +37,6 @@
3837
import com.google.firebase.remoteconfig.internal.RemoteConfigServiceErrorResponse;
3938

4039
import java.io.IOException;
41-
import java.util.ArrayList;
4240
import java.util.List;
4341
import java.util.Map;
4442

@@ -47,26 +45,28 @@
4745
*/
4846
final class FirebaseRemoteConfigClientImpl implements FirebaseRemoteConfigClient {
4947

50-
private static final String RC_URL = "https://firebaseremoteconfig.googleapis.com/v1/projects/%s/remoteConfig";
48+
private static final String REMOTE_CONFIG_URL = "https://firebaseremoteconfig.googleapis.com/v1/projects/%s/remoteConfig";
5149

5250
private static final Map<String, String> COMMON_HEADERS =
5351
ImmutableMap.of(
5452
"X-GOOG-API-FORMAT-VERSION", "2",
5553
"X-Firebase-Client", "fire-admin-java/" + SdkUtils.getVersion(),
54+
// There is a known issue in which the ETag is not properly returned in cases
55+
// where the request does not specify a compression type. Currently, it is
56+
// required to include the header `Accept-Encoding: gzip` or equivalent in all
57+
// requests. https://firebase.google.com/docs/remote-config/use-config-rest#etag_usage_and_forced_updates
5658
"Accept-Encoding", "gzip"
5759
);
5860

59-
private final String rcSendUrl;
61+
private final String remoteConfigUrl;
6062
private final HttpRequestFactory requestFactory;
61-
private final HttpRequestFactory childRequestFactory;
6263
private final JsonFactory jsonFactory;
6364
private final ErrorHandlingHttpClient<FirebaseRemoteConfigException> httpClient;
6465

6566
private FirebaseRemoteConfigClientImpl(Builder builder) {
6667
checkArgument(!Strings.isNullOrEmpty(builder.projectId));
67-
this.rcSendUrl = String.format(RC_URL, builder.projectId);
68+
this.remoteConfigUrl = String.format(REMOTE_CONFIG_URL, builder.projectId);
6869
this.requestFactory = checkNotNull(builder.requestFactory);
69-
this.childRequestFactory = checkNotNull(builder.childRequestFactory);
7070
this.jsonFactory = checkNotNull(builder.jsonFactory);
7171
HttpResponseInterceptor responseInterceptor = builder.responseInterceptor;
7272
RemoteConfigErrorHandler errorHandler = new RemoteConfigErrorHandler(this.jsonFactory);
@@ -75,49 +75,34 @@ private FirebaseRemoteConfigClientImpl(Builder builder) {
7575
}
7676

7777
@VisibleForTesting
78-
String getRcSendUrl() {
79-
return rcSendUrl;
78+
String getRemoteConfigUrl() {
79+
return remoteConfigUrl;
8080
}
8181

8282
@VisibleForTesting
8383
HttpRequestFactory getRequestFactory() {
8484
return requestFactory;
8585
}
8686

87-
@VisibleForTesting
88-
HttpRequestFactory getChildRequestFactory() {
89-
return childRequestFactory;
90-
}
91-
9287
@VisibleForTesting
9388
JsonFactory getJsonFactory() {
9489
return jsonFactory;
9590
}
9691

9792
@Override
9893
public RemoteConfigTemplate getTemplate() throws FirebaseRemoteConfigException {
99-
HttpRequestInfo request = HttpRequestInfo.buildGetRequest(rcSendUrl)
94+
HttpRequestInfo request = HttpRequestInfo.buildGetRequest(remoteConfigUrl)
10095
.addAllHeaders(COMMON_HEADERS);
10196
IncomingHttpResponse response = httpClient.send(request);
10297
RemoteConfigTemplate parsed = httpClient.parse(response, RemoteConfigTemplate.class);
10398

10499
List<String> etagList = (List<String>) response.getHeaders().get("etag");
105-
106-
if (etagList == null || etagList.isEmpty()) {
107-
throw new FirebaseRemoteConfigException(
108-
ErrorCode.INTERNAL,
109-
"ETag header is not available in the server response.", null, null,
110-
RemoteConfigErrorCode.INTERNAL);
111-
}
100+
checkArgument(!(etagList == null || etagList.isEmpty()),
101+
"ETag header is not available in the server response.");
112102

113103
String etag = etagList.get(0);
114-
115-
if (Strings.isNullOrEmpty(etag)) {
116-
throw new FirebaseRemoteConfigException(
117-
ErrorCode.INTERNAL,
118-
"ETag header is not available in the server response.", null, null,
119-
RemoteConfigErrorCode.INTERNAL);
120-
}
104+
checkArgument(!Strings.isNullOrEmpty(etag),
105+
"ETag header is not available in the server response.");
121106

122107
parsed.setETag(etag);
123108
return parsed;
@@ -133,7 +118,6 @@ static FirebaseRemoteConfigClientImpl fromApp(FirebaseApp app) {
133118
return FirebaseRemoteConfigClientImpl.builder()
134119
.setProjectId(projectId)
135120
.setRequestFactory(ApiClientUtils.newAuthorizedRequestFactory(app))
136-
.setChildRequestFactory(ApiClientUtils.newUnauthorizedRequestFactory(app))
137121
.setJsonFactory(app.getOptions().getJsonFactory())
138122
.build();
139123
}
@@ -146,7 +130,6 @@ static final class Builder {
146130

147131
private String projectId;
148132
private HttpRequestFactory requestFactory;
149-
private HttpRequestFactory childRequestFactory;
150133
private JsonFactory jsonFactory;
151134
private HttpResponseInterceptor responseInterceptor;
152135

@@ -162,12 +145,6 @@ Builder setRequestFactory(HttpRequestFactory requestFactory) {
162145
return this;
163146
}
164147

165-
Builder setChildRequestFactory(
166-
HttpRequestFactory childRequestFactory) {
167-
this.childRequestFactory = childRequestFactory;
168-
return this;
169-
}
170-
171148
Builder setJsonFactory(JsonFactory jsonFactory) {
172149
this.jsonFactory = jsonFactory;
173150
return this;

src/main/java/com/google/firebase/remoteconfig/RemoteConfigTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.google.api.client.util.Key;
2020

21-
public class RemoteConfigTemplate {
21+
public final class RemoteConfigTemplate {
2222

2323
@Key("etag")
2424
private String etag;

src/main/java/com/google/firebase/remoteconfig/internal/RemoteConfigServiceErrorResponse.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* These error messages take the form,
3131
* `"error": {"code": 123, "message": "[CODE]: Message Details", "status": "ERROR_STATUS"}`
3232
*/
33-
public class RemoteConfigServiceErrorResponse extends GenericJson {
33+
public final class RemoteConfigServiceErrorResponse extends GenericJson {
3434

3535
private static final Map<String, RemoteConfigErrorCode> RC_ERROR_CODES =
3636
ImmutableMap.<String, RemoteConfigErrorCode>builder()
@@ -55,7 +55,7 @@ public RemoteConfigErrorCode getRemoteConfigErrorCode() {
5555
return null;
5656
}
5757

58-
String message = getErrorMessage();
58+
String message = (String) error.get("message");
5959
if (Strings.isNullOrEmpty(message)) {
6060
return null;
6161
}
@@ -68,13 +68,4 @@ public RemoteConfigErrorCode getRemoteConfigErrorCode() {
6868

6969
return null;
7070
}
71-
72-
@Nullable
73-
public String getErrorMessage() {
74-
if (error == null) {
75-
return null;
76-
}
77-
78-
return (String) error.get("message");
79-
}
8071
}

0 commit comments

Comments
 (0)