This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
/
ResponseCookiesFeature.cs
69 lines (60 loc) · 2.63 KB
/
ResponseCookiesFeature.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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.AspNetCore.Http.Internal;
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 = new FeatureReferences<IHttpResponseFeature>(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, null);
}
return _cookiesCollection;
}
}
}
}