Exemple #1
0
        public void SendFileResponse(HttpListenerContext context)
        {
            string url = context.Request.RawUrl;

            if (!FileExists(url))
            {
                return;
            }

            FileInfo fileInfo     = new FileInfo(GetFullPath(url));
            string   lastModified = fileInfo.LastWriteTime.ToString("R");

            if (RequestParser.LastModifiedSinceEquals(context.Request, lastModified))
            {
                responseWriter.SendNotModified(context.Response);
            }
            else
            {
                SendFileContent(context, fileInfo);
            }
        }
Exemple #2
0
        private void SendFileContent(HttpListenerContext context, FileInfo fileInfo)
        {
            byte[]      fileContent  = GetContent(fileInfo);
            ContentType contentType  = GetContentType(fileInfo.Extension);
            string      lastModified = fileInfo.LastWriteTime.ToString("R");
            string      expires      = fileInfo.LastWriteTime.AddHours(23).ToString("R");

            responseWriter.AddLastModifiedAndExpires(context.Response, lastModified,
                                                     expires);

            if (RequestParser.GzipCanBeUsed(context.Request) &&
                fileContent.Length > 1024)
            {
                responseWriter.SendZippedResponse(context.Response,
                                                  new ByteResponseData(fileContent,
                                                                       contentType));
            }
            else
            {
                responseWriter.SendResponse(context.Response,
                                            new ByteResponseData(fileContent,
                                                                 contentType));
            }
        }