public static string GetNephosOrStandardDateString(NameValueCollection headers) { string str = null; str = (HttpRequestAccessorCommon.GetHeaderValues(headers, "x-ms-date").Count <= 0 ? headers.GetValues("Date")[0] : MessageCanonicalizer.GetCanonicalizedHeaderValue(headers, "x-ms-date")); return(str); }
public static string GetCanonicalizedHeaderValue(NameValueCollection headers, string key) { StringBuilder stringBuilder = new StringBuilder(); string empty = string.Empty; foreach (string headerValue in HttpRequestAccessorCommon.GetHeaderValues(headers, key)) { string str = headerValue.Replace("\r\n", string.Empty); stringBuilder.Append(empty); stringBuilder.Append(str); empty = ","; } return(stringBuilder.ToString()); }
public static string GetContentMD5(NameValueCollection headers) { string empty = string.Empty; ArrayList headerValues = HttpRequestAccessorCommon.GetHeaderValues(headers, "Content-MD5"); if (headerValues.Count > 1) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { "Content-MD5" }; throw new HttpRequestDuplicateHeaderException(string.Format(invariantCulture, "The given HTTP request header contains more than one {0} values.", objArray)); } if (headerValues.Count == 1) { empty = (string)headerValues[0]; } return(empty); }
public static string CanonicalizeHttpRequestDefault(Uri address, NephosUriComponents uriComponents, string method, string contentType, NameValueCollection headers, bool isFileService = false, string rawUrl = null) { MessageCanonicalizer.CanonicalizedString canonicalizedString = new MessageCanonicalizer.CanonicalizedString(method); canonicalizedString.AppendCanonicalizedElement(MessageCanonicalizer.GetContentMD5(headers)); canonicalizedString.AppendCanonicalizedElement(contentType); string str = null; if (HttpRequestAccessorCommon.GetHeaderValues(headers, "x-ms-date").Count <= 0) { string[] values = headers.GetValues("Date"); str = (values == null || (int)values.Length == 0 ? string.Empty : values[0]); } else { str = null; } canonicalizedString.AppendCanonicalizedElement(str); ArrayList arrayLists = new ArrayList(); foreach (string key in headers.Keys) { if (key == null || !key.ToLowerInvariant().StartsWith("x-ms-", StringComparison.Ordinal)) { continue; } arrayLists.Add(key.ToLowerInvariant()); } arrayLists.Sort(); foreach (string arrayList in arrayLists) { string canonicalizedHeaderValue = MessageCanonicalizer.GetCanonicalizedHeaderValue(headers, arrayList); if (string.IsNullOrEmpty(canonicalizedHeaderValue) && !isFileService && MessageCanonicalizer.IsVersionBeforeFeb16(headers["x-ms-version"])) { continue; } StringBuilder stringBuilder = new StringBuilder(arrayList); stringBuilder.Append(":"); stringBuilder.Append(canonicalizedHeaderValue); canonicalizedString.AppendCanonicalizedElement(stringBuilder.ToString()); } canonicalizedString.AppendCanonicalizedElement(MessageCanonicalizer.GetCanonicalizedResource(address, uriComponents, rawUrl)); return(canonicalizedString.Value); }
public static void GetAuthorizationFieldValues(NameValueCollection headers, string authHeaderName, out string authScheme, out string authSchemeParam) { ArrayList headerValues = HttpRequestAccessorCommon.GetHeaderValues(headers, authHeaderName); if (headerValues.Count == 0) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { "Authorization" }; throw new HttpRequestHeaderNotFoundException(string.Format(invariantCulture, "No '{0}' header found.", objArray)); } if (headerValues.Count > 1) { CultureInfo cultureInfo = CultureInfo.InvariantCulture; object[] objArray1 = new object[] { "Authorization" }; StringBuilder stringBuilder = new StringBuilder(string.Format(cultureInfo, "More than one '{0}' header values found ", objArray1)); string str = ":"; foreach (string headerValue in headerValues) { stringBuilder.Append(str); stringBuilder.Append(headerValue); str = ","; } throw new HttpRequestDuplicateHeaderException(stringBuilder.ToString()); } string item = (string)headerValues[0]; string[] strArrays = item.Split(HttpRequestAccessorCommon.spaceDelimiter, StringSplitOptions.RemoveEmptyEntries); if ((int)strArrays.Length != 2) { CultureInfo invariantCulture1 = CultureInfo.InvariantCulture; object[] objArray2 = new object[] { "Authorization", item }; throw new HttpRequestInvalidHeaderException(string.Format(invariantCulture1, "{0} value '{1}' is invalid.", objArray2)); } authScheme = strArrays[0]; authSchemeParam = strArrays[1]; }
public static ArrayList GetHeaderValues(WebRequest request, string headerName) { return(HttpRequestAccessorCommon.GetHeaderValues(request.Headers, headerName)); }