File: Parsers\CacheControlHeaderValueParser.cs
Web Access
Project: src\src\Libraries\Microsoft.AspNetCore.HeaderParsing\Microsoft.AspNetCore.HeaderParsing.csproj (Microsoft.AspNetCore.HeaderParsing)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
 
namespace Microsoft.AspNetCore.HeaderParsing.Parsers;
 
internal sealed class CacheControlHeaderValueParser : HeaderParser<CacheControlHeaderValue>
{
    public static CacheControlHeaderValueParser Instance { get; } = new();
 
    public override bool TryParse(StringValues values, [NotNullWhen(true)] out CacheControlHeaderValue? result, [NotNullWhen(false)] out string? error)
    {
        if (values.Count != 1 || !CacheControlHeaderValue.TryParse(values[0], out var parsedValue))
        {
            error = "Unable to parse cache control value.";
            result = default;
            return false;
        }
 
        error = default;
        result = parsedValue;
        return true;
    }
}