Skip to content

Commit 97909b6

Browse files
lrhnCommit Queue
authored andcommitted
Update the cookie and cookie-date parsers.
Avoid doing unnecessary allocations, don't use `String.operator[]` to access single characters, or creating substrings that are not needed. Reuse the date-parser for cookie dates, instead of having two separate parsers. The cookie-date-parser was very forgiving, and only tested very little. It's unlikely that there will be wildly different cookie formats in actual use, when the specification only allows for one format. Change-Id: I81b3620cc4476af3584b859f9c1eb80362f83979 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448383 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Lasse Nielsen <[email protected]>
1 parent 60b72cb commit 97909b6

File tree

10 files changed

+808
-654
lines changed

10 files changed

+808
-654
lines changed

sdk/lib/_http/http.dart

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,7 @@ abstract interface class HeaderValue {
622622
factory HeaderValue([
623623
String value = "",
624624
Map<String, String?> parameters = const {},
625-
]) {
626-
return _HeaderValue(value, parameters);
627-
}
625+
]) => _HeaderValue(value, parameters);
628626

629627
/// Creates a new header value object from parsing a header value
630628
/// string with both value and optional parameters.
@@ -636,8 +634,8 @@ abstract interface class HeaderValue {
636634
}) {
637635
return _HeaderValue.parse(
638636
value,
639-
parameterSeparator: parameterSeparator,
640-
valueSeparator: valueSeparator,
637+
parameterSeparator: parameterSeparator.codeUnitAt(0),
638+
valueSeparator: valueSeparator?.codeUnitAt(0) ?? _CharCode.NONE,
641639
preserveBackslash: preserveBackslash,
642640
);
643641
}
@@ -829,7 +827,7 @@ abstract interface class Cookie {
829827
/// U+0021 (`!`) through U+007E (`~`), except the separator characters:
830828
/// `(`, `)`, `<`, `>`, `@`, `,`, `;`, `:`, `\`, `"`, `/`, `[`, `]`, `?`, `=`,
831829
/// `{`, and `}`.
832-
late String name;
830+
abstract String name;
833831

834832
/// The value of the cookie.
835833
///
@@ -840,34 +838,34 @@ abstract interface class Cookie {
840838
/// `"`, `,`, `;` and `\`.
841839
/// Cookie values may be wrapped in a single pair of double quotes
842840
/// (U+0022, `"`).
843-
late String value;
841+
abstract String value;
844842

845843
/// The time at which the cookie expires.
846-
DateTime? expires;
844+
abstract DateTime? expires;
847845

848846
/// The number of seconds until the cookie expires. A zero or negative value
849847
/// means the cookie has expired.
850-
int? maxAge;
848+
abstract int? maxAge;
851849

852850
/// The domain that the cookie applies to.
853-
String? domain;
851+
abstract String? domain;
854852

855853
/// The path within the [domain] that the cookie applies to.
856-
String? path;
854+
abstract String? path;
857855

858856
/// Whether to only send this cookie on secure connections.
859-
bool secure = false;
857+
abstract bool secure;
860858

861859
/// Whether the cookie is only sent in the HTTP request and is not made
862860
/// available to client side scripts.
863-
bool httpOnly = false;
861+
abstract bool httpOnly;
864862

865863
/// Whether the cookie is available from other sites.
866864
///
867865
/// This value is `null` if the SameSite attribute is not present.
868866
///
869867
/// See [SameSite] for more information.
870-
SameSite? sameSite;
868+
abstract SameSite? sameSite;
871869

872870
/// Creates a new cookie setting the name and value.
873871
///

0 commit comments

Comments
 (0)