/// <summary>
        /// Unconditionally adds the authorization header to the request
        /// </summary>
        /// <param name="request">The request to add the authorization header to</param>
        /// <param name="header">The type of the HTTP header that stores the authorization information</param>
        /// <param name="authValue">The authentication header value</param>
        public static void SetAuthorizationHeader([NotNull] this IHttpRequestMessage request, AuthHeader header, [NotNull] string authValue)
        {
            var headerName = header.ToAuthorizationHeaderName();

            request.Headers.Remove(headerName);
            request.Headers.Add(headerName, authValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove the authorization HTTP header if it's not equal to the old one.
        /// </summary>
        /// <param name="parameters">List of HTTP headers</param>
        /// <param name="header">The type of the HTTP header that stores the authorization information</param>
        /// <param name="authValue">The authorization header value</param>
        /// <returns>true = header removed, false = same header already exists, null = header not found</returns>
        public static bool?RemoveAuthorizationHeader([NotNull, ItemNotNull] IList <Parameter> parameters, AuthHeader header, [NotNull] string authValue)
        {
            var authParam = parameters.SingleOrDefault(
                p => p.Name.Equals(header.ToAuthorizationHeaderName(), StringComparison.OrdinalIgnoreCase));

            if (authParam == null)
            {
                return(null);
            }
            var v = (string)authParam.Value;

            if (v != null && v == authValue)
            {
                return(false);
            }
            parameters.Remove(authParam);
            return(true);
        }
        /// <summary>
        /// Remove the authorization HTTP header if it's not equal to the old one.
        /// </summary>
        /// <param name="parameters">List of HTTP headers</param>
        /// <param name="header">The type of the HTTP header that stores the authorization information</param>
        /// <param name="authValue">The authorization header value</param>
        /// <returns>true = header removed, false = same header already exists, null = header not found</returns>
        public static bool?RemoveAuthorizationHeader([NotNull, ItemNotNull] IParameterCollection parameters, AuthHeader header, [NotNull] string authValue)
        {
            var authParam = parameters.Find(ParameterType.HttpHeader, header.ToAuthorizationHeaderName()).FirstOrDefault();

            if (authParam == null)
            {
                return(null);
            }

            var v = (string)authParam.Value;

            if (v != null && v == authValue)
            {
                return(false);
            }

            parameters.Remove(authParam);
            return(true);
        }
 /// <summary>
 /// Unconditionally adds the authorization header to the request
 /// </summary>
 /// <param name="request">The request to add the authorization header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 public static void SetAuthorizationHeader([NotNull] IRestRequest request, AuthHeader header, [NotNull] string authValue)
 {
     request.AddParameter(header.ToAuthorizationHeaderName(), authValue, ParameterType.HttpHeader);
 }
 /// <summary>
 /// Remove the authorization HTTP header if it's not equal to the old one.
 /// </summary>
 /// <param name="parameters">List of HTTP headers</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 /// <returns>true = header removed, false = same header already exists, null = header not found</returns>
 public static bool? RemoveAuthorizationHeader(IList<Parameter> parameters, AuthHeader header, string authValue)
 {
     var authParam = parameters.SingleOrDefault(
         p => p.Name.Equals(header.ToAuthorizationHeaderName(), StringComparison.OrdinalIgnoreCase));
     if (authParam == null)
         return null;
     var v = (string)authParam.Value;
     if (v != null && v == authValue)
         return false;
     parameters.Remove(authParam);
     return true;
 }
 /// <summary>
 /// Unconditionally adds the authorization header to the request
 /// </summary>
 /// <param name="request">The request to add the authorization header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authentication header value</param>
 public static void SetAuthorizationHeader(this IHttpRequestMessage request, AuthHeader header, string authValue)
 {
     var headerName = header.ToAuthorizationHeaderName();
     request.Headers.Remove(headerName);
     request.Headers.Add(headerName, authValue);
 }
 /// <summary>
 /// Unconditionally adds the authorization header to the request
 /// </summary>
 /// <param name="request">The request to add the authorization header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 public static void SetAuthorizationHeader(IRestRequest request, AuthHeader header, string authValue)
 {
     request.AddParameter(header.ToAuthorizationHeaderName(), authValue, ParameterType.HttpHeader);
 }
 /// <summary>
 /// Unconditionally adds the authorization header to the request
 /// </summary>
 /// <param name="request">The request to add the authorization header to</param>
 /// <param name="header">The type of the HTTP header that stores the authorization information</param>
 /// <param name="authValue">The authorization header value</param>
 public static void SetAuthorizationHeader([NotNull] IRestRequest request, AuthHeader header, [NotNull] string authValue)
 {
     request.Parameters.AddOrUpdate(new Parameter {
         Name = header.ToAuthorizationHeaderName(), Value = authValue, Type = ParameterType.HttpHeader
     });
 }