mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[http] noFolding() should follow same check as add()
Walk through http headers class. Since http header uses case-insensitive headers, noFolding() implicitly assumes field name is lower-cases. It is used to compare to lower-cases field name. Validate the field name before it is stored and also add a test case for noFolding(). Change-Id: I58f8a0ed0d366281e1e7a8c60fd46ff81c8ee796 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121773 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Commit-Queue: Zichang Guo <zichangguo@google.com>
This commit is contained in:
parent
7408ed4730
commit
4366afc6f5
3 changed files with 18 additions and 0 deletions
|
@ -104,6 +104,7 @@ class _HttpHeaders implements HttpHeaders {
|
|||
}
|
||||
|
||||
void noFolding(String name) {
|
||||
name = _validateField(name);
|
||||
if (_noFoldingHeaders == null) _noFoldingHeaders = new List<String>();
|
||||
_noFoldingHeaders.add(name);
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ class _HttpHeaders implements HttpHeaders {
|
|||
}
|
||||
|
||||
void noFolding(String name) {
|
||||
name = _validateField(name);
|
||||
if (_noFoldingHeaders == null) _noFoldingHeaders = new List<String>();
|
||||
_noFoldingHeaders.add(name);
|
||||
}
|
||||
|
|
|
@ -563,6 +563,21 @@ void testClear() {
|
|||
Expect.isFalse(headers.chunkedTransferEncoding);
|
||||
}
|
||||
|
||||
void testFolding() {
|
||||
_HttpHeaders headers = new _HttpHeaders("1.1");
|
||||
headers.add("a", "b");
|
||||
headers.add("a", "c");
|
||||
headers.add("a", "d");
|
||||
// no folding by default
|
||||
Expect.isTrue(headers.toString().contains('b, c, d'));
|
||||
// Header name should be case insensitive
|
||||
headers.noFolding('A');
|
||||
var str = headers.toString();
|
||||
Expect.isTrue(str.contains(': b'));
|
||||
Expect.isTrue(str.contains(': c'));
|
||||
Expect.isTrue(str.contains(': d'));
|
||||
}
|
||||
|
||||
main() {
|
||||
testMultiValue();
|
||||
testDate();
|
||||
|
@ -581,4 +596,5 @@ main() {
|
|||
testInvalidFieldName();
|
||||
testInvalidFieldValue();
|
||||
testClear();
|
||||
testFolding();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue