Skip to content

Commit abb2b5d

Browse files
committed
chore(flutter): handle gzip encoding
1 parent 29cea73 commit abb2b5d

File tree

9 files changed

+28
-14
lines changed

9 files changed

+28
-14
lines changed

android/measure/src/main/java/sh/measure/android/exporter/AttachmentExporter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ internal class DefaultAttachmentExporter(
134134
val response = httpClient.uploadFile(
135135
url = attachment.url,
136136
contentType = attachment.contentType,
137+
contentEncoding = attachment.contentEncoding,
137138
headers = attachment.headers,
138139
fileSize = file.length(),
139140
) { sink ->

android/measure/src/main/java/sh/measure/android/exporter/AttachmentPacket.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ internal data class AttachmentPacket(
2828

2929
else -> "application/octet-stream"
3030
}
31+
32+
val contentEncoding: String? = when (type) {
33+
AttachmentType.LAYOUT_SNAPSHOT_JSON -> "gzip"
34+
else -> null
35+
}
3136
}

android/measure/src/main/java/sh/measure/android/exporter/HttpUrlConnectionClient.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal interface HttpClient {
2222
fun uploadFile(
2323
url: String,
2424
contentType: String,
25+
contentEncoding: String?,
2526
headers: Map<String, String>,
2627
fileSize: Long,
2728
fileWriter: (BufferedSink) -> Unit,
@@ -89,13 +90,15 @@ internal class HttpUrlConnectionClient(private val logger: Logger) : HttpClient
8990
override fun uploadFile(
9091
url: String,
9192
contentType: String,
93+
contentEncoding: String?,
9294
headers: Map<String, String>,
9395
fileSize: Long,
9496
fileWriter: (BufferedSink) -> Unit,
9597
): HttpResponse {
9698
var connection: HttpURLConnection? = null
9799
return try {
98-
connection = createFileUploadConnection(url, contentType, headers, fileSize)
100+
connection =
101+
createFileUploadConnection(url, contentType, contentEncoding, headers, fileSize)
99102
logger.log(LogLevel.Debug, "Uploading file to: $url")
100103
connection.outputStream.sink().buffer().use { sink ->
101104
fileWriter(sink)
@@ -144,6 +147,7 @@ internal class HttpUrlConnectionClient(private val logger: Logger) : HttpClient
144147
private fun createFileUploadConnection(
145148
url: String,
146149
contentType: String,
150+
contentEncoding: String?,
147151
headers: Map<String, String>,
148152
fileSize: Long,
149153
): HttpURLConnection = (URL(url).openConnection() as HttpURLConnection).apply {
@@ -156,6 +160,7 @@ internal class HttpUrlConnectionClient(private val logger: Logger) : HttpClient
156160
setChunkedStreamingMode(0)
157161
}
158162
setRequestProperty("Content-Type", contentType)
163+
contentEncoding?.let { setRequestProperty("Content-Encoding", contentEncoding) }
159164
headers.forEach { (key, value) ->
160165
setRequestProperty(key, value)
161166
}

flutter/example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
<meta-data
2727
android:name="sh.measure.android.API_KEY"
28-
android:value="msrsh_" />
28+
android:value="msrsh_8456989a9cd452c7a4864d37a1f3cf9b4f8a45395203c19cb5b6d8252c6970fd_95a8744f" />
2929

3030
<meta-data android:name="sh.measure.android.API_URL"
31-
android:value="http://localhost:8080" />
31+
android:value="https://staging-ingest.measure.sh" />
3232

3333
<meta-data
3434
android:name="flutterEmbedding"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package sh.measure.android.flutter
22

33
import android.app.Application
4+
import sh.measure.android.Measure
5+
import sh.measure.android.config.MeasureConfig
46

57
class SampleApp : Application() {
68
override fun onCreate() {
79
super.onCreate()
10+
11+
Measure.init(this, MeasureConfig(enableLogging = true))
812
}
913
}

flutter/example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Future<void> main() async {
2121
layoutSnapshotWidgetTypes: msrWidgetsForLayoutSnapshot,
2222
),
2323
clientInfo: ClientInfo(
24-
apiKey: "msrsh_0c89033fc9ca86c29ba0300452d65ee441a60aac5adc7c5ee2d5057ebcbb4133_2d215ff0",
24+
apiKey: "msrsh_8456989a9cd452c7a4864d37a1f3cf9b4f8a45395203c19cb5b6d8252c6970fd_95a8744f",
2525
apiUrl: "https://staging-ingest.measure.sh",
2626
),
2727
);

flutter/packages/measure_flutter/lib/src/bug_report/attachment_processing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Future<FileProcessingResult> writeJsonToFileInIsolate(WriteLayoutSnapshotParams
116116
params.snapshot,
117117
params.fileName,
118118
params.rootPath,
119-
params.compress,
119+
compress: params.compress,
120120
);
121121
}
122122

flutter/packages/measure_flutter/lib/src/isolate/file_processing_isolate.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ class FileProcessingIsolate {
131131
_sendPort = await completer.future.timeout(
132132
_initTimeout,
133133
onTimeout: () {
134-
throw TimeoutException(
135-
'Failed to initialize file processing isolate');
134+
throw TimeoutException('Failed to initialize file processing isolate');
136135
},
137136
);
138137

@@ -228,9 +227,9 @@ class FileProcessingIsolate {
228227
Future<FileProcessingResult> processLayoutSnapshotWrite(
229228
LayoutSnapshot snapshot,
230229
String fileName,
231-
String rootPath,
232-
bool compress,
233-
) async {
230+
String rootPath, {
231+
bool compress = true,
232+
}) async {
234233
if (!_isInitialized || _sendPort == null) {
235234
return const FileProcessingResult(
236235
error: 'Isolate not initialized',
@@ -340,8 +339,7 @@ class FileProcessingIsolate {
340339
}
341340

342341
/// Handle JSON write in isolate
343-
static Future<void> _handleJsonWrite(
344-
LayoutSnapshotWriteRequest request) async {
342+
static Future<void> _handleJsonWrite(LayoutSnapshotWriteRequest request) async {
345343
try {
346344
final result = await writeJsonToFileInIsolateWorker(
347345
request.snapshot,

flutter/packages/measure_flutter/test/utils/fake_file_processing_isolate.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class FakeFileProcessingIsolate implements FileProcessingIsolate {
2121
Future<FileProcessingResult> processLayoutSnapshotWrite(
2222
LayoutSnapshot snapshot,
2323
String fileName,
24-
String rootPath,
25-
) async {
24+
String rootPath, {
25+
bool compress = true,
26+
}) async {
2627
if (shouldThrowException) {
2728
throw Exception('Test exception');
2829
}

0 commit comments

Comments
 (0)