Ejemplo n.º 1
0
        /// <summary>
        /// Handles correlation ID forwarding.
        /// </summary>
        /// <param name="requestHeaders">HTTP request headers.</param>
        /// <returns>
        /// HTTP request headers containing correlation ID (or unchanged, if forwarding not set).
        /// </returns>
        private HttpRequestHeaders HandleCorrelationIdForwarding(HttpRequestHeaders requestHeaders)
        {
            if (_settings.Settings == HeaderPropagation.NoPropagation)
            {
                return(requestHeaders);
            }

            var correlationContext = _correlationContextAccessor.CorrelationContext;

            return((_settings.Settings, correlationContext) switch
            {
                (HeaderPropagation.UsePredefinedHeaderName, _) =>
                requestHeaders.AddHeaderIfNotSet(
                    _settings.HeaderName,
                    correlationContext.CorrelationId),

                (HeaderPropagation.KeepIncomingHeaderName, RequestCorrelationContext requestCorrelationContext) =>
                requestHeaders.AddHeaderIfNotSet(
                    requestCorrelationContext.Header,
                    requestCorrelationContext.CorrelationId),

                (HeaderPropagation.KeepIncomingHeaderName, GeneratedCorrelationContext generatedCorrelationContext) =>
                requestHeaders.AddHeaderIfNotSet(
                    _settings.HeaderName,
                    generatedCorrelationContext.CorrelationId),

                _ => requestHeaders,
            });