本文整理汇总了C#中HttpHeaders.TryAddWithoutValidation方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaders.TryAddWithoutValidation方法的具体用法?C# HttpHeaders.TryAddWithoutValidation怎么用?C# HttpHeaders.TryAddWithoutValidation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.TryAddWithoutValidation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateHeaderFields
/// <summary>
/// Copies the unsorted header fields to a sorted collection.
/// </summary>
/// <param name="source">The unsorted source headers</param>
/// <param name="destination">The destination <see cref="HttpRequestHeaders"/> or <see cref="HttpResponseHeaders"/>.</param>
/// <param name="contentStream">The input <see cref="Stream"/> used to form any <see cref="HttpContent"/> being part of this HTTP request.</param>
/// <param name="rewind">Start location of any request entity within the <paramref name="contentStream"/>.</param>
/// <returns>An <see cref="HttpContent"/> instance if header fields contained and <see cref="HttpContentHeaders"/>.</returns>
private static HttpContent CreateHeaderFields(HttpHeaders source, HttpHeaders destination, Stream contentStream, int rewind)
{
Contract.Assert(source != null, "source headers cannot be null");
Contract.Assert(destination != null, "destination headers cannot be null");
Contract.Assert(contentStream != null, "contentStream must be non null");
HttpContentHeaders contentHeaders = null;
HttpContent content = null;
// Set the header fields
foreach (KeyValuePair<string, IEnumerable<string>> header in source)
{
if (!destination.TryAddWithoutValidation(header.Key, header.Value))
{
if (contentHeaders == null)
{
contentHeaders = FormattingUtilities.CreateEmptyContentHeaders();
}
contentHeaders.TryAddWithoutValidation(header.Key, header.Value);
}
}
// If we have content headers then create an HttpContent for this Response
if (contentHeaders != null)
{
// Need to rewind the input stream to be at the position right after the HTTP header
// which we may already have parsed as we read the content stream.
if (!contentStream.CanSeek)
{
throw Error.InvalidOperation(Resources.HttpMessageContentStreamMustBeSeekable, "ContentReadStream", FormattingUtilities.HttpResponseMessageType.Name);
}
contentStream.Seek(0 - rewind, SeekOrigin.Current);
content = new StreamContent(contentStream);
contentHeaders.CopyTo(content.Headers);
}
return content;
}
示例2: MergeWebHeaderCollectionWithHttpHeaders
internal static void MergeWebHeaderCollectionWithHttpHeaders(WebHeaderCollection headersToMerge, HttpHeaders mainHeaders, HttpHeaders contentHeaders)
{
foreach (string headerKey in headersToMerge.AllKeys)
{
if (WellKnownContentHeaders.Contains(headerKey))
{
contentHeaders.TryAddWithoutValidation(headerKey, headersToMerge[headerKey]);
}
else
{
mainHeaders.TryAddWithoutValidation(headerKey, headersToMerge[headerKey]);
}
}
}
示例3: CopyTo
/// <summary>
/// Copies current header field to the provided <see cref="HttpHeaders"/> instance.
/// </summary>
/// <param name="headers">The headers.</param>
/// <param name="ignoreHeaderValidation">Set to false to validate headers</param>
public void CopyTo(HttpHeaders headers, bool ignoreHeaderValidation)
{
var name = _name.ToString();
var value = _value.ToString().Trim(CurrentHeaderFieldStore._linearWhiteSpace);
if (ignoreHeaderValidation)
{
headers.TryAddWithoutValidation(name, value);
}
else
{
headers.Add(name, value);
}
Clear();
}
示例4: TryAddHeader
public bool TryAddHeader(HttpHeaders headers, string value)
{
Fx.Assert(headers != null, "The 'headers' parameter should never be null.");
if (!headers.TryAddWithoutValidation(this.Name, value))
{
this.UpdateHeaderInfo(headers);
return false;
}
return true;
}