2024-02-07 19:32:36 +08:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2024-03-07 23:01:32 +08:00
|
|
|
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
|
2024-02-07 19:32:36 +08:00
|
|
|
import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http;
|
|
|
|
import 'package:starcitizen_doctor/common/rust/api/http_api.dart';
|
2024-02-07 22:19:43 +08:00
|
|
|
import 'package:starcitizen_doctor/common/rust/http_package.dart';
|
2024-02-07 19:32:36 +08:00
|
|
|
|
|
|
|
class RSHttp {
|
2024-02-07 22:19:43 +08:00
|
|
|
static init() async {
|
|
|
|
await rust_http.setDefaultHeader(headers: {
|
|
|
|
"User-Agent":
|
2024-03-07 23:01:32 +08:00
|
|
|
"SCToolBox/${ConstConf.appVersion} (${ConstConf.appVersionCode})${ConstConf.isMSE ? "" : " DEV"} RSHttp"
|
2024-02-07 22:19:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-03 15:57:37 +08:00
|
|
|
static Future<RustHttpResponse> get(
|
|
|
|
String url, {
|
|
|
|
Map<String, String>? headers,
|
|
|
|
String? withIpAddress,
|
|
|
|
bool? withCustomDns,
|
|
|
|
}) async {
|
2024-02-07 19:32:36 +08:00
|
|
|
final r = await rust_http.fetch(
|
2024-11-03 15:57:37 +08:00
|
|
|
method: MyMethod.gets,
|
|
|
|
url: url,
|
|
|
|
headers: headers,
|
|
|
|
withIpAddress: withIpAddress,
|
|
|
|
withCustomDns: withCustomDns,
|
|
|
|
);
|
2024-02-07 22:29:15 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2024-11-03 15:57:37 +08:00
|
|
|
static Future<String> getText(
|
|
|
|
String url, {
|
|
|
|
Map<String, String>? headers,
|
|
|
|
String? withIpAddress,
|
|
|
|
bool? withCustomDns,
|
|
|
|
}) async {
|
|
|
|
final r = await get(url,
|
|
|
|
headers: headers,
|
|
|
|
withIpAddress: withIpAddress,
|
|
|
|
withCustomDns: withCustomDns);
|
2024-02-07 19:32:36 +08:00
|
|
|
if (r.data == null) return "";
|
|
|
|
final str = utf8.decode(r.data!);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2024-11-03 15:57:37 +08:00
|
|
|
static Future<RustHttpResponse> postData(
|
|
|
|
String url, {
|
|
|
|
Map<String, String>? headers,
|
|
|
|
String? contentType,
|
|
|
|
Uint8List? data,
|
|
|
|
String? withIpAddress,
|
|
|
|
bool? withCustomDns,
|
|
|
|
}) async {
|
2024-02-07 19:32:36 +08:00
|
|
|
if (contentType != null) {
|
|
|
|
headers ??= {};
|
|
|
|
headers["Content-Type"] = contentType;
|
|
|
|
}
|
|
|
|
final r = await rust_http.fetch(
|
2024-11-03 15:57:37 +08:00
|
|
|
method: MyMethod.post,
|
|
|
|
url: url,
|
|
|
|
headers: headers,
|
|
|
|
inputData: data,
|
|
|
|
withIpAddress: withIpAddress,
|
|
|
|
withCustomDns: withCustomDns,
|
|
|
|
);
|
2024-02-16 22:47:06 +08:00
|
|
|
return r;
|
2024-02-07 19:32:36 +08:00
|
|
|
}
|
2024-02-07 22:19:43 +08:00
|
|
|
|
2024-11-03 15:57:37 +08:00
|
|
|
static Future<RustHttpResponse> head(
|
|
|
|
String url, {
|
|
|
|
Map<String, String>? headers,
|
|
|
|
String? withIpAddress,
|
|
|
|
bool? withCustomDns,
|
|
|
|
}) async {
|
2024-02-07 22:19:43 +08:00
|
|
|
final r = await rust_http.fetch(
|
2024-11-03 15:57:37 +08:00
|
|
|
method: MyMethod.head,
|
|
|
|
url: url,
|
|
|
|
headers: headers,
|
|
|
|
withIpAddress: withIpAddress,
|
|
|
|
withCustomDns: withCustomDns,
|
|
|
|
);
|
2024-02-07 22:19:43 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<List<String>> dnsLookupTxt(String host) async {
|
|
|
|
return await rust_http.dnsLookupTxt(host: host);
|
|
|
|
}
|
2024-03-12 22:08:46 +08:00
|
|
|
|
|
|
|
static Future<List<String>> dnsLookupIps(String host) async {
|
|
|
|
return await rust_http.dnsLookupIps(host: host);
|
|
|
|
}
|
2024-02-07 19:32:36 +08:00
|
|
|
}
|