本文整理汇总了C#中System.Net.Http.Headers.HttpRequestHeaders类的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestHeaders类的具体用法?C# HttpRequestHeaders怎么用?C# HttpRequestHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestHeaders类属于System.Net.Http.Headers命名空间,在下文中一共展示了HttpRequestHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildClaimsPrincipal
private async Task<ClaimsPrincipal> BuildClaimsPrincipal(HttpRequestHeaders headers)
{
string credentials;
try
{
var token = Convert.FromBase64String(headers.Authorization.Parameter);
credentials = Encoding.UTF8.GetString(token);
}
catch (FormatException)
{
return null;
}
catch (ArgumentException)
{
return null;
}
var parts = credentials.Split(':');
if (parts.Length != 2)
return null;
var userId = parts[0].Trim();
var password = parts[1].Trim();
if (! await _validateCredentials(userId, password))
return null;
var claims = new[] {new Claim(ClaimTypes.Name, userId)};
var claimsIdentities = new[] {new ClaimsIdentity(claims, Scheme)};
return new ClaimsPrincipal(claimsIdentities);
}
示例2: GetFromRequestHeaders
public static ApiCredentials GetFromRequestHeaders(HttpRequestHeaders requestHeaders)
{
//this could/should be another interface for testing purposes
var authenticationHeader = requestHeaders.Authorization;
if (authenticationHeader.Scheme != Configuration.AuthenticationScheme)
{
return null;
}
if (requestHeaders.Authorization == null || requestHeaders.Authorization.Parameter == null
|| !requestHeaders.Authorization.Parameter.Contains(":"))
{
return null;
}
var apiKey = requestHeaders.Authorization.Parameter.Split(':')[0];
if (apiKey == null)
{
return null;
}
var decodedBytes = Convert.FromBase64String(authenticationHeader.Parameter);
var signature = Encoding.UTF8.GetString(decodedBytes);
return new ApiCredentials()
{
Signature = signature,
ApiKey = apiKey
};
}
示例3: CopyTo
internal static void CopyTo(this HttpRequestHeaders from, HttpRequestHeaders to)
{
foreach (var header in from)
{
to.TryAddWithoutValidation(header.Key, header.Value);
}
}
示例4: GetCookie
public static string GetCookie(HttpRequestHeaders headers, string name)
{
var cookies = headers.GetCookies(name).FirstOrDefault();
if (cookies == null) return null;
var cookie = cookies.Cookies.SingleOrDefault(x => x.Name == name);
return cookie == null ? null : cookie.Value;
}
示例5: Populate
internal void Populate(HttpRequestHeaders headers)
{
if (this.Range != null)
{
headers.Range = new RangeHeaderValue(this.Range[0], this.Range[1]);
}
if (this.ModifiedSinceConstraint.HasValue)
{
headers.IfModifiedSince = new DateTimeOffset(this.ModifiedSinceConstraint.Value);
}
if (this.UnmodifiedSinceConstraint.HasValue)
{
headers.IfUnmodifiedSince = new DateTimeOffset(this.UnmodifiedSinceConstraint.Value);
}
if (this._matchingETagConstraints.Count > 0)
{
foreach (string temp in this._matchingETagConstraints)
headers.IfMatch.Add(new EntityTagHeaderValue(temp));
}
if (this._nonmatchingEtagConstraints.Count > 0)
{
foreach (string temp in this._nonmatchingEtagConstraints)
headers.IfMatch.Add(new EntityTagHeaderValue(temp));
}
}
示例6: CanonicalizedHeaders
internal static string CanonicalizedHeaders(HttpRequestHeaders headers)
{
var canonicalizedString = new CanonicalizedString(string.Empty);
var keyList =
headers.Where(h => h.Key.StartsWith("x-ms-", StringComparison.OrdinalIgnoreCase)).Select(header => header.Key).ToList();
keyList.Sort();
foreach (string str2 in keyList)
{
var builder = new StringBuilder(str2);
string str3 = ":";
foreach (string str4 in GetHeaderValues(headers, str2))
{
string str5 = str4.Replace("\r\n", string.Empty);
builder.Append(str3);
builder.Append(str5);
str3 = ",";
}
canonicalizedString.AppendCanonicalizedElement(builder.ToString());
}
return canonicalizedString.Value.TrimEnd('\n').TrimStart('\n');
}
示例7: Populate
internal void Populate(HttpRequestHeaders headers)
{
if (this.CacheControl != null)
{
headers.Add("response-cache-control", this.CacheControl);
}
if (this.ContentDisposition != null)
{
headers.Add("response-content-disposition", this.ContentDisposition);
}
if (this.ContentEncoding != null)
{
headers.Add("response-content-encoding", this.ContentEncoding);
}
if (this.ContentLanguage != null)
{
headers.Add("response-content-language", this.ContentLanguage);
}
if (this.ContentType != null)
{
headers.Add("response-content-type", this.ContentType);
}
if (this.Expires != null)
{
headers.Add("response-expires", this.Expires);
}
}
示例8: Authentication
/// <summary>
/// Authorization request header from client.
/// </summary>
/// <param name="header">header from client</param>
/// <returns>-401/-403/{userId}</returns>
public static long Authentication(HttpRequestHeaders header)
{
string authorization = header.GetValues("Authorization").FirstOrDefault();
if (authorization == null)
{
return -401;
}
using (var db = new CF_FamsamEntities())
{
string token = authorization.Split(null)[1];
Session session = db.Session.Find(token);
Debug.WriteLine("____________________________" + session.token);
if (session == null) return -403;
if (session.expired < DateTime.Now)
{
Debug.WriteLine("____________________________ session mili:" + session.expired.Millisecond);
Debug.WriteLine("____________________________ now mili:" + DateTime.Now.Millisecond);
//session expired
db.Session.Remove(session);
db.SaveChanges();
return -403;
}
else
{
return session.User.id;
}
}
}
示例9: _GetCanonicalizedHeaders
private string _GetCanonicalizedHeaders(HttpRequestHeaders headers)
{
var orderedHeaders = headers.OrderBy(x => x.Key);
var headersWithAggregatedValues = orderedHeaders.Where(x => x.Key.StartsWith("x-ms")).Select(x => x.Key.ToLowerInvariant() + ":" + headers.GetValues(x.Key).Aggregate((x1, x2) => x1 + "," + x2));
var canonicalHeader = headersWithAggregatedValues.Aggregate((x1, x2) => x1 + "\n" + x2) + "\n";
return canonicalHeader;
}
示例10: HttpRequestMessage
/// <summary>
/// Initializes a new instance of the <see cref="HttpRequestMessage" /> class
/// with an HTTP method and a request System.Uri.
/// </summary>
/// <param name="method">The HTTP method.</param>
/// <param name="requestUri">The System.Uri to request.</param>
public HttpRequestMessage(HttpMethod method, Uri requestUri)
{
RequestUri = requestUri;
Properties = new Dictionary<string, object>();
Version = new Version("1.1");
Method = method;
Headers = new HttpRequestHeaders(new WebHeaderCollection());
}
示例11: GetValueStorage
public string GetValueStorage(HttpRequestHeaders context, string key)
{
var cookie = context.GetCookies(key).FirstOrDefault();
if (cookie != null)
return cookie[key].Value;
return null;
}
示例12: IsHeaderContainToken
public static bool IsHeaderContainToken(HttpRequestHeaders header)
{
if (header.Contains(Constants.AccessTokenKey))
{
return true;
}
return false;
}
示例13: CanonicalizeHttpHeaders
/// <summary>
/// Canonicalizes the HTTP headers.
/// </summary>
/// <param name="method">The HTTP method for the request.</param>
/// <param name="requestHeaders">The request headers.</param>
/// <param name="contentHeaders">The content headers.</param>
/// <returns>A string representation of the HTTP headers.</returns>
private static string CanonicalizeHttpHeaders(
HttpMethod method,
HttpRequestHeaders requestHeaders,
HttpContentHeaders contentHeaders)
{
long? contentLength = contentHeaders != null ? contentHeaders.ContentLength : null;
return CanonicalizeHttpHeaders(method, contentLength, requestHeaders, contentHeaders);
}
示例14: ReadAuthenticationContent
protected bool ReadAuthenticationContent(HttpRequestHeaders authenticationContent, string key, out string value)
{
value = string.Empty;
var content = authenticationContent.FirstOrDefault(pair => pair.Key == key);
if (content.Value == null || content.Value.Count() != 1)
return false;
value = content.Value.First();
return true;
}
示例15: Build
public string Build(string verb, string content, StorageUri uri, AzureStorageAccountInfo accountInfo, HttpRequestHeaders headers, string contentType)
{
var ifMatch = "";
var md5 = "";
var canonicalizedHeaderString = _GetCanonicalizedHeaders(headers);
var canonResource = _GetCanonicalizedResource(new Uri(uri.ToUriString()), accountInfo.Account);
var authorizationHeader = _GetAuthorizationHeader(verb, content, ifMatch, canonicalizedHeaderString, canonResource, md5, accountInfo, contentType);
return authorizationHeader;
}