Skip to content

Commit 86928e1

Browse files
fix: Allow optional whitespace in header values (#188)
1 parent f041ec6 commit 86928e1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

http_cache_core/lib/src/model/cache/cache_control.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class CacheControl {
110110
other.add(attribute);
111111
}
112112
}
113+
scanner.scan(whitespace);
113114
}
114115

115116
headerValues ??= [];

http_cache_core/test/cache_control_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ void main() {
4040
expect(cacheControl1, equals(cacheControl3));
4141
});
4242

43+
test('headers with and without optional whitespace', () {
44+
final cacheControl1 = CacheControl(
45+
maxAge: 1,
46+
noCache: true,
47+
noStore: true,
48+
other: ['unknown', 'unknown2=2'],
49+
privacy: 'public',
50+
maxStale: 2,
51+
minFresh: 3,
52+
mustRevalidate: true,
53+
);
54+
55+
final cacheControl2 = CacheControl.fromHeader([
56+
'max-age=1 , no-store, no-cache, public,unknown , unknown2=2 , max-stale=2,min-fresh=3,must-revalidate',
57+
]);
58+
59+
expect(cacheControl1, equals(cacheControl2));
60+
61+
// Redo test with toHeader()
62+
final cacheControl3 = CacheControl.fromHeader([cacheControl2.toHeader()]);
63+
expect(cacheControl1, equals(cacheControl3));
64+
});
65+
4366
test('headers splitted', () {
4467
final cacheControl1 = CacheControl(
4568
maxAge: 1,

0 commit comments

Comments
 (0)