feat: rust/rsHttp Option with_custom_dns

This commit is contained in:
2024-11-03 15:57:37 +08:00
parent 7e1e96707c
commit 0c03050f5c
7 changed files with 227 additions and 44 deletions

View File

@ -14,49 +14,73 @@ class RSHttp {
});
}
static Future<RustHttpResponse> get(String url,
{Map<String, String>? headers, String? withIpAddress}) async {
static Future<RustHttpResponse> get(
String url, {
Map<String, String>? headers,
String? withIpAddress,
bool? withCustomDns,
}) async {
final r = await rust_http.fetch(
method: MyMethod.gets,
url: url,
headers: headers,
withIpAddress: withIpAddress);
method: MyMethod.gets,
url: url,
headers: headers,
withIpAddress: withIpAddress,
withCustomDns: withCustomDns,
);
return r;
}
static Future<String> getText(String url,
{Map<String, String>? headers, String? withIpAddress}) async {
final r = await get(url, headers: headers, withIpAddress: withIpAddress);
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);
if (r.data == null) return "";
final str = utf8.decode(r.data!);
return str;
}
static Future<RustHttpResponse> postData(String url,
{Map<String, String>? headers,
String? contentType,
Uint8List? data,
String? withIpAddress}) async {
static Future<RustHttpResponse> postData(
String url, {
Map<String, String>? headers,
String? contentType,
Uint8List? data,
String? withIpAddress,
bool? withCustomDns,
}) async {
if (contentType != null) {
headers ??= {};
headers["Content-Type"] = contentType;
}
final r = await rust_http.fetch(
method: MyMethod.post,
url: url,
headers: headers,
inputData: data,
withIpAddress: withIpAddress);
method: MyMethod.post,
url: url,
headers: headers,
inputData: data,
withIpAddress: withIpAddress,
withCustomDns: withCustomDns,
);
return r;
}
static Future<RustHttpResponse> head(String url,
{Map<String, String>? headers, String? withIpAddress}) async {
static Future<RustHttpResponse> head(
String url, {
Map<String, String>? headers,
String? withIpAddress,
bool? withCustomDns,
}) async {
final r = await rust_http.fetch(
method: MyMethod.head,
url: url,
headers: headers,
withIpAddress: withIpAddress);
method: MyMethod.head,
url: url,
headers: headers,
withIpAddress: withIpAddress,
withCustomDns: withCustomDns,
);
return r;
}