@Test public void fetch_setsAllHeaders_sendsAllHeadersToServer() throws Exception { setServerResponseTo(noChangeResponseBody, SECOND_ETAG); Map<String, String> customHeaders = ImmutableMap.of("x-enable-fetch", "true"); Map<String, String> expectedHeaders = new HashMap<>(); expectedHeaders.put("If-None-Match", FIRST_ETAG); expectedHeaders.put("X-Goog-Api-Key", API_KEY); expectedHeaders.put("X-Android-Package", context.getPackageName()); expectedHeaders.put("X-Android-Cert", null); expectedHeaders.put("X-Google-GFE-Can-Retry", "yes"); expectedHeaders.put("X-Goog-Firebase-Installations-Auth", INSTALLATION_AUTH_TOKEN_STRING); expectedHeaders.put("Content-Type", "application/json"); expectedHeaders.put("Accept", "application/json"); expectedHeaders.putAll(customHeaders); fetch(FIRST_ETAG, ImmutableMap.of(), customHeaders); assertThat(fakeHttpURLConnection.getRequestHeaders()).isEqualTo(expectedHeaders); }
@Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } ConfigFetchHttpClient(
      Context context,
      String appId,
      String apiKey,
      String namespace,
      long connectTimeoutInSeconds,
      long readTimeoutInSeconds); }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } ConfigFetchHttpClient(
      Context context,
      String appId,
      String apiKey,
      String namespace,
      long connectTimeoutInSeconds,
      long readTimeoutInSeconds); @VisibleForTesting long getConnectTimeoutInSeconds(); @VisibleForTesting long getReadTimeoutInSeconds(); }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } ConfigFetchHttpClient(
      Context context,
      String appId,
      String apiKey,
      String namespace,
      long connectTimeoutInSeconds,
      long readTimeoutInSeconds); @VisibleForTesting long getConnectTimeoutInSeconds(); @VisibleForTesting long getReadTimeoutInSeconds();  }