-
Notifications
You must be signed in to change notification settings - Fork 855
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
using Yarp.ReverseProxy.Configuration; | ||
using Yarp.ReverseProxy.Utilities; | ||
|
||
namespace Yarp.ReverseProxy.SessionAffinity; | ||
|
||
internal static class AffinityHelpers | ||
{ | ||
internal static CookieOptions CreateCookieOptions(SessionAffinityCookieConfig? config, bool isHttps, IClock clock) | ||
{ | ||
return new CookieOptions | ||
{ | ||
Path = config?.Path ?? "/", | ||
SameSite = config?.SameSite ?? SameSiteMode.Unspecified, | ||
HttpOnly = config?.HttpOnly ?? true, | ||
MaxAge = config?.MaxAge, | ||
Domain = config?.Domain, | ||
IsEssential = config?.IsEssential ?? false, | ||
Secure = config?.SecurePolicy == CookieSecurePolicy.Always || (config?.SecurePolicy == CookieSecurePolicy.SameAsRequest && isHttps), | ||
Expires = config?.Expiration is not null ? clock.GetUtcNow().Add(config.Expiration.Value) : default(DateTimeOffset?), | ||
}; | ||
} | ||
} |
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,40 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Yarp.ReverseProxy.SessionAffinity; | ||
|
||
internal static class Log | ||
{ | ||
private static readonly Action<ILogger, string, Exception?> _affinityCannotBeEstablishedBecauseNoDestinationsFound = LoggerMessage.Define<string>( | ||
LogLevel.Warning, | ||
EventIds.AffinityCannotBeEstablishedBecauseNoDestinationsFoundOnCluster, | ||
"The request affinity cannot be established because no destinations are found on cluster `{clusterId}`."); | ||
|
||
private static readonly Action<ILogger, Exception?> _requestAffinityKeyDecryptionFailed = LoggerMessage.Define( | ||
LogLevel.Error, | ||
EventIds.RequestAffinityKeyDecryptionFailed, | ||
"The request affinity key decryption failed."); | ||
|
||
private static readonly Action<ILogger, string, Exception?> _destinationMatchingToAffinityKeyNotFound = LoggerMessage.Define<string>( | ||
LogLevel.Warning, | ||
EventIds.DestinationMatchingToAffinityKeyNotFound, | ||
"Destination matching to the request affinity key is not found on cluster `{clusterId}`. Configured failure policy will be applied."); | ||
|
||
public static void AffinityCannotBeEstablishedBecauseNoDestinationsFound(ILogger logger, string clusterId) | ||
{ | ||
_affinityCannotBeEstablishedBecauseNoDestinationsFound(logger, clusterId, null); | ||
} | ||
|
||
public static void RequestAffinityKeyDecryptionFailed(ILogger logger, Exception? ex) | ||
{ | ||
_requestAffinityKeyDecryptionFailed(logger, ex); | ||
} | ||
|
||
public static void DestinationMatchingToAffinityKeyNotFound(ILogger logger, string clusterId) | ||
{ | ||
_destinationMatchingToAffinityKeyNotFound(logger, clusterId, null); | ||
} | ||
} |