Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpHeaders #37

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ class CaseInsensitiveMap<K extends String, V> implements Map<K, V> {

@override
V putIfAbsent(K key, V Function() ifAbsent) {
return _contents.putIfAbsent(normalizeKey(key), ifAbsent);
final normalizedKey = normalizeKey(key);

return _contents.putIfAbsent(normalizedKey, () {
_originalKeys[normalizedKey] = key;

return ifAbsent();
});
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension RequestInformationExtensions on RequestInformation {

/// Vanity method to add headers to the request.
void addHeaders(HttpHeaders headers) {
headers.addAll(headers);
this.headers.addAll(headers);
}

/// Vanity method to add query parameters to the request.
Expand Down
20 changes: 20 additions & 0 deletions packages/kiota_abstractions/test/case_insensitive_map_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ignore_for_file: avoid_redundant_argument_values

import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:test/test.dart';

void main() {
group('CaseInsensitiveMap', () {
test('putIfAbsent', () {
final headers = HttpHeaders()
..putIfAbsent('key', () => {'value'})
..map((name, values) {
return MapEntry(name, values.join(', '));
});
expect(
headers['key'],
{'value'},
);
});
});
}
12 changes: 12 additions & 0 deletions packages/kiota_abstractions/test/request_information_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,17 @@ void main() {
// Assert
expect(testRequest.uri.toString(), 'http://localhost/first,second');
});

test('Add headers', () {
// Arrange
final testRequest = RequestInformation();
final headers = HttpHeaders()..putIfAbsent('key', () => {'value'});

// Act
testRequest.addHeaders(headers);

// Assert
expect(testRequest.headers['key'], {'value'});
});
});
}
Loading