本文整理汇总了C#中IHttpRequest.IsAcceptGZip方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.IsAcceptGZip方法的具体用法?C# IHttpRequest.IsAcceptGZip怎么用?C# IHttpRequest.IsAcceptGZip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpRequest
的用法示例。
在下文中一共展示了IHttpRequest.IsAcceptGZip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public HttpResponse Handle(IHttpRequest req)
{
var requestedFilename = HttpUtility.UrlDecode(req.Path.Substring(reqPathFilenameStartIndex));
var absFilename = Path.GetFullPath(Path.Combine(directory, requestedFilename));
if (!absFilename.StartsWith(directory))
{
return Forbidden;
}
var fileInfo = new FileInfo(absFilename);
if (!fileInfo.Exists) // cached but deleted
{
return NotFound;
}
DateTime ifModifiedSince;
CachedFile cachedFile;
HttpResponse response;
if (req.TryGetIfLastModifiedSince(out ifModifiedSince) && fileInfo.LastWriteTimeUtc <= ifModifiedSince)
{
// Remote client (browser) has a valid cached copy (we may not have it in cache yet though eg. server restarted)
response = new HttpResponse(HttpStatusCode.NotModified, MimeMapping.GetMimeMapping(fileInfo.Name));
}
else if (cache.TryGetValue(absFilename, out cachedFile) && fileInfo.LastWriteTimeUtc <= cachedFile.LastModified)
{
// Dictionary cached copy is still valid
response = req.IsAcceptGZip() ? cachedFile.GZippedResponse : cachedFile.Response;
}
else
{
// Load fresh from disk
if (fileInfo.Length <= maxFileLengthToCache)
{
var fileResponse = new FileResponse.Buffered(fileInfo);
var gzippedFileResponse = gzipFunc(fileResponse);
cache[absFilename] = new CachedFile(fileResponse, gzippedFileResponse);
response = req.IsAcceptGZip() ? gzippedFileResponse : fileResponse;
}
else
{
response = new FileResponse.Stream(fileInfo);
}
}
return response;
}
示例2: Handle
public HttpResponse Handle(IHttpRequest req)
{
var fullName = GetFileFullName(req);
var fileInfo = new FileInfo(fullName);
if (!fileInfo.Exists) // cached but deleted
{
return NotFound;
}
DateTime ifModifiedSince;
CachedFile cachedFile;
var checkLastModified = req.TryGetIfLastModifiedSince(out ifModifiedSince); // remote client has a cached version
var hasCachedResponse = checkLastModified ? TryGetCachedFileResponse(fullName, ifModifiedSince, out cachedFile) : TryGetCachedFileResponse(fullName, out cachedFile);
if (hasCachedResponse && fileInfo.LastWriteTimeUtc <= cachedFile.LastModified)
{
if (checkLastModified)
{
return NotChanged(cachedFile.ContentType);
}
else
{
return req.IsAcceptGZip() && cachedFile.GZippedResponse != null ? cachedFile.GZippedResponse : cachedFile.Response;
}
}
else
{
var fileResponse = new FileResponse(fileInfo);
cachedFile = new CachedFile(fileResponse, gzipFunc != null ? fileResponse.GZip(gzipFunc) : null);
cache[fullName] = cachedFile;
return req.IsAcceptGZip() && cachedFile.GZippedResponse != null ? cachedFile.GZippedResponse : cachedFile.Response;
}
}