/// <summary>
        /// Copies all details from the source to the current response.
        /// </summary>
        public static async Task CopyToCurrentContext(this HttpResponseMessage source, HttpContext context)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Response.StatusCode = (int)source.StatusCode;

            foreach (var header in source.Headers)
            {
                if (!_ignoredResponseHeaders.Contains(header.Key))
                {
                    context.Response.Headers[header.Key] = header.Value.ToArray();
                }
            }

            foreach (var header in source.Content.Headers)
            {
                if (!_ignoredResponseHeaders.Contains(header.Key))
                {
                    context.Response.Headers[header.Key] = header.Value.ToArray();
                }
            }

            context.AddResponseProxyHeaders();

            await source.Content.CopyToAsync(context.Response.Body);
        }
Esempio n. 2
0
        public static async Task CopyToCurrentContext(this HttpResponseMessage source, HttpContext context)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Response.StatusCode = (int)source.StatusCode;

            foreach (var header in source.Headers.Where(header => !IgnoredResponseHeaders.Contains(header.Key)))
            {
                context.Response.Headers[header.Key] = header.Value.ToArray();
            }

            foreach (var header in source.Content.Headers.Where(header => !IgnoredResponseHeaders.Contains(header.Key)))
            {
                context.Response.Headers[header.Key] = header.Value.ToArray();
            }

            context.AddResponseProxyHeaders();

            // todo huh ?
            if (context.Response.Body == null)
            {
                context.Response.StatusCode = 666;
                return;
            }

            await source.Content.CopyToAsync(context.Response.Body).ConfigureAwait(false);
        }
        /// <summary>
        /// Copies all details from the source to the current response.
        /// </summary>
        public static async Task CopyToCurrentContext(this HttpResponseMessage source, HttpContext context)
        {
            if (source == null)
                throw new ArgumentNullException(nameof(source));

            if (context == null)
                throw new ArgumentNullException(nameof(context));

            context.Response.StatusCode = (int)source.StatusCode;

            foreach (var header in source.Headers)
            {
                if (!_ignoredResponseHeaders.Contains(header.Key))
                {
                    context.Response.Headers[header.Key] = header.Value.ToArray();
                }
            }

            foreach (var header in source.Content.Headers)
            {
                if (!_ignoredResponseHeaders.Contains(header.Key))
                {
                    context.Response.Headers[header.Key] = header.Value.ToArray();
                }
            }

            context.AddResponseProxyHeaders();

            await source.Content.CopyToAsync(context.Response.Body);
        }