Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Move *CommaSeperatedValues APIs from IHeaderDictionary to extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Aug 25, 2015
1 parent 022c692 commit ce4587a
Show file tree
Hide file tree
Showing 5 changed files with 670 additions and 150 deletions.
29 changes: 0 additions & 29 deletions src/Microsoft.AspNet.Http.Abstractions/IHeaderDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,5 @@ public interface IHeaderDictionary : IReadableStringCollection, IDictionary<stri
/// Gets a collection containing the keys.
/// </summary>
new ICollection<string> Keys { get; }

/// <summary>
/// Get the associated values from the collection separated into individual values.
/// Quoted values will not be split, and the quotes will be removed.
/// </summary>
/// <param name="key">The header name.</param>
/// <returns>the associated values from the collection separated into individual values, or null if the key is not present.</returns>
StringValues GetCommaSeparatedValues(string key);

/// <summary>
/// Add a new value. Appends to the header list if already present
/// </summary>
/// <param name="key">The header name.</param>
/// <param name="value">The header value.</param>
void Append(string key, StringValues value);

/// <summary>
/// Quotes any values containing comas, and then coma joins all of the values with any existing values.
/// </summary>
/// <param name="key">The header name.</param>
/// <param name="values">The header values.</param>
void AppendCommaSeparatedValues(string key, params string[] values);

/// <summary>
/// Quotes any values containing comas, and then coma joins all of the values.
/// </summary>
/// <param name="key">The header name.</param>
/// <param name="values">The header values.</param>
void SetCommaSeparatedValues(string key, params string[] values);
}
}
52 changes: 52 additions & 0 deletions src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Primitives;

namespace Microsoft.AspNet.Http
{
public static class HeaderDictionaryExtensions
{
/// <summary>
/// Add new values. Each item remains a separate array entry.
/// </summary>
/// <param name="key">The header name.</param>
/// <param name="value">The header value.</param>
public static void Append(this IHeaderDictionary headers, string key, StringValues value)
{
ParsingHelpers.AppendHeaderUnmodified(headers, key, value);
}

/// <summary>
/// Quotes any values containing comas, and then coma joins all of the values with any existing values.
/// </summary>
/// <param name="key">The header name.</param>
/// <param name="values">The header values.</param>
public static void AppendCommaSeparatedValues(this IHeaderDictionary headers, string key, params string[] values)
{
ParsingHelpers.AppendHeaderJoined(headers, key, values);
}

/// <summary>
/// Get the associated values from the collection separated into individual values.
/// Quoted values will not be split, and the quotes will be removed.
/// </summary>
/// <param name="key">The header name.</param>
/// <returns>the associated values from the collection separated into individual values, or StringValues.Empty if the key is not present.</returns>
public static string[] GetCommaSeparatedValues(this IHeaderDictionary headers, string key)
{
return ParsingHelpers.GetHeaderSplit(headers, key);
}

/// <summary>
/// Quotes any values containing comas, and then coma joins all of the values.
/// </summary>
/// <param name="key">The header name.</param>
/// <param name="values">The header values.</param>
public static void SetCommaSeparatedValues(this IHeaderDictionary headers, string key, params string[] values)
{
ParsingHelpers.SetHeaderJoined(headers, key, values);
}
}
}
Loading

0 comments on commit ce4587a

Please sign in to comment.