|
12 | 12 | using Microsoft.AspNetCore.Mvc.Formatters;
|
13 | 13 | using Microsoft.AspNetCore.WebUtilities;
|
14 | 14 | using Microsoft.Azure.WebJobs.Script.WebHost.Formatters;
|
| 15 | +using Microsoft.Net.Http.Headers; |
15 | 16 | using Newtonsoft.Json;
|
16 | 17 |
|
17 | 18 | namespace Microsoft.Azure.WebJobs.Script.Binding
|
@@ -45,16 +46,27 @@ public async Task ExecuteResultAsync(ActionContext context)
|
45 | 46 | {
|
46 | 47 | foreach (var header in Headers)
|
47 | 48 | {
|
48 |
| - response.Headers.Add(header.Key, header.Value?.ToString() ?? string.Empty); |
| 49 | + if (header.Key.Equals("content-type", StringComparison.OrdinalIgnoreCase)) |
| 50 | + { |
| 51 | + if (header.Value == null) |
| 52 | + { |
| 53 | + throw new InvalidOperationException("content-type header cannot be null"); |
| 54 | + } |
| 55 | + response.ContentType = header.Value.ToString(); |
| 56 | + } |
| 57 | + else |
| 58 | + { |
| 59 | + response.Headers.Add(header.Key, header.Value?.ToString() ?? string.Empty); |
| 60 | + } |
49 | 61 | }
|
50 | 62 | }
|
51 | 63 |
|
52 |
| - await WriteResponseBodyAsync(response, Content); |
53 |
| - |
54 | 64 | if (StatusCode != null)
|
55 | 65 | {
|
56 | 66 | response.StatusCode = StatusCode.Value;
|
57 | 67 | }
|
| 68 | + |
| 69 | + await WriteResponseBodyAsync(response, Content); |
58 | 70 | }
|
59 | 71 |
|
60 | 72 | private async Task WriteResponseBodyAsync(HttpResponse response, object content)
|
@@ -83,11 +95,15 @@ private async Task WriteResponseBodyAsync(HttpResponse response, object content)
|
83 | 95 |
|
84 | 96 | private static OutputFormatterWriteContext CreateFormatterContext(HttpResponse response, object content)
|
85 | 97 | {
|
86 |
| - return new OutputFormatterWriteContext( |
| 98 | + var context = new OutputFormatterWriteContext( |
87 | 99 | response.HttpContext,
|
88 | 100 | (s, e) => new HttpResponseStreamWriter(s, e),
|
89 | 101 | content?.GetType(),
|
90 | 102 | content);
|
| 103 | + |
| 104 | + context.ContentType = response.ContentType; |
| 105 | + |
| 106 | + return context; |
91 | 107 | }
|
92 | 108 |
|
93 | 109 | private static IOutputFormatter SelectedFormatter(OutputFormatterWriteContext formatterContext)
|
|
0 commit comments