25
25
import com .google .common .annotations .VisibleForTesting ;
26
26
import com .google .common .base .Strings ;
27
27
import com .google .common .collect .ImmutableMap ;
28
- import com .google .firebase .ErrorCode ;
29
28
import com .google .firebase .FirebaseApp ;
30
29
import com .google .firebase .FirebaseException ;
31
30
import com .google .firebase .ImplFirebaseTrampolines ;
38
37
import com .google .firebase .remoteconfig .internal .RemoteConfigServiceErrorResponse ;
39
38
40
39
import java .io .IOException ;
41
- import java .util .ArrayList ;
42
40
import java .util .List ;
43
41
import java .util .Map ;
44
42
47
45
*/
48
46
final class FirebaseRemoteConfigClientImpl implements FirebaseRemoteConfigClient {
49
47
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" ;
51
49
52
50
private static final Map <String , String > COMMON_HEADERS =
53
51
ImmutableMap .of (
54
52
"X-GOOG-API-FORMAT-VERSION" , "2" ,
55
53
"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
56
58
"Accept-Encoding" , "gzip"
57
59
);
58
60
59
- private final String rcSendUrl ;
61
+ private final String remoteConfigUrl ;
60
62
private final HttpRequestFactory requestFactory ;
61
- private final HttpRequestFactory childRequestFactory ;
62
63
private final JsonFactory jsonFactory ;
63
64
private final ErrorHandlingHttpClient <FirebaseRemoteConfigException > httpClient ;
64
65
65
66
private FirebaseRemoteConfigClientImpl (Builder builder ) {
66
67
checkArgument (!Strings .isNullOrEmpty (builder .projectId ));
67
- this .rcSendUrl = String .format (RC_URL , builder .projectId );
68
+ this .remoteConfigUrl = String .format (REMOTE_CONFIG_URL , builder .projectId );
68
69
this .requestFactory = checkNotNull (builder .requestFactory );
69
- this .childRequestFactory = checkNotNull (builder .childRequestFactory );
70
70
this .jsonFactory = checkNotNull (builder .jsonFactory );
71
71
HttpResponseInterceptor responseInterceptor = builder .responseInterceptor ;
72
72
RemoteConfigErrorHandler errorHandler = new RemoteConfigErrorHandler (this .jsonFactory );
@@ -75,49 +75,34 @@ private FirebaseRemoteConfigClientImpl(Builder builder) {
75
75
}
76
76
77
77
@ VisibleForTesting
78
- String getRcSendUrl () {
79
- return rcSendUrl ;
78
+ String getRemoteConfigUrl () {
79
+ return remoteConfigUrl ;
80
80
}
81
81
82
82
@ VisibleForTesting
83
83
HttpRequestFactory getRequestFactory () {
84
84
return requestFactory ;
85
85
}
86
86
87
- @ VisibleForTesting
88
- HttpRequestFactory getChildRequestFactory () {
89
- return childRequestFactory ;
90
- }
91
-
92
87
@ VisibleForTesting
93
88
JsonFactory getJsonFactory () {
94
89
return jsonFactory ;
95
90
}
96
91
97
92
@ Override
98
93
public RemoteConfigTemplate getTemplate () throws FirebaseRemoteConfigException {
99
- HttpRequestInfo request = HttpRequestInfo .buildGetRequest (rcSendUrl )
94
+ HttpRequestInfo request = HttpRequestInfo .buildGetRequest (remoteConfigUrl )
100
95
.addAllHeaders (COMMON_HEADERS );
101
96
IncomingHttpResponse response = httpClient .send (request );
102
97
RemoteConfigTemplate parsed = httpClient .parse (response , RemoteConfigTemplate .class );
103
98
104
99
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." );
112
102
113
103
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." );
121
106
122
107
parsed .setETag (etag );
123
108
return parsed ;
@@ -133,7 +118,6 @@ static FirebaseRemoteConfigClientImpl fromApp(FirebaseApp app) {
133
118
return FirebaseRemoteConfigClientImpl .builder ()
134
119
.setProjectId (projectId )
135
120
.setRequestFactory (ApiClientUtils .newAuthorizedRequestFactory (app ))
136
- .setChildRequestFactory (ApiClientUtils .newUnauthorizedRequestFactory (app ))
137
121
.setJsonFactory (app .getOptions ().getJsonFactory ())
138
122
.build ();
139
123
}
@@ -146,7 +130,6 @@ static final class Builder {
146
130
147
131
private String projectId ;
148
132
private HttpRequestFactory requestFactory ;
149
- private HttpRequestFactory childRequestFactory ;
150
133
private JsonFactory jsonFactory ;
151
134
private HttpResponseInterceptor responseInterceptor ;
152
135
@@ -162,12 +145,6 @@ Builder setRequestFactory(HttpRequestFactory requestFactory) {
162
145
return this ;
163
146
}
164
147
165
- Builder setChildRequestFactory (
166
- HttpRequestFactory childRequestFactory ) {
167
- this .childRequestFactory = childRequestFactory ;
168
- return this ;
169
- }
170
-
171
148
Builder setJsonFactory (JsonFactory jsonFactory ) {
172
149
this .jsonFactory = jsonFactory ;
173
150
return this ;
0 commit comments