Skip to content

Commit

Permalink
Allow HTTP Headers for GET requests
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Mar 13, 2021
1 parent fa8df22 commit e3b7ad9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/src/utilities/web_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ class WebUtil {
static final HttpClient _client = HttpClient();

/// HTTP GET request.
static Future<HttpClientResponse> get(String base, String api) async {
static Future<HttpClientResponse> get(String base, String api,
{Map<String, dynamic> 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();
}

Expand All @@ -19,7 +23,8 @@ class WebUtil {
[Map<String, dynamic> 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) {
Expand Down

0 comments on commit e3b7ad9

Please sign in to comment.