Skip to content

Commit

Permalink
ab compression
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Jul 28, 2023
1 parent 1de50e8 commit e5bdbff
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions flutter/lib/models/ab_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_hbb/models/model.dart';
Expand Down Expand Up @@ -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<String, dynamic> json = jsonDecode(resp.body);
if (json.containsKey('error')) {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit e5bdbff

Please sign in to comment.