当前位置: 首页>>代码示例>>C#>>正文


C# EntityTagHeaderValue.Equals方法代码示例

本文整理汇总了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;
	    }
开发者ID:namics,项目名称:TerrificNet,代码行数:32,代码来源:StaticFileController.cs

示例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;
        }
开发者ID:jwallra,项目名称:azure-mobile-apps-net-server-1,代码行数:30,代码来源:HttpRequestMessageExtensions.cs

示例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;
	    }
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:24,代码来源:StaticFileController.cs

示例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));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:18,代码来源:EntityTagHeaderValueTest.cs

示例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));
 }
开发者ID:jeddawson,项目名称:kudu,代码行数:8,代码来源:VfsControllerBase.cs

示例6: EtagEquals

 private static bool EtagEquals(HttpRequestMessage request, EntityTagHeaderValue currentEtag)
 {
     return request.Headers.IfNoneMatch != null &&
         request.Headers.IfNoneMatch.Any(etag => currentEtag.Equals(etag));
 }
开发者ID:GregPerez83,项目名称:kudu,代码行数:5,代码来源:DeploymentController.cs

示例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;
 }
开发者ID:hackmp,项目名称:kudu,代码行数:17,代码来源:VfsControllerBase.cs


注:本文中的System.Net.Http.Headers.EntityTagHeaderValue.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。