mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
update network wrapper
This commit is contained in:
parent
544df2c882
commit
f1cb7278c5
1 changed files with 56 additions and 17 deletions
|
@ -1,40 +1,79 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
|
||||||
// WIP wrapper layer
|
// WIP wrapper layer
|
||||||
|
|
||||||
abstract class HTTP {
|
abstract class HTTP {
|
||||||
static Future<http.Response> get({
|
static Future<HttpClientResponse> get({
|
||||||
required Uri url,
|
required Uri url,
|
||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
required bool routeOverTor,
|
required bool routeOverTor,
|
||||||
}) async {
|
}) async {
|
||||||
if (routeOverTor) {
|
final httpClient = HttpClient();
|
||||||
// TODO
|
try {
|
||||||
throw UnimplementedError();
|
if (routeOverTor) {
|
||||||
} else {
|
// TODO
|
||||||
return http.get(url, headers: headers);
|
throw UnimplementedError();
|
||||||
|
} else {
|
||||||
|
final HttpClientRequest request = await httpClient.getUrl(
|
||||||
|
url,
|
||||||
|
);
|
||||||
|
|
||||||
|
request.headers.clear();
|
||||||
|
if (headers != null) {
|
||||||
|
headers.forEach((key, value) => request.headers.add);
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.close();
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"HTTP.get() rethrew: $e\n$s",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
httpClient.close(force: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<http.Response> post({
|
static Future<HttpClientResponse> post({
|
||||||
required Uri url,
|
required Uri url,
|
||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
Object? body,
|
Object? body,
|
||||||
Encoding? encoding,
|
Encoding? encoding,
|
||||||
required bool routeOverTor,
|
required bool routeOverTor,
|
||||||
}) async {
|
}) async {
|
||||||
if (routeOverTor) {
|
final httpClient = HttpClient();
|
||||||
// TODO
|
try {
|
||||||
throw UnimplementedError();
|
if (routeOverTor) {
|
||||||
} else {
|
// TODO
|
||||||
return http.post(
|
throw UnimplementedError();
|
||||||
url,
|
} else {
|
||||||
headers: headers,
|
final HttpClientRequest request = await httpClient.postUrl(
|
||||||
body: body,
|
url,
|
||||||
encoding: encoding,
|
);
|
||||||
|
|
||||||
|
request.headers.clear();
|
||||||
|
|
||||||
|
if (headers != null) {
|
||||||
|
headers.forEach((key, value) => request.headers.add);
|
||||||
|
}
|
||||||
|
|
||||||
|
request.write(body);
|
||||||
|
|
||||||
|
return request.close();
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"HTTP.post() rethrew: $e\n$s",
|
||||||
|
level: LogLevel.Info,
|
||||||
);
|
);
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
httpClient.close(force: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue