|
3 | 3 | using System.Web;
|
4 | 4 | using System.Web.Hosting;
|
5 | 5 | using System.Reflection;
|
| 6 | +using System.Diagnostics; |
6 | 7 | using System.Threading;
|
7 | 8 | using System.Threading.Tasks;
|
8 | 9 | using System.Collections.Concurrent;
|
@@ -107,22 +108,29 @@ public override async Task ProcessRequestAsync(HttpContext ctx)
|
107 | 108 |
|
108 | 109 | if (tsource?.Task == task)
|
109 | 110 | {
|
110 |
| - ctx.Trace.Write("ProcessImage Begin"); |
| 111 | + ctx.Trace.Write(nameof(WebRSize), $"{nameof(MagicImageProcessor.ProcessImage)} Begin"); |
111 | 112 | await process(tsource, ctx.Request.Path, cachePath, s);
|
112 |
| - ctx.Trace.Write("ProcessImage End"); |
| 113 | + ctx.Trace.Write(nameof(WebRSize), $"{nameof(MagicImageProcessor.ProcessImage)} End"); |
113 | 114 | }
|
114 | 115 |
|
115 |
| - var res = await task; |
| 116 | + var img = await task; |
| 117 | + var res = ctx.Response; |
116 | 118 |
|
117 |
| - if (!ctx.Response.IsClientConnected) |
| 119 | + if (!res.IsClientConnected) |
118 | 120 | return;
|
119 | 121 |
|
120 |
| - ctx.Response.BufferOutput = false; |
121 |
| - ctx.Response.ContentType = MimeMapping.GetMimeMapping(Path.GetFileName(cachePath)); |
122 |
| - ctx.Response.AddHeader("Content-Length", res.Count.ToString()); |
123 |
| - ctx.Response.Cache.SetLastModifiedFromFileDependencies(); |
| 122 | + try |
| 123 | + { |
| 124 | + res.BufferOutput = false; |
| 125 | + res.ContentType = MimeMapping.GetMimeMapping(Path.GetFileName(cachePath)); |
| 126 | + res.AddHeader("Content-Length", img.Count.ToString()); |
124 | 127 |
|
125 |
| - await ctx.Response.OutputStream.WriteAsync(res.Array, res.Offset, res.Count); |
| 128 | + await res.OutputStream.WriteAsync(img.Array, img.Offset, img.Count); |
| 129 | + } |
| 130 | + catch (HttpException ex) when (new StackTrace(ex).GetFrame(0)?.GetMethod().Name == "RaiseCommunicationError") |
| 131 | + { |
| 132 | + // no problem here. client just disconnected before transmission completed. |
| 133 | + } |
126 | 134 | }
|
127 | 135 |
|
128 | 136 | public override bool IsReusable => true;
|
|
0 commit comments