本文整理汇总了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); });
}
示例2: IsRequestedMediaTypeAccepted
private static bool IsRequestedMediaTypeAccepted(HttpHeaderValueCollection<MediaTypeWithQualityHeaderValue> acceptHeader)
{
return GlobalConfiguration
.Configuration
.Formatters
.Any(formatter => acceptHeader.Any(mediaType => FormatterSuportsMediaType(mediaType, formatter)));
}
示例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);
}
示例4: CreateAuthorizationHeaderAsync
protected virtual Task<AuthenticationHeaderValue> CreateAuthorizationHeaderAsync(
HttpRequestMessage request,
HttpHeaderValueCollection<AuthenticationHeaderValue> challenges,
CancellationToken cancellationToken)
{
return Task.FromResult<AuthenticationHeaderValue>(null);
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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); });
}
示例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());
}
示例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.");
}
示例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.");
}
示例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]);
}
}