Пример #1
0
        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);
            }
        }
Пример #2
0
        /// <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);
                    }
                }
            }
        }
Пример #3
0
        private void ReportMissingFile(IRequestInfo info)
        {
            var localPath = GetLocalPathWithoutQuery(info);

            if (!IgnoreFileIfMissing(localPath))
            {
                Logger.WriteEvent("**{0}: File Missing: {1}", GetType().Name, localPath);
            }
            info.WriteError(404);
        }
Пример #4
0
 /// <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.
     }
 }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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);
                    }
                }

            }
        }
Пример #7
0
 public void Failed(string text)
 {
     //Debug.WriteLine(this.Requestinfo.LocalPathWithoutQuery+": "+text);
     _requestInfo.ContentType = "text/plain";
     _requestInfo.WriteError(503, text);
 }
Пример #8
0
 private void ReportMissingFile(IRequestInfo info)
 {
     var localPath = GetLocalPathWithoutQuery(info);
     if (!IgnoreFileIfMissing(localPath))
         Logger.WriteEvent("**{0}: File Missing: {1}", GetType().Name, localPath);
     info.WriteError(404);
 }
Пример #9
0
        /// <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;
        }
Пример #10
0
 /// <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);
 }
Пример #11
0
 protected void ReportMissingFile(IRequestInfo info)
 {
     Logger.WriteEvent("**{0}: File Missing: {1}", GetType().Name, GetLocalPathWithoutQuery(info));
     info.WriteError(404);
 }