mirror of
https://github.com/foss42/apidash.git
synced 2025-05-31 22:33:59 +08:00
closes #207 header suggestions sorted by relevance
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import '../consts.dart';
|
||||
|
||||
List<String> getHeaderSuggestions(String pattern) {
|
||||
return kHttpHeadersMap.keys
|
||||
.where(
|
||||
(element) => element.toLowerCase().contains(pattern.toLowerCase()),
|
||||
)
|
||||
var matches = kHttpHeadersMap.keys
|
||||
.map((item) => (item.toLowerCase().indexOf(pattern.toLowerCase()), item))
|
||||
.where((element) => element.$1 >= 0)
|
||||
.toList();
|
||||
|
||||
matches.sort((a, b) => a.$1.compareTo(b.$1));
|
||||
|
||||
return matches.map((item) => item.$2).toList();
|
||||
}
|
||||
|
@ -114,15 +114,15 @@ void main() {
|
||||
test("Testing using 'x-' pattern", () {
|
||||
String pattern = "x-";
|
||||
List<String> expected = [
|
||||
"Access-Control-Max-Age",
|
||||
"Max-Forwards",
|
||||
"X-Api-Key",
|
||||
"X-Content-Type-Options",
|
||||
"X-CSRF-Token",
|
||||
"X-Forwarded-For",
|
||||
"X-Frame-Options",
|
||||
"X-Requested-With",
|
||||
"X-XSS-Protection"
|
||||
"X-XSS-Protection",
|
||||
"Max-Forwards",
|
||||
"Access-Control-Max-Age",
|
||||
];
|
||||
expect(getHeaderSuggestions(pattern), expected);
|
||||
});
|
||||
@ -130,11 +130,11 @@ void main() {
|
||||
test("Testing for 'origin' pattern", () {
|
||||
String pattern = "origin";
|
||||
List<String> expected = [
|
||||
'Access-Control-Allow-Origin',
|
||||
'Origin',
|
||||
'Cross-Origin-Embedder-Policy',
|
||||
'Cross-Origin-Opener-Policy',
|
||||
'Cross-Origin-Resource-Policy',
|
||||
'Origin'
|
||||
'Access-Control-Allow-Origin',
|
||||
];
|
||||
expect(getHeaderSuggestions(pattern), expected);
|
||||
});
|
||||
|
Reference in New Issue
Block a user