• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Headers.EntityTagHeaderValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Net.Http.Headers.EntityTagHeaderValue的典型用法代码示例。如果您正苦于以下问题:C# EntityTagHeaderValue类的具体用法?C# EntityTagHeaderValue怎么用?C# EntityTagHeaderValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EntityTagHeaderValue类属于System.Net.Http.Headers命名空间,在下文中一共展示了EntityTagHeaderValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RangeConditionHeaderValue

		public RangeConditionHeaderValue (EntityTagHeaderValue entityTag)
		{
			if (entityTag == null)
				throw new ArgumentNullException ("entityTag");

			EntityTag = entityTag;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:RangeConditionHeaderValue.cs


示例2: EntityTagHeaderValue

        private EntityTagHeaderValue(EntityTagHeaderValue source)
        {
            Contract.Requires(source != null);

            _tag = source._tag;
            _isWeak = source._isWeak;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:EntityTagHeaderValue.cs


示例3: EntityTagHeaderValue

        private EntityTagHeaderValue(EntityTagHeaderValue source)
        {
            Contract.Requires(source != null);

            this.tag = source.tag;
            this.isWeak = source.isWeak;
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:7,代码来源:EntityTagHeaderValue.cs


示例4: OnActionExecuted

        /// <summary>
        /// The on action executed.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        public override void OnActionExecuted(HttpActionExecutedContext context)
        {
            var request = context.Request;
            var key = GetKey(request);

            EntityTagHeaderValue etag = null;

            bool isGet = request.Method == HttpMethod.Get;
            bool isPutOrPost = request.Method == HttpMethod.Put || request.Method == HttpMethod.Post;

            if (isPutOrPost)
            {
                ////empty the dictionary because the resource has been changed.So now all tags will be cleared and data
                //// will be fetched from server. It would be good to implement a logic in which only change the ETags
                //// of that urls which are affected by this post or put method rather than clearing entire dictionary
                     etags.Clear();
                //// generate new ETag for Put or Post because the resource is changed.
                    etag = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
                    etags.AddOrUpdate(key, etag, (k, val) => etag);

            }
            //if ((isGet && !etags.TryGetValue(key, out etag)) || isPutOrPost)
            //{
            //    //// generate new ETag for Put or Post because the resource is changed.
            //    etag = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
            //    etags.AddOrUpdate(key, etag, (k, val) => etag);
            //}

            if (isGet)
            {
                context.Response.Headers.ETag = etag;
            }
        }
开发者ID:sandipuchdadiya,项目名称:QTecApp,代码行数:39,代码来源:ETagAttribute.cs


示例5: 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


示例6: ParseETag

        public IDictionary<string, object> ParseETag(EntityTagHeaderValue etagHeaderValue)
        {
            if (etagHeaderValue == null)
            {
                throw Error.ArgumentNull("etagHeaderValue");
            }

            string tag = etagHeaderValue.Tag.Trim('\"');

            // split etag
            string[] rawValues = tag.Split(Separator);
            IDictionary<string, object> properties = new Dictionary<string, object>();
            for (int index = 0; index < rawValues.Length; index++)
            {
                string rawValue = rawValues[index];

                // base64 decode
                byte[] bytes = Convert.FromBase64String(rawValue);
                string valueString = Encoding.UTF8.GetString(bytes);
                object obj = ODataUriUtils.ConvertFromUriLiteral(valueString, ODataVersion.V3);
                if (obj is ODataUriNullValue)
                {
                    obj = null;
                }
                properties.Add(index.ToString(CultureInfo.InvariantCulture), obj);
            }

            return properties;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:29,代码来源:DefaultODataETagHandler.cs


示例7: EntityTagHeaderValue

        private EntityTagHeaderValue(EntityTagHeaderValue source)
        {
            Debug.Assert(source != null);

            _tag = source._tag;
            _isWeak = source._isWeak;
        }
开发者ID:Corillian,项目名称:corefx,代码行数:7,代码来源:EntityTagHeaderValue.cs


示例8: Equals

 public void Equals()
 {
     var tfhv = new EntityTagHeaderValue ("\"abc\"");
     Assert.AreEqual (tfhv, new EntityTagHeaderValue ("\"abc\""), "#1");
     Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AbC\""), "#2");
     Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AA\""), "#3");
 }
开发者ID:RainsSoft,项目名称:dotnet-httpclient35,代码行数:7,代码来源:EntityTagHeaderValueTest.cs


示例9: NotModifiedResponse

        public NotModifiedResponse(HttpRequestMessage request, EntityTagHeaderValue etag)
            : base(HttpStatusCode.NotModified)
        {
            if(etag!=null)
                this.Headers.ETag = etag;

            this.RequestMessage = request;
        }
开发者ID:erpframework,项目名称:CacheCow,代码行数:8,代码来源:NotModifiedResponse.cs


示例10: RangeConditionHeaderValue

        public RangeConditionHeaderValue(EntityTagHeaderValue entityTag)
        {
            if (entityTag == null)
            {
                throw new ArgumentNullException(nameof(entityTag));
            }

            _entityTag = entityTag;
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:9,代码来源:RangeConditionHeaderValue.cs


示例11: SendAsync

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Method == HttpMethod.Get)
            {
                // should we ignore trailing slash
                var resource = request.RequestUri.ToString();

                ICollection<EntityTagHeaderValue> etags = request.Headers.IfNoneMatch;
                // compare the Etag with the one in the cache
                // do conditional get.
                EntityTagHeaderValue actualEtag = null;
                if (etags.Count > 0 && ETagHandler.ETagCache.TryGetValue(resource, out actualEtag))
                {
                    if (etags.Any(etag => etag.Tag == actualEtag.Tag))
                    {
                        return Task.Factory.StartNew<HttpResponseMessage>(task => new NotModifiedResponse(), cancellationToken);
                    }
                }
            }
            else if (request.Method == HttpMethod.Put)
            {
                // should we ignore trailing slash
                var resource = request.RequestUri.ToString();

                ICollection<EntityTagHeaderValue> etags = request.Headers.IfMatch;
                // compare the Etag with the one in the cache
                // do conditional get.

                EntityTagHeaderValue actualEtag = null;
                if (etags.Count > 0 && ETagHandler.ETagCache.TryGetValue(resource, out actualEtag))
                {
                    var matchFound = etags.Any(etag => etag.Tag == actualEtag.Tag);

                    if (!matchFound)
                    {
                        return Task.Factory.StartNew<HttpResponseMessage>(task => new ConflictResponse(), cancellationToken);
                    }
                }
            }
            return base.SendAsync(request, cancellationToken).ContinueWith(task =>
            {
                var httpResponse = task.Result;
                var eTagKey = request.RequestUri.ToString();
                EntityTagHeaderValue eTagValue;

                // Post would invalidate the collection, put should invalidate the individual item
                if (!ETagCache.TryGetValue(eTagKey, out eTagValue) || request.Method == HttpMethod.Put || request.Method == HttpMethod.Post)
                {
                    eTagValue = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
                    ETagCache.AddOrUpdate(eTagKey, eTagValue, (key, existingVal) => eTagValue);
                }
                httpResponse.Headers.ETag = eTagValue;

                return httpResponse;
            });
        }
开发者ID:BiaoLiu,项目名称:osharp,代码行数:56,代码来源:ETagHandler.cs


示例12: SetEntityTagHeader

        public static void SetEntityTagHeader(this HttpResponseMessage httpResponseMessage, EntityTagHeaderValue etag, DateTime lastModified)
        {
            if (httpResponseMessage.Content == null)
            {
                httpResponseMessage.Content = new NullContent();
            }

            httpResponseMessage.Headers.ETag = etag;
            httpResponseMessage.Content.Headers.LastModified = lastModified;
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:10,代码来源:HttpResponseMessageExtensions.cs


示例13: ToString_UseDifferentETags_AllSerializedCorrectly

        public void ToString_UseDifferentETags_AllSerializedCorrectly()
        {
            EntityTagHeaderValue etag = new EntityTagHeaderValue("\"e tag\"");
            Assert.Equal("\"e tag\"", etag.ToString());

            etag = new EntityTagHeaderValue("\"e tag\"", true);
            Assert.Equal("W/\"e tag\"", etag.ToString());

            etag = new EntityTagHeaderValue("\"\"", false);
            Assert.Equal("\"\"", etag.ToString());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:EntityTagHeaderValueTest.cs


示例14: Should_return_Conflict_for_Put_if_key_is_in_header_but_match_not_found_in_cache

        public void Should_return_Conflict_for_Put_if_key_is_in_header_but_match_not_found_in_cache()
        {
            var eTagHandler = GetHandler();

            var requestMessage = new HttpRequestMessage(HttpMethod.Put, etag.Key);
            requestMessage.Headers.Add("If-Match", etag.Value.Tag);

            var newRandomValue = new EntityTagHeaderValue("\"" + Guid.NewGuid() + "\"");
            AddETagValue(new KeyValuePair<string, EntityTagHeaderValue>(etag.Key, newRandomValue));

            var response = ExecuteRequest(eTagHandler, requestMessage);

            response.StatusCode.ShouldEqual(HttpStatusCode.Conflict);
        }
开发者ID:aehyok,项目名称:WebAPIContrib,代码行数:14,代码来源:ETagHandlerTests.cs


示例15: GetHashCode_UseSameAndDifferentETags_SameOrDifferentHashCodes

        public void GetHashCode_UseSameAndDifferentETags_SameOrDifferentHashCodes()
        {
            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.NotEqual(etag1.GetHashCode(), etag2.GetHashCode());
            Assert.NotEqual(etag1.GetHashCode(), etag3.GetHashCode());
            Assert.NotEqual(etag1.GetHashCode(), etag4.GetHashCode());
            Assert.NotEqual(etag1.GetHashCode(), etag6.GetHashCode());
            Assert.Equal(etag1.GetHashCode(), etag5.GetHashCode());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:15,代码来源:EntityTagHeaderValueTest.cs


示例16: OnActionExecuted

        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            var request = actionExecutedContext.Request;
              var key = GetKey(request);

              EntityTagHeaderValue entityTag;

              if (!_etTagHeaderValues.TryGetValue(key, out entityTag) || request.Method == HttpMethod.Post || request.Method == HttpMethod.Post) {
            entityTag = new EntityTagHeaderValue("\"" + Guid.NewGuid().ToString() + "\"");
            _etTagHeaderValues.AddOrUpdate(key, entityTag, (k, val) => entityTag);
              }

              actionExecutedContext.Response.Headers.ETag = entityTag;
              SetCacheControl(actionExecutedContext.Response);
        }
开发者ID:leveragesystems,项目名称:leverage_api,代码行数:15,代码来源:CacheActionFilter.cs


示例17: 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


示例18: CheckValidParsedValue

        private void CheckValidParsedValue(string input, int startIndex, EntityTagHeaderValue expectedResult,
            int expectedIndex, bool supportsMultipleValues)
        {
            HttpHeaderParser parser = null;
            if (supportsMultipleValues)
            {
                parser = GenericHeaderParser.MultipleValueEntityTagParser;
            }
            else
            {
                parser = GenericHeaderParser.SingleValueEntityTagParser;
            }

            object result = null;
            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                string.Format("TryParse returned false. Input: '{0}', AllowMultipleValues/Any: {1}", input,
                supportsMultipleValues));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(result, expectedResult);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:20,代码来源:EntityTagParserTest.cs


示例19: GetModule

        public object GetModule(string name)
        {
            var module = ViewModuleProvider.ResolveViewModule(name);
            if (module == null)
                return NotFound();

            var eTagHeaderValue = new EntityTagHeaderValue("\"" + module.ETag + "\"");
            if (Request.Headers.IfNoneMatch.Contains(eTagHeaderValue))
                return new HttpResponseMessage(HttpStatusCode.NotModified);

            var lastModifiedTime = (DateTimeOffset?)module.LastModifiedTime;
            if (Request.Headers.IfModifiedSince >= lastModifiedTime)
                return new HttpResponseMessage(HttpStatusCode.NotModified);

            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Headers.ETag = eTagHeaderValue;
            response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true };
            response.Content = new PushStreamContent((s, c, t) => { module.Write(s); s.Close(); });
            response.Content.Headers.ContentType = new MediaTypeHeaderValue(module.ContentType);
            response.Content.Headers.LastModified = lastModifiedTime;
            return response;
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:22,代码来源:ViewController.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Headers.HttpContentHeaders类代码示例发布时间:2022-05-26
下一篇:
C# Headers.ContentDispositionHeaderValue类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap