feat: [RustHTTP] DNS Host Map

This commit is contained in:
2024-03-12 20:07:06 +08:00
parent 51393317b1
commit 26b58324c4
11 changed files with 262 additions and 40 deletions

View File

@ -16,17 +16,22 @@ Future<RustHttpResponse> fetch(
required String url,
Map<String, String>? headers,
Uint8List? inputData,
String? withIpAddress,
dynamic hint}) =>
RustLib.instance.api.fetch(
method: method,
url: url,
headers: headers,
inputData: inputData,
withIpAddress: withIpAddress,
hint: hint);
Future<List<String>> dnsLookupTxt({required String host, dynamic hint}) =>
RustLib.instance.api.dnsLookupTxt(host: host, hint: hint);
Future<List<String>> dnsLookupIps({required String host, dynamic hint}) =>
RustLib.instance.api.dnsLookupIps(host: host, hint: hint);
enum MyMethod {
options,
gets,

View File

@ -64,6 +64,8 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
}
abstract class RustLibApi extends BaseApi {
Future<List<String>> dnsLookupIps({required String host, dynamic hint});
Future<List<String>> dnsLookupTxt({required String host, dynamic hint});
Future<RustHttpResponse> fetch(
@ -71,6 +73,7 @@ abstract class RustLibApi extends BaseApi {
required String url,
Map<String, String>? headers,
Uint8List? inputData,
String? withIpAddress,
dynamic hint});
Future<void> setDefaultHeader(
@ -91,6 +94,31 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
required super.portManager,
});
@override
Future<List<String>> dnsLookupIps({required String host, dynamic hint}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(host, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 4, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_list_String,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kDnsLookupIpsConstMeta,
argValues: [host],
apiImpl: this,
hint: hint,
));
}
TaskConstMeta get kDnsLookupIpsConstMeta => const TaskConstMeta(
debugName: "dns_lookup_ips",
argNames: ["host"],
);
@override
Future<List<String>> dnsLookupTxt({required String host, dynamic hint}) {
return handler.executeNormal(NormalTask(
@ -122,6 +150,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
required String url,
Map<String, String>? headers,
Uint8List? inputData,
String? withIpAddress,
dynamic hint}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
@ -130,6 +159,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(url, serializer);
sse_encode_opt_Map_String_String(headers, serializer);
sse_encode_opt_list_prim_u_8_strict(inputData, serializer);
sse_encode_opt_String(withIpAddress, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 2, port: port_);
},
@ -138,7 +168,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kFetchConstMeta,
argValues: [method, url, headers, inputData],
argValues: [method, url, headers, inputData, withIpAddress],
apiImpl: this,
hint: hint,
));
@ -146,7 +176,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
TaskConstMeta get kFetchConstMeta => const TaskConstMeta(
debugName: "fetch",
argNames: ["method", "url", "headers", "inputData"],
argNames: ["method", "url", "headers", "inputData", "withIpAddress"],
);
@override
@ -188,7 +218,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_list_String(arguments, serializer);
sse_encode_String(workingDirectory, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 4, port: port_);
funcId: 5, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
@ -273,6 +303,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw == null ? null : dco_decode_Map_String_String(raw);
}
@protected
String? dco_decode_opt_String(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return raw == null ? null : dco_decode_String(raw);
}
@protected
int? dco_decode_opt_box_autoadd_u_64(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@ -431,6 +467,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
String? sse_decode_opt_String(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
if (sse_decode_bool(deserializer)) {
return (sse_decode_String(deserializer));
} else {
return null;
}
}
@protected
int? sse_decode_opt_box_autoadd_u_64(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@ -595,6 +642,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
void sse_encode_opt_String(String? self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_bool(self != null, serializer);
if (self != null) {
sse_encode_String(self, serializer);
}
}
@protected
void sse_encode_opt_box_autoadd_u_64(int? self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs

View File

@ -53,6 +53,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw);
@protected
String? dco_decode_opt_String(dynamic raw);
@protected
int? dco_decode_opt_box_autoadd_u_64(dynamic raw);
@ -113,6 +116,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
Map<String, String>? sse_decode_opt_Map_String_String(
SseDeserializer deserializer);
@protected
String? sse_decode_opt_String(SseDeserializer deserializer);
@protected
int? sse_decode_opt_box_autoadd_u_64(SseDeserializer deserializer);
@ -179,6 +185,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
void sse_encode_opt_Map_String_String(
Map<String, String>? self, SseSerializer serializer);
@protected
void sse_encode_opt_String(String? self, SseSerializer serializer);
@protected
void sse_encode_opt_box_autoadd_u_64(int? self, SseSerializer serializer);

View File

@ -52,6 +52,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw);
@protected
String? dco_decode_opt_String(dynamic raw);
@protected
int? dco_decode_opt_box_autoadd_u_64(dynamic raw);
@ -112,6 +115,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
Map<String, String>? sse_decode_opt_Map_String_String(
SseDeserializer deserializer);
@protected
String? sse_decode_opt_String(SseDeserializer deserializer);
@protected
int? sse_decode_opt_box_autoadd_u_64(SseDeserializer deserializer);
@ -178,6 +184,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
void sse_encode_opt_Map_String_String(
Map<String, String>? self, SseSerializer serializer);
@protected
void sse_encode_opt_String(String? self, SseSerializer serializer);
@protected
void sse_encode_opt_box_autoadd_u_64(int? self, SseSerializer serializer);

View File

@ -12,6 +12,7 @@ enum MyHttpVersion {
http11,
http2,
http3,
httpUnknown,
}
class RustHttpResponse {