[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:
Zichang Guo 2019-11-11 16:36:23 +00:00 committed by commit-bot@chromium.org
parent 7408ed4730
commit 4366afc6f5
3 changed files with 18 additions and 0 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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();
}