Exemplo n.º 1
0
        private bool GetFileResponse(string fileAbsPath, HttpResponse httpResponse)
        {
            if (!File.Exists(fileAbsPath))
            {
                return(false);
            }
            string ext = Path.GetExtension(fileAbsPath);

            if (ext.Length > 0)
            {
                ext = ext.Substring(1);
            }

            httpResponse.ContentType = MIMETypeRegistry.Instance.TranslateToMIME(ext);
            if (MIMETypeRegistry.GetMIMEType(httpResponse.ContentType) == HttpServer.Common.MIMEType.TEXT)
            {
                httpResponse.ContentCharset = "utf-8";
            }

            using (FileStream fr = new FileStream(fileAbsPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                if (ServerContext.ServerConfig.ChunkedModeThershold < 0 ||
                    fr.Length < ServerContext.ServerConfig.ChunkedModeThershold)
                {
                    httpResponse.ResponseDataStream.CopyFrom(fr);
                }
                else
                {
                    ChunkedStream outputStream = httpResponse.GetChunckedOutputStream();
                    outputStream.CopyFrom(fr);
                }
            }
            return(true);
        }