Skip to content

Commit e3b7ad9

Browse files
committed
Allow HTTP Headers for GET requests
1 parent fa8df22 commit e3b7ad9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/src/utilities/web_util.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ class WebUtil {
88
static final HttpClient _client = HttpClient();
99

1010
/// HTTP GET request.
11-
static Future<HttpClientResponse> get(String base, String api) async {
11+
static Future<HttpClientResponse> get(String base, String api,
12+
{Map<String, dynamic> headers = const {}}) async {
1213
if (!base.endsWith('/')) base += '/';
1314
final request = await _client.getUrl(Uri.parse('$base$api'));
15+
for (final header in headers.entries) {
16+
request.headers.add(header.key, header.value);
17+
}
1418
return request.close();
1519
}
1620

@@ -19,7 +23,8 @@ class WebUtil {
1923
[Map<String, dynamic> headers = const {}]) async {
2024
if (!base.endsWith('/')) base += '/';
2125
if (!(body is List) && !(body is Map)) {
22-
throw Exception('body must be a List or Map');
26+
throw ArgumentError.value(
27+
body.runtimeType, 'body', 'body must be a List or Map');
2328
}
2429
final request = await _client.postUrl(Uri.parse('$base$api'));
2530
for (MapEntry e in headers.entries) {

0 commit comments

Comments
 (0)