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); } }
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)); } }