本文整理汇总了C#中System.Net.Http.Headers.EntityTagHeaderValue.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# EntityTagHeaderValue.Equals方法的具体用法?C# EntityTagHeaderValue.Equals怎么用?C# EntityTagHeaderValue.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.Headers.EntityTagHeaderValue
的用法示例。
在下文中一共展示了EntityTagHeaderValue.Equals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInternal
protected HttpResponseMessage GetInternal(string path)
{
var pathInfo = PathInfo.Create(path);
var filePath = _fileSystem.Path.Combine(this.FilePath, pathInfo);
if (!_fileSystem.FileExists(filePath))
return new HttpResponseMessage(HttpStatusCode.NotFound);
var eTag = new EntityTagHeaderValue(string.Concat("\"", _fileSystem.GetFileInfo(filePath).Etag, "\""));
if (Request.Headers.IfNoneMatch != null)
{
foreach (var noneMatch in Request.Headers.IfNoneMatch)
{
if (eTag.Equals(noneMatch))
return new HttpResponseMessage(HttpStatusCode.NotModified);
}
}
var stream = _fileSystem.OpenRead(filePath);
var message = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
message.Content.Headers.ContentType = new MediaTypeHeaderValue(GetMimeType(_fileSystem.Path.GetExtension(pathInfo).ToLower()));
message.Headers.ETag = eTag;
// remove Pragma
message.Headers.Remove("Pragma");
message.Headers.CacheControl = new CacheControlHeaderValue {Private = true, MaxAge = TimeSpan.Zero};
message.Content.Headers.Expires = DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1));
//message.Content.Headers.LastModified
return message;
}
示例2: IsIfNoneMatch
/// <summary>
/// Checks if the request is conditional having a <c>If-None-Match</c> HTTP header field with a value that matches the
/// <paramref name="current"/> value. In the case of <c>true</c> this can be used to indicate that a
/// 304 (Not Modified) or a 412 (Precondition Failed) status code should be used.
/// </summary>
/// <param name="request">The request to match.</param>
/// <param name="current">The current etag for the resource. If there is no current etag (i.e. the resource does not yet
/// exist) then use <c>null</c>.</param>
/// <returns>Returns <c>true</c> if one of the <c>If-None-Match</c> values match the current etag; or the
/// <c>If-None-Match</c> value is "*" and <paramref name="current"/> is not null; otherwise false.</returns>
public static bool IsIfNoneMatch(this HttpRequestMessage request, EntityTagHeaderValue current)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
if (request.Headers.IfNoneMatch != null)
{
foreach (EntityTagHeaderValue etag in request.Headers.IfNoneMatch)
{
if (current != null && (etag == EntityTagHeaderValue.Any || current.Equals(etag)))
{
return true;
}
}
}
return false;
}
示例3: GetInternal
protected HttpResponseMessage GetInternal(string path)
{
var pathInfo = PathInfo.Create(path);
var filePath = _fileSystem.Path.Combine(this.FilePath, pathInfo);
if (!_fileSystem.FileExists(filePath))
return new HttpResponseMessage(HttpStatusCode.NotFound);
var eTag = new EntityTagHeaderValue(string.Concat("\"", _fileSystem.GetFileInfo(filePath).Etag, "\""));
if (Request.Headers.IfNoneMatch != null)
{
foreach (var noneMatch in Request.Headers.IfNoneMatch)
{
if (eTag.Equals(noneMatch))
return new HttpResponseMessage(HttpStatusCode.NotModified);
}
}
var stream = _fileSystem.OpenRead(filePath);
var message = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
message.Content.Headers.ContentType = new MediaTypeHeaderValue(GetMimeType(_fileSystem.Path.GetExtension(pathInfo).ToLower()));
message.Headers.ETag = eTag;
return message;
}
示例4: Equals_UseSameAndDifferentETags_EqualOrNotEqualNoExceptions
public void Equals_UseSameAndDifferentETags_EqualOrNotEqualNoExceptions()
{
EntityTagHeaderValue etag1 = new EntityTagHeaderValue("\"tag\"");
EntityTagHeaderValue etag2 = new EntityTagHeaderValue("\"TAG\"");
EntityTagHeaderValue etag3 = new EntityTagHeaderValue("\"tag\"", true);
EntityTagHeaderValue etag4 = new EntityTagHeaderValue("\"tag1\"");
EntityTagHeaderValue etag5 = new EntityTagHeaderValue("\"tag\"");
EntityTagHeaderValue etag6 = EntityTagHeaderValue.Any;
Assert.False(etag1.Equals(etag2));
Assert.False(etag2.Equals(etag1));
Assert.False(etag1.Equals(null));
Assert.False(etag1.Equals(etag3));
Assert.False(etag3.Equals(etag1));
Assert.False(etag1.Equals(etag4));
Assert.False(etag1.Equals(etag6));
Assert.True(etag1.Equals(etag5));
}
示例5: IsIfNoneMatchRequest
/// <summary>
/// Indicates whether this is a If-None-Match request with a matching etag.
/// </summary>
protected bool IsIfNoneMatchRequest(EntityTagHeaderValue currentEtag)
{
return currentEtag != null && Request.Headers.IfNoneMatch != null &&
Request.Headers.IfNoneMatch.Any(entityTag => currentEtag.Equals(entityTag));
}
示例6: EtagEquals
private static bool EtagEquals(HttpRequestMessage request, EntityTagHeaderValue currentEtag)
{
return request.Headers.IfNoneMatch != null &&
request.Headers.IfNoneMatch.Any(etag => currentEtag.Equals(etag));
}
示例7: IsRangeRequest
/// <summary>
/// Indicates whether this is a conditional range request containing an
/// If-Range header with a matching etag and a Range header indicating the
/// desired ranges
/// </summary>
protected bool IsRangeRequest(EntityTagHeaderValue currentEtag)
{
if (currentEtag != null && Request.Headers.IfRange != null && Request.Headers.Range != null)
{
// First check that the etag matches so that we can consider the range request
if (currentEtag.Equals(Request.Headers.IfRange.EntityTag))
{
return true;
}
}
return false;
}