Skip to content

Commit cf00a83

Browse files
committed
Use gzip encoding to publish and get template.
Change-Id: I24a568576a4949756a1152562db14696e22264a6
1 parent 7fd04a8 commit cf00a83

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

config/src/main/java/com/google/firebase/samples/config/Configure.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.net.URL;
1818
import java.util.Collections;
1919
import java.util.Scanner;
20+
import java.util.zip.GZIPInputStream;
21+
import java.util.zip.GZIPOutputStream;
2022

2123
/**
2224
* Retrieve and publish templates for Firebase Remote Config using the REST API.
@@ -51,10 +53,12 @@ private static String getAccessToken() throws IOException {
5153
private static void getTemplate() throws IOException {
5254
HttpURLConnection httpURLConnection = getCommonConnection();
5355
httpURLConnection.setRequestMethod("GET");
56+
httpURLConnection.setRequestProperty("Accept-Encoding", "gzip");
5457

5558
int code = httpURLConnection.getResponseCode();
5659
if (code == 200) {
57-
String response = inputstreamToString(httpURLConnection.getInputStream());
60+
InputStream inputStream = new GZIPInputStream(httpURLConnection.getInputStream());
61+
String response = inputstreamToString(inputStream);
5862

5963
JsonParser jsonParser = new JsonParser();
6064
JsonElement jsonElement = jsonParser.parse(response);
@@ -100,10 +104,12 @@ private static void publishTemplate(String etag) throws IOException {
100104
httpURLConnection.setDoOutput(true);
101105
httpURLConnection.setRequestMethod("PUT");
102106
httpURLConnection.setRequestProperty("If-Match", etag);
107+
httpURLConnection.setRequestProperty("Content-Encoding", "gzip");
103108

104109
String configStr = readConfig();
105110

106-
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream());
111+
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(httpURLConnection.getOutputStream());
112+
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(gzipOutputStream);
107113
outputStreamWriter.write(configStr);
108114
outputStreamWriter.flush();
109115
outputStreamWriter.close();

0 commit comments

Comments
 (0)