From e5bdbffbcf61af187408dd68c6552101fdaef4e6 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 28 Jul 2023 17:53:02 +0800 Subject: [PATCH] ab compression --- flutter/lib/models/ab_model.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index ee16fb79843..8ae320a521d 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_hbb/models/model.dart'; @@ -47,7 +48,8 @@ class AbModel { try { var authHeaders = getHttpHeaders(); authHeaders['Content-Type'] = "application/json"; - final resp = await http.post(Uri.parse(api), headers: authHeaders); + authHeaders['Accept-Encoding'] = "gzip"; + final resp = await http.get(Uri.parse(api), headers: authHeaders); if (resp.body.isNotEmpty && resp.body.toLowerCase() != "null") { Map json = jsonDecode(resp.body); if (json.containsKey('error')) { @@ -136,8 +138,16 @@ class AbModel { final body = jsonEncode({ "data": jsonEncode({"tags": tags, "peers": peersJsonData}) }); + var request = http.Request('POST', Uri.parse(api)); + if (licensedDevices > 0) { + authHeaders['Content-Encoding'] = "gzip"; + request.bodyBytes = GZipCodec().encode(utf8.encode(body)); + } else { + request.body = body; + } + request.headers.addAll(authHeaders); try { - await http.post(Uri.parse(api), headers: authHeaders, body: body); + await http.Client().send(request); await pullAb(quiet: true); } catch (e) { BotToast.showText(contentColor: Colors.red, text: e.toString());