public async Task ExecuteResultAsync(ActionContext context) { HttpResponse response = context.HttpContext.Response; if (Headers != null) { foreach (var header in Headers) { if (header.Key.Equals("content-type", StringComparison.OrdinalIgnoreCase)) { if (header.Value == null) { throw new InvalidOperationException("content-type header cannot be null"); } response.ContentType = header.Value.ToString(); } else { if (response.Headers.ContainsKey(header.Key)) { Utility.AccumulateDuplicateHeader(response.HttpContext, header.Key); } else { response.Headers.Add(header.Key, header.Value.ToString() ?? string.Empty); } } } } if (StatusCode != null) { response.StatusCode = StatusCode.Value; } if (Cookies != null) { foreach (var cookie in Cookies) { if (cookie.Item3 != null) { response.Cookies.Append(cookie.Item1, cookie.Item2, cookie.Item3); } else { response.Cookies.Append(cookie.Item1, cookie.Item2); } } } await WriteResponseBodyAsync(response, Content); }
internal void AddResponseHeaders(HttpContext context) { HttpResponse response = context.Response; if (Headers != null) { foreach (var header in Headers) { if (response.Headers.ContainsKey(header.Key)) { Utility.AccumulateDuplicateHeader(response.HttpContext, header.Key); } else { response.Headers.Add(header.Key, header.Value.ToString() ?? string.Empty); } } } }