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


C# HttpHeaderValueCollection类代码示例

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


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

示例1: Add_CallWithNullValue_Throw

        public void Add_CallWithNullValue_Throw()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            Assert.Throws<ArgumentNullException>(() => { collection.Add(null); });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:HttpHeaderValueCollectionTest.cs

示例2: IsRequestedMediaTypeAccepted

 private static bool IsRequestedMediaTypeAccepted(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeader)
 {
     return GlobalConfiguration
         .Configuration
         .Formatters
         .Any(formatter => acceptHeader.Any(mediaType => FormatterSuportsMediaType(mediaType, formatter)));
 }
开发者ID:rmueller,项目名称:WebAPIContrib,代码行数:7,代码来源:NotAcceptableMessageHandler.cs

示例3: IsReadOnly_CallProperty_AlwaysFalse

        public void IsReadOnly_CallProperty_AlwaysFalse()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string)));
            HttpHeaderValueCollection<string> collection = new HttpHeaderValueCollection<string>(knownHeader, headers);

            Assert.False(collection.IsReadOnly);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:HttpHeaderValueCollectionTest.cs

示例4: CreateAuthorizationHeaderAsync

 protected virtual Task<AuthenticationHeaderValue> CreateAuthorizationHeaderAsync(
     HttpRequestMessage request, 
     HttpHeaderValueCollection<AuthenticationHeaderValue> challenges,  
     CancellationToken cancellationToken)
 {
     return Task.FromResult<AuthenticationHeaderValue>(null);
 }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:7,代码来源:HttpAuthenticationHandler.cs

示例5: CreateAuthorizationHeaderAsync

        protected override async Task<AuthenticationHeaderValue> CreateAuthorizationHeaderAsync(HttpRequestMessage request, HttpHeaderValueCollection<AuthenticationHeaderValue> challenges, CancellationToken cancellationToken)
        {
            AuthenticationHeaderValue bearerChallenge = challenges.FirstOrDefault(IsOAuth2BearerChallenge);
            if (bearerChallenge != null)
            {
                string accessToken = await GetAccessTokenAsync(request);
                if (accessToken != null)
                {
                    return new AuthenticationHeaderValue(BearerScheme, accessToken);                 
                }
            }
 	        return null;
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:13,代码来源:OAuth2BearerTokenHandler.cs

示例6: GetcontrollerActionConfiguration

        public IActionConfiguration GetcontrollerActionConfiguration(Type controllerType, MethodInfo actionMethodInfo, HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeaders)
        {
            if (!_controllerRules.ContainsKey(controllerType))
                return null;
            var controller = _controllerRules[controllerType];

            if (!controller.ContainsKey(actionMethodInfo))
                return null;

            var result = controller[actionMethodInfo];

            if ((acceptHeaders != null) && !acceptHeaders.Contains(new MediaTypeWithQualityHeaderValue(result.MetadataProvider.ContentType)))
                return null;

            return result;
        }
开发者ID:RichieYang,项目名称:NHateoas,代码行数:16,代码来源:ControllerConfiguration.cs

示例7: CreateParser

        public static IParseDomainPosts CreateParser(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> mediaTypeHeaderValues)
        {
            bool containsXml = false;

            foreach (var mediaType in mediaTypeHeaderValues)
                if (mediaType.MediaType.Contains("xml"))
                    containsXml = true;

            //if its xml try reading using xml
            if (containsXml)
            {
                return new XmlDomainPostParser();
            }
            // otherwise try to read it as json, treat as 'default' andlast resort
            return new JsonDomainPostParser();
        }
开发者ID:iancooper,项目名称:Paramore.Contrib,代码行数:16,代码来源:ConversionStrategyFactory.cs

示例8: Count_AddMultipleValuesThenQueryCount_ReturnsValueCountWithSpecialValues

        public void Count_AddMultipleValuesThenQueryCount_ReturnsValueCountWithSpecialValues()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(string)));
            HttpHeaderValueCollection<string> collection = new HttpHeaderValueCollection<string>(knownHeader, headers,
                "special");

            Assert.Equal(0, collection.Count);

            collection.Add("value1");
            headers.Add(knownHeader, "special");
            Assert.Equal(2, collection.Count);

            headers.Add(knownHeader, "special");
            headers.Add(knownHeader, "value2");
            headers.Add(knownHeader, "special");
            Assert.Equal(5, collection.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:HttpHeaderValueCollectionTest.cs

示例9: GetEncoder

        public Func<Stream, Stream> GetEncoder(HttpHeaderValueCollection<StringWithQualityHeaderValue> list)
        {
            // The following steps will walk you through
            // completing the implementation of this method
            if (list != null && list.Count > 0)
            {
                // More code goes here
                var headerValue = list.OrderByDescending(e => e.Quality ?? 1.0D).Where(e => !e.Quality.HasValue || e.Quality.Value > 0.0D).FirstOrDefault(e => supported.Keys.Contains(e.Value, StringComparer.OrdinalIgnoreCase));
                // Case 1: We can support what client has asked for
                if (headerValue != null)
                    return GetStreamForSchema(headerValue.Value);
                // Case 2: Client will accept anything we support except
                // the ones explicitly specified as not preferred by setting q=0
                if (list.Any(e => e.Value == "*" &&
                (!e.Quality.HasValue || e.Quality.Value > 0.0D)))
                {
                    var encoding = supported.Keys.Where(se =>
                    !list.Any(e =>
                    e.Value.Equals(se, StringComparison.OrdinalIgnoreCase) &&
                    e.Quality.HasValue &&
                    e.Quality.Value == 0.0D))
                    .FirstOrDefault();
                    if (encoding != null)
                        return GetStreamForSchema(encoding);
                }

                // Case 3: Client specifically refusing identity
                if (list.Any(e => e.Value.Equals(IDENTITY, StringComparison.OrdinalIgnoreCase) &&
                e.Quality.HasValue && e.Quality.Value == 0.0D))
                {
                    throw new NegotiationFailedException();
                }
                // Case 4: Client is not willing to accept any of the encodings
                // we support and is not willing to accept identity
                if (list.Any(e => e.Value == "*" &&
                (e.Quality.HasValue || e.Quality.Value == 0.0D)))
                {
                    if (!list.Any(e => e.Value.Equals(IDENTITY, StringComparison.OrdinalIgnoreCase)))
                        throw new NegotiationFailedException();
                }
            }
            // Settle for the default, which is no transformation whatsoever
            return null;
        }
开发者ID:KaranGandhi,项目名称:TestDemo,代码行数:44,代码来源:EncodingSchema.cs

示例10: Add_AddValues_AllValuesAdded

        public void Add_AddValues_AllValuesAdded()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/1/"));
            collection.Add(new Uri("http://www.example.org/2/"));
            collection.Add(new Uri("http://www.example.org/3/"));

            Assert.Equal(3, collection.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:HttpHeaderValueCollectionTest.cs

示例11: Ctor_ProvideValidator_ValidatorIsUsedWhenAddingValues

        public void Ctor_ProvideValidator_ValidatorIsUsedWhenAddingValues()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                MockValidator);

            // Adding an arbitrary Uri should not throw.
            collection.Add(new Uri("http://some/"));

            // When we add 'invalidValue' our MockValidator will throw.
            Assert.Throws<MockException>(() => { collection.Add(invalidValue); });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:HttpHeaderValueCollectionTest.cs

示例12: RemoveSpecialValue_AddValueAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved

        public void RemoveSpecialValue_AddValueAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/"));
            collection.SetSpecialValue();
            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
            Assert.Equal(2, headers.GetValues(knownHeader).Count());

            collection.RemoveSpecialValue();
            Assert.False(collection.IsSpecialValueSet, "Special value is set.");
            Assert.Equal(1, headers.GetValues(knownHeader).Count());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:HttpHeaderValueCollectionTest.cs

示例13: GetEnumerator_AddValuesAndSpecialValue_AllValuesReturned

        public void GetEnumerator_AddValuesAndSpecialValue_AllValuesReturned()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/1/"));
            collection.Add(new Uri("http://www.example.org/2/"));
            collection.SetSpecialValue();
            collection.Add(new Uri("http://www.example.org/3/"));

            System.Collections.IEnumerable enumerable = collection;

            // The special value we added above, must be part of the collection returned by GetEnumerator().
            int i = 1;
            bool specialFound = false;
            foreach (var item in enumerable)
            {
                if (item.Equals(specialValue))
                {
                    specialFound = true;
                }
                else
                {
                    Assert.Equal(new Uri("http://www.example.org/" + i + "/"), item);
                    i++;
                }
            }

            Assert.True(specialFound);
            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
        }
开发者ID:dotnet,项目名称:corefx,代码行数:32,代码来源:HttpHeaderValueCollectionTest.cs

示例14: GetEnumerator_NoValues_EmptyEnumerator

        public void GetEnumerator_NoValues_EmptyEnumerator()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            IEnumerator<Uri> enumerator = collection.GetEnumerator();

            Assert.False(enumerator.MoveNext(), "No items expected in enumerator.");
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:HttpHeaderValueCollectionTest.cs

示例15: CopyTo_NoValues_DoesNotChangeArray

        public void CopyTo_NoValues_DoesNotChangeArray()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers);

            Uri[] array = new Uri[4];
            collection.CopyTo(array, 0);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.Null(array[i]);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:HttpHeaderValueCollectionTest.cs


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