-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved usability
- Loading branch information
Showing
17 changed files
with
397 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace HeaderPropagation | ||
{ | ||
/// <summary> | ||
/// A context object for <see cref="HeaderPropagationEntry.ValueFilter"/> delegates. | ||
/// </summary> | ||
public struct HeaderPropagationContext | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="HeaderPropagationContext"/> with the provided | ||
/// <paramref name="httpContext"/>, <paramref name="headerName"/> and <paramref name="headerValue"/>. | ||
/// </summary> | ||
/// <param name="httpContext">The <see cref="Microsoft.AspNetCore.Http.HttpContext"/> associated with the current request.</param> | ||
/// <param name="headerName">The header name.</param> | ||
/// <param name="headerValue">The header value present in the current request.</param> | ||
public HeaderPropagationContext(HttpContext httpContext, string headerName, StringValues headerValue) | ||
{ | ||
if (httpContext == null) | ||
{ | ||
throw new ArgumentNullException(nameof(httpContext)); | ||
} | ||
|
||
if (headerName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(headerName)); | ||
} | ||
|
||
HttpContext = httpContext; | ||
HeaderName = headerName; | ||
HeaderValue = headerValue; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="Microsoft.AspNetCore.Http.HttpContext"/> associated with the current request. | ||
/// </summary> | ||
public HttpContext HttpContext { get; } | ||
|
||
/// <summary> | ||
/// Gets the header name. | ||
/// </summary> | ||
public string HeaderName { get; } | ||
|
||
/// <summary> | ||
/// Gets the header value from the current request. | ||
/// </summary> | ||
public StringValues HeaderValue { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// 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.Collections.ObjectModel; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace HeaderPropagation | ||
{ | ||
/// <summary> | ||
/// A collection of <see cref="HeaderPropagationEntry"/> items. | ||
/// </summary> | ||
public sealed class HeaderPropagationEntryCollection : Collection<HeaderPropagationEntry> | ||
{ | ||
/// <summary> | ||
/// Adds an <see cref="HeaderPropagationEntry"/> that will use <paramref name="headerName"/> as | ||
/// the value of <see cref="HeaderPropagationEntry.InboundHeaderName"/> and | ||
/// <see cref="HeaderPropagationEntry.OutboundHeaderName"/>. | ||
/// </summary> | ||
/// <param name="headerName">The header name to be propagated.</param> | ||
public void Add(string headerName) | ||
{ | ||
if (headerName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(headerName)); | ||
} | ||
|
||
Add(new HeaderPropagationEntry(headerName, headerName, valueFilter: null)); | ||
} | ||
|
||
/// <summary> | ||
/// Adds an <see cref="HeaderPropagationEntry"/> that will use <paramref name="headerName"/> as | ||
/// the value of <see cref="HeaderPropagationEntry.InboundHeaderName"/> and | ||
/// <see cref="HeaderPropagationEntry.OutboundHeaderName"/>. | ||
/// </summary> | ||
/// <param name="headerName">The header name to be propagated.</param> | ||
/// <param name="valueFilter"> | ||
/// A filter delegate that can be used to transform the header value. | ||
/// <see cref="HeaderPropagationEntry.ValueFilter"/>. | ||
/// </param> | ||
public void Add(string headerName, Func<HeaderPropagationContext, StringValues> valueFilter) | ||
{ | ||
if (headerName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(headerName)); | ||
} | ||
|
||
Add(new HeaderPropagationEntry(headerName, headerName, valueFilter)); | ||
} | ||
|
||
/// <summary> | ||
/// Adds an <see cref="HeaderPropagationEntry"/> that will use the provided <paramref name="inboundHeaderName"/> | ||
/// and <paramref name="outboundHeaderName"/>. | ||
/// </summary> | ||
/// <param name="inboundHeaderName"> | ||
/// The name of the header to be captured by <see cref="HeaderPropagationMiddleware"/>. | ||
/// </param> | ||
/// <param name="outboundHeaderName"> | ||
/// The name of the header to be added by <see cref="HeaderPropagationMessageHandler"/>. | ||
/// </param> | ||
public void Add(string inboundHeaderName, string outboundHeaderName) | ||
{ | ||
if (inboundHeaderName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(inboundHeaderName)); | ||
} | ||
|
||
if (outboundHeaderName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(outboundHeaderName)); | ||
} | ||
|
||
Add(new HeaderPropagationEntry(inboundHeaderName, outboundHeaderName, valueFilter: null)); | ||
} | ||
|
||
/// <summary> | ||
/// Adds an <see cref="HeaderPropagationEntry"/> that will use the provided <paramref name="inboundHeaderName"/>, | ||
/// <paramref name="outboundHeaderName"/>, and <paramref name="valueFilter"/>. | ||
/// </summary> | ||
/// <param name="inboundHeaderName"> | ||
/// The name of the header to be captured by <see cref="HeaderPropagationMiddleware"/>. | ||
/// </param> | ||
/// <param name="outboundHeaderName"> | ||
/// The name of the header to be added by <see cref="HeaderPropagationMessageHandler"/>. | ||
/// </param> | ||
/// <param name="valueFilter"> | ||
/// A filter delegate that can be used to transform the header value. | ||
/// <see cref="HeaderPropagationEntry.ValueFilter"/>. | ||
/// </param> | ||
public void Add( | ||
string inboundHeaderName, | ||
string outboundHeaderName, | ||
Func<HeaderPropagationContext, StringValues> valueFilter) | ||
{ | ||
if (inboundHeaderName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(inboundHeaderName)); | ||
} | ||
|
||
if (outboundHeaderName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(outboundHeaderName)); | ||
} | ||
|
||
Add(new HeaderPropagationEntry(inboundHeaderName, outboundHeaderName, valueFilter)); | ||
} | ||
} | ||
} |
Oops, something went wrong.