getGuessFileType() public méthode

public getGuessFileType ( ) : string
Résultat string
Exemple #1
0
        /// <summary>
        /// This method checks that the request path exists in the PAGE_ROOT directory.
        /// Then the content-type is parsed from the request.
        /// An HttpRequest is generated and sent, followed by the file specified.
        /// Call this method conditionally from any subclass unless there are no conditions as to what clients are permitted to GET.
        /// </summary>
        /// <param name="request"></param>
        protected virtual bool processGet(HttpRequest request)
        {
            String relativePath = request.Path;

            if (relativePath.IndexOf('/') == 0)
            {
                relativePath = relativePath.Substring(1);
            }
            HttpResponse response;

            //Keep in mind that File.OpenRead defaultly uses FileShare.Read
            #region "File Checks and Response Generation"
            if (File.Exists(PAGE_ROOT + relativePath))
            {
                String Content = request.requestMetaInfo("Accept");
                response = new HttpResponse(HttpResponse.ConnectionStatus.OK, "keep-alive", PAGE_ROOT + relativePath);
                response.addHeader("Content-Type", request.getGuessFileType());
            }
            else
            {
                if (request.Path.Equals("/"))
                {
                    response = new HttpResponse(HttpResponse.ConnectionStatus.OK, "keep-alive", PAGE_ROOT + @"\" + onInit(request));
                    response.addHeader("Content-Type", "text/html");
                }
                else
                {
                    on404(request);
                    return(false);
                }
            }
            #endregion


            using (FileStream s = File.OpenRead(response.FilePath))
            {
                response.addHeader("Content-Length", s.Length.ToString());
                try
                {
                    SocketWriteLine(response.ToString());
                    s.CopyTo(stream);
                }
                catch (SocketException)
                {
                    return(false);
                }
                catch (IOException)
                {
                    return(false);
                }
            }
            //}
            //catch (IOException e)
            //{
            //    Debug.WriteLine("send failure:  " + request.path);
            //}

            stream.Flush();
            return(true);
        }
        /// <summary>
        /// This method checks that the request path exists in the PAGE_ROOT directory.
        /// Then the content-type is parsed from the request.
        /// An HttpRequest is generated and sent, followed by the file specified.
        /// Call this method conditionally from any subclass unless there are no conditions as to what clients are permitted to GET.
        /// </summary>
        /// <param name="request"></param>
        protected virtual bool processGet(HttpRequest request)
        {
            String relativePath = request.Path;
            if (relativePath.IndexOf('/') == 0)
            {
                relativePath = relativePath.Substring(1);
            }
            HttpResponse response;

            //Keep in mind that File.OpenRead defaultly uses FileShare.Read
            #region "File Checks and Response Generation"
            if (File.Exists(PAGE_ROOT + relativePath))
            {
                String Content = request.requestMetaInfo("Accept");
                response = new HttpResponse(HttpResponse.ConnectionStatus.OK, "keep-alive", PAGE_ROOT + relativePath);
                response.addHeader("Content-Type", request.getGuessFileType());
            }
            else
            {
                if (request.Path.Equals("/"))
                {
                    response = new HttpResponse(HttpResponse.ConnectionStatus.OK, "keep-alive", PAGE_ROOT + @"\" + onInit(request));
                    response.addHeader("Content-Type", "text/html");
                }
                else
                {
                    on404(request);
                    return false;
                }
            }
            #endregion

            using (FileStream s = File.OpenRead(response.FilePath))
            {
                response.addHeader("Content-Length", s.Length.ToString());
                try
                {
                    SocketWriteLine(response.ToString());
                    s.CopyTo(stream);
                }
                catch (SocketException)
                {
                    return false;
                }
                catch (IOException)
                {
                    return false;
                }
            }
            //}
            //catch (IOException e)
            //{
            //    Debug.WriteLine("send failure:  " + request.path);
            //}

            stream.Flush();
            return true;
        }