<commit_before>// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Text;
using Microsoft.Extensions.ObjectPool;

namespace Microsoft.AspNetCore.Http.Features
{
    /// <summary>
    /// Default implementation of <see cref="IResponseCookiesFeature"/>.
    /// </summary>
    public class ResponseCookiesFeature : IResponseCookiesFeature
    {
        // Lambda hoisted to static readonly field to improve inlining https://github.com/dotnet/roslyn/issues/13624
        private readonly static Func<IFeatureCollection, IHttpResponseFeature?> _nullResponseFeature = f => null;

        private FeatureReferences<IHttpResponseFeature> _features;
        private IResponseCookies? _cookiesCollection;

        /// <summary>
        /// Initializes a new <see cref="ResponseCookiesFeature"/> instance.
        /// </summary>
        /// <param name="features">
        /// <see cref="IFeatureCollection"/> containing all defined features, including this
        /// <see cref="IResponseCookiesFeature"/> and the <see cref="IHttpResponseFeature"/>.
        /// </param>
        public ResponseCookiesFeature(IFeatureCollection features)
            : this(features, builderPool: null)
        {
        }

        /// <summary>
        /// Initializes a new <see cref="ResponseCookiesFeature"/> instance.
        /// </summary>
        /// <param name="features">
        /// <see cref="IFeatureCollection"/> containing all defined features, including this
        /// <see cref="IResponseCookiesFeature"/> and the <see cref="IHttpResponseFeature"/>.
        /// </param>
        /// <param name="builderPool">The <see cref="ObjectPool{T}"/>, if available.</param>
        public ResponseCookiesFeature(IFeatureCollection features, ObjectPool<StringBuilder>? builderPool)
        {
            if (features == null)
            {
                throw new ArgumentNullException(nameof(features));
            }

            _features.Initalize(features);
        }

        private IHttpResponseFeature HttpResponseFeature => _features.Fetch(ref _features.Cache, _nullResponseFeature)!;

        /// <inheritdoc />
        public IResponseCookies Cookies
        {
            get
            {
                if (_cookiesCollection == null)
                {
                    var headers = HttpResponseFeature.Headers;
                    _cookiesCollection = new ResponseCookies(headers);
                }

                return _cookiesCollection;
            }
        }<commit_msg>Obsolete the ResponseCookiesFeature constructor (#24546)<commit_after>// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Text;
using Microsoft.Extensions.ObjectPool;

namespace Microsoft.AspNetCore.Http.Features
{
    /// <summary>
    /// Default implementation of <see cref="IResponseCookiesFeature"/>.
    /// </summary>
    public class ResponseCookiesFeature : IResponseCookiesFeature
    {
        // Lambda hoisted to static readonly field to improve inlining https://github.com/dotnet/roslyn/issues/13624
        private readonly static Func<IFeatureCollection, IHttpResponseFeature?> _nullResponseFeature = f => null;

        private FeatureReferences<IHttpResponseFeature> _features;
        private IResponseCookies? _cookiesCollection;

        /// <summary>
        /// Initializes a new <see cref="ResponseCookiesFeature"/> instance.
        /// </summary>
        /// <param name="features">
        /// <see cref="IFeatureCollection"/> containing all defined features, including this
        /// <see cref="IResponseCookiesFeature"/> and the <see cref="IHttpResponseFeature"/>.
        /// </param>
        public ResponseCookiesFeature(IFeatureCollection features)
        {
            if (features == null)
            {
                throw new ArgumentNullException(nameof(features));
            }

            _features.Initalize(features);
        }

        /// <summary>
        /// Initializes a new <see cref="ResponseCookiesFeature"/> instance.
        /// </summary>
        /// <param name="features">
        /// <see cref="IFeatureCollection"/> containing all defined features, including this
        /// <see cref="IResponseCookiesFeature"/> and the <see cref="IHttpResponseFeature"/>.
        /// </param>
        /// <param name="builderPool">The <see cref="ObjectPool{T}"/>, if available.</param>
        [Obsolete("This constructor is obsolete and will be removed in a future version.")]
        public ResponseCookiesFeature(IFeatureCollection features, ObjectPool<StringBuilder>? builderPool)
        {
            if (features == null)
            {
                throw new ArgumentNullException(nameof(features));
            }

            _features.Initalize(features);
        }

        private IHttpResponseFeature HttpResponseFeature => _features.Fetch(ref _features.Cache, _nullResponseFeature)!;

        /// <inheritdoc />
        public IResponseCookies Cookies
        {
            get
            {
                if (_cookiesCollection == null)
                {
                    var headers = HttpResponseFeature.Headers;
                    _cookiesCollection = new ResponseCookies(headers);
                }

                return _cookiesCollection;
            }
        }
{'fraction_non_alphanumeric': 0.10554951033732318, 'fraction_numerical': 0.0034457743924555676, 'mean_word_length': 2.2633136094674557, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5558481', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1301, 'n_words': 346}