|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using Microsoft.AspNet.Http.Internal; |
| 5 | +using Microsoft.Framework.Primitives; |
| 6 | + |
| 7 | +namespace Microsoft.AspNet.Http |
| 8 | +{ |
| 9 | + public static class HeaderDictionaryExtensions |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Add new values. Each item remains a separate array entry. |
| 13 | + /// </summary> |
| 14 | + /// <param name="key">The header name.</param> |
| 15 | + /// <param name="value">The header value.</param> |
| 16 | + public static void Append(this IHeaderDictionary headers, string key, StringValues value) |
| 17 | + { |
| 18 | + ParsingHelpers.AppendHeaderUnmodified(headers, key, value); |
| 19 | + } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Quotes any values containing comas, and then coma joins all of the values with any existing values. |
| 23 | + /// </summary> |
| 24 | + /// <param name="key">The header name.</param> |
| 25 | + /// <param name="values">The header values.</param> |
| 26 | + public static void AppendCommaSeparatedValues(this IHeaderDictionary headers, string key, params string[] values) |
| 27 | + { |
| 28 | + ParsingHelpers.AppendHeaderJoined(headers, key, values); |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Get the associated values from the collection separated into individual values. |
| 33 | + /// Quoted values will not be split, and the quotes will be removed. |
| 34 | + /// </summary> |
| 35 | + /// <param name="key">The header name.</param> |
| 36 | + /// <returns>the associated values from the collection separated into individual values, or StringValues.Empty if the key is not present.</returns> |
| 37 | + public static string[] GetCommaSeparatedValues(this IHeaderDictionary headers, string key) |
| 38 | + { |
| 39 | + return ParsingHelpers.GetHeaderSplit(headers, key); |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Quotes any values containing comas, and then coma joins all of the values. |
| 44 | + /// </summary> |
| 45 | + /// <param name="key">The header name.</param> |
| 46 | + /// <param name="values">The header values.</param> |
| 47 | + public static void SetCommaSeparatedValues(this IHeaderDictionary headers, string key, params string[] values) |
| 48 | + { |
| 49 | + ParsingHelpers.SetHeaderJoined(headers, key, values); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments