// Add the given parameter to the list. Remove if date is null. private void SetDate(string parameter, DateTimeOffset?date) { var dateParameter = NameValueHeaderValue.Find(_parameters, parameter); if (date == null) { // Remove parameter if (dateParameter != null) { _parameters.Remove(dateParameter); } } else { // Must always be quoted var dateString = HeaderUtilities.FormatDate(date.GetValueOrDefault(), quoted: true); if (dateParameter != null) { dateParameter.Value = dateString; } else { Parameters.Add(new NameValueHeaderValue(parameter, dateString)); } } }
public override string ToString() { if (_entityTag == null) { return(HeaderUtilities.FormatDate(_lastModified.GetValueOrDefault())); } return(_entityTag.ToString()); }
/// <summary> /// Append string representation of this <see cref="SetCookieHeaderValue"/> to given /// <paramref name="builder"/>. /// </summary> /// <param name="builder"> /// The <see cref="StringBuilder"/> to receive the string representation of this /// <see cref="SetCookieHeaderValue"/>. /// </param> public void AppendToStringBuilder(StringBuilder builder) { builder.Append(_name.AsSpan()); builder.Append("="); builder.Append(_value.AsSpan()); if (Expires.HasValue) { AppendSegment(builder, ExpiresToken, HeaderUtilities.FormatDate(Expires.GetValueOrDefault())); } if (MaxAge.HasValue) { AppendSegment(builder, MaxAgeToken, HeaderUtilities.FormatNonNegativeInt64((long)MaxAge.GetValueOrDefault().TotalSeconds)); } if (Domain != null) { AppendSegment(builder, DomainToken, Domain); } if (Path != null) { AppendSegment(builder, PathToken, Path); } if (Secure) { AppendSegment(builder, SecureToken, null); } // Allow for Unspecified (-1) to skip SameSite if (SameSite == SameSiteMode.None && !SuppressSameSiteNone) { AppendSegment(builder, SameSiteToken, SameSiteNoneToken); } else if (SameSite == SameSiteMode.Lax) { AppendSegment(builder, SameSiteToken, SameSiteLaxToken); } else if (SameSite == SameSiteMode.Strict) { AppendSegment(builder, SameSiteToken, SameSiteStrictToken); } if (HttpOnly) { AppendSegment(builder, HttpOnlyToken, null); } }