static void WriteDetailedError(ContextWrapper ctx, ResultDelegate result, Task<object> task) { result( "500 InternalError", new HeaderDictionary { {"Content-Type", new[] {"text/plain"}} }, (write, flush, end, cancel) => { var sb = new StringBuilder(); sb.AppendLine("Detailed error report (request came from localhost) at "+DateTime.Now); sb.AppendLine(ctx.Request.Url.ToString()); sb.Append("Faulted -- "); BuildExceptionTrace(task.Exception, sb); sb.AppendLine("Headers:"); Stringify(ctx.Request.Headers, sb); var bytes = Encoding.Default.GetBytes(sb.ToString()); write(new ArraySegment<byte>(bytes)); end(null); } ); }
static bool AccessedByNonLocalUrl(ContextWrapper ctx) { return ctx == null || (ctx.Request.Url.Host != "localhost" && ctx.Request.Url.Host != "127.0.0.1"); }