public void Failed(HttpStatusCode statusCode, string text = null) { _requestInfo.ResponseContentType = "text/plain"; int statusCodeInt = (int)statusCode; if (text == null) { _requestInfo.WriteError(statusCodeInt); } else { _requestInfo.WriteError(statusCodeInt, text); } }
/// <summary> /// This is designed to be easily unit testable by not taking actual HttpContext, but doing everything through this IRequestInfo object /// </summary> /// <param name="info"></param> public void MakeReply(IRequestInfo info) { if (info.LocalPathWithoutQuery.EndsWith("testconnection")) { info.WriteCompleteOutput("OK"); return; } var r = info.LocalPathWithoutQuery.Replace("/bloom/", ""); r = r.Replace("%3A", ":"); r = r.Replace("%20", " "); r = r.Replace("%27", "'"); if (r.EndsWith(".png") || r.EndsWith(".jpg")) { info.ContentType = r.EndsWith(".png") ? "image/png" : "image/jpeg"; r = r.Replace("thumbnail", ""); //if (r.Contains("thumb")) { if (File.Exists(r)) { info.ReplyWithImage(_cache.GetPathToResizedImage(r)); } else { Logger.WriteEvent("**ImageServer: File Missing: " + r); info.WriteError(404); } } } }
private void ReportMissingFile(IRequestInfo info) { var localPath = GetLocalPathWithoutQuery(info); if (!IgnoreFileIfMissing(localPath)) { Logger.WriteEvent("**{0}: File Missing: {1}", GetType().Name, localPath); } info.WriteError(404); }
/// <summary> /// This is designed to be easily unit testable by not taking actual HttpContext, but doing everything through this IRequestInfo object /// </summary> /// <param name="info"></param> internal void MakeReply(IRequestInfo info) { if (!ProcessRequest(info)) { if (ShouldReportFailedRequest(info)) { ReportMissingFile(info); } info.WriteError(404); // Informing the caller is always needed. } }
/// <summary> /// This method is overridden in classes inheriting from this class to handle specific request types /// </summary> /// <param name="info"></param> /// <returns></returns> protected virtual bool ProcessRequest(IRequestInfo info) { #if MEMORYCHECK // Check memory for the benefit of developers. (Also see all requests as a side benefit.) var debugMsg = String.Format("ServerBase.ProcessRequest(\"{0}\"", info.RawUrl); SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, debugMsg, false); #endif // process request for directory index var requestedPath = GetLocalPathWithoutQuery(info); if (info.RawUrl.EndsWith("/") && (Directory.Exists(requestedPath))) { info.WriteError(403, "Directory listing denied"); return(true); } if (requestedPath.EndsWith("testconnection")) { info.WriteCompleteOutput("OK"); return(true); } return(false); }
/// <summary> /// This is designed to be easily unit testable by not taking actual HttpContext, but doing everything through this IRequestInfo object /// </summary> /// <param name="info"></param> public void MakeReply(IRequestInfo info) { if(info.LocalPathWithoutQuery.EndsWith("testconnection")) { info.WriteCompleteOutput("OK"); return; } var r = info.LocalPathWithoutQuery.Replace("/bloom/", ""); r = r.Replace("%3A", ":"); r = r.Replace("%20", " "); r = r.Replace("%27", "'"); if (r.EndsWith(".png") || r.EndsWith(".jpg")) { info.ContentType = r.EndsWith(".png") ? "image/png" : "image/jpeg"; r = r.Replace("thumbnail", ""); //if (r.Contains("thumb")) { if (File.Exists(r)) { info.ReplyWithImage(_cache.GetPathToResizedImage(r)); } else { Logger.WriteEvent("**ImageServer: File Missing: "+r); info.WriteError(404); } } } }
public void Failed(string text) { //Debug.WriteLine(this.Requestinfo.LocalPathWithoutQuery+": "+text); _requestInfo.ContentType = "text/plain"; _requestInfo.WriteError(503, text); }
private void ReportMissingFile(IRequestInfo info) { var localPath = GetLocalPathWithoutQuery(info); if (!IgnoreFileIfMissing(localPath)) Logger.WriteEvent("**{0}: File Missing: {1}", GetType().Name, localPath); info.WriteError(404); }
/// <summary> /// This method is overridden in classes inheriting from this class to handle specific request types /// </summary> /// <param name="info"></param> /// <returns></returns> protected virtual bool ProcessRequest(IRequestInfo info) { #if MEMORYCHECK // Check memory for the benefit of developers. (Also see all requests as a side benefit.) var debugMsg = String.Format("ServerBase.ProcessRequest(\"{0}\"", info.RawUrl); SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, debugMsg, false); #endif // process request for directory index var requestedPath = GetLocalPathWithoutQuery(info); if (info.RawUrl.EndsWith("/") && (Directory.Exists(requestedPath))) { info.WriteError(403, "Directory listing denied"); return true; } if (requestedPath.EndsWith("testconnection")) { info.WriteCompleteOutput("OK"); return true; } return false; }
/// <summary> /// Use this one in cases where the error has already been output to a progress box, /// and repeating the error is just noise. /// </summary> public void Failed() { _requestInfo.ContentType = "text/plain"; _requestInfo.WriteError(503); }
protected void ReportMissingFile(IRequestInfo info) { Logger.WriteEvent("**{0}: File Missing: {1}", GetType().Name, GetLocalPathWithoutQuery(info)); info.WriteError(404); }