From e3b7ad9115c276b74838bb155c82b92b8de6b074 Mon Sep 17 00:00:00 2001 From: pnda <43609023+ThePNDA@users.noreply.github.com> Date: Sat, 13 Mar 2021 19:04:38 +0100 Subject: [PATCH] Allow HTTP Headers for GET requests --- lib/src/utilities/web_util.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/utilities/web_util.dart b/lib/src/utilities/web_util.dart index dbf86ea..49ebedd 100644 --- a/lib/src/utilities/web_util.dart +++ b/lib/src/utilities/web_util.dart @@ -8,9 +8,13 @@ class WebUtil { static final HttpClient _client = HttpClient(); /// HTTP GET request. - static Future get(String base, String api) async { + static Future get(String base, String api, + {Map headers = const {}}) async { if (!base.endsWith('/')) base += '/'; final request = await _client.getUrl(Uri.parse('$base$api')); + for (final header in headers.entries) { + request.headers.add(header.key, header.value); + } return request.close(); } @@ -19,7 +23,8 @@ class WebUtil { [Map headers = const {}]) async { if (!base.endsWith('/')) base += '/'; if (!(body is List) && !(body is Map)) { - throw Exception('body must be a List or Map'); + throw ArgumentError.value( + body.runtimeType, 'body', 'body must be a List or Map'); } final request = await _client.postUrl(Uri.parse('$base$api')); for (MapEntry e in headers.entries) {