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';
|
import '../consts.dart';
|
||||||
|
|
||||||
List<String> getHeaderSuggestions(String pattern) {
|
List<String> getHeaderSuggestions(String pattern) {
|
||||||
return kHttpHeadersMap.keys
|
var matches = kHttpHeadersMap.keys
|
||||||
.where(
|
.map((item) => (item.toLowerCase().indexOf(pattern.toLowerCase()), item))
|
||||||
(element) => element.toLowerCase().contains(pattern.toLowerCase()),
|
.where((element) => element.$1 >= 0)
|
||||||
)
|
|
||||||
.toList();
|
.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", () {
|
test("Testing using 'x-' pattern", () {
|
||||||
String pattern = "x-";
|
String pattern = "x-";
|
||||||
List<String> expected = [
|
List<String> expected = [
|
||||||
"Access-Control-Max-Age",
|
|
||||||
"Max-Forwards",
|
|
||||||
"X-Api-Key",
|
"X-Api-Key",
|
||||||
"X-Content-Type-Options",
|
"X-Content-Type-Options",
|
||||||
"X-CSRF-Token",
|
"X-CSRF-Token",
|
||||||
"X-Forwarded-For",
|
"X-Forwarded-For",
|
||||||
"X-Frame-Options",
|
"X-Frame-Options",
|
||||||
"X-Requested-With",
|
"X-Requested-With",
|
||||||
"X-XSS-Protection"
|
"X-XSS-Protection",
|
||||||
|
"Max-Forwards",
|
||||||
|
"Access-Control-Max-Age",
|
||||||
];
|
];
|
||||||
expect(getHeaderSuggestions(pattern), expected);
|
expect(getHeaderSuggestions(pattern), expected);
|
||||||
});
|
});
|
||||||
@ -130,11 +130,11 @@ void main() {
|
|||||||
test("Testing for 'origin' pattern", () {
|
test("Testing for 'origin' pattern", () {
|
||||||
String pattern = "origin";
|
String pattern = "origin";
|
||||||
List<String> expected = [
|
List<String> expected = [
|
||||||
'Access-Control-Allow-Origin',
|
'Origin',
|
||||||
'Cross-Origin-Embedder-Policy',
|
'Cross-Origin-Embedder-Policy',
|
||||||
'Cross-Origin-Opener-Policy',
|
'Cross-Origin-Opener-Policy',
|
||||||
'Cross-Origin-Resource-Policy',
|
'Cross-Origin-Resource-Policy',
|
||||||
'Origin'
|
'Access-Control-Allow-Origin',
|
||||||
];
|
];
|
||||||
expect(getHeaderSuggestions(pattern), expected);
|
expect(getHeaderSuggestions(pattern), expected);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user