public static void Replace(this IHttpHeaders headers, string key, IEnumerable <string> values)
 {
     if (headers.Contains(key))
     {
         headers.Remove(key);
     }
     headers.Add(key, values);
 }
 public static void ReplaceWithoutValidation(this IHttpHeaders headers, string key, string value)
 {
     if (headers.Contains(key))
     {
         headers.Remove(key);
     }
     headers.TryAddWithoutValidation(key, value);
 }
 public static void Replace(this IHttpHeaders headers, string key, string value)
 {
     if (headers.Contains(key))
     {
         headers.Remove(key);
     }
     headers.Add(key, value);
 }
 /// <summary>
 /// Returns a modified HTTP client object with the default HTTP header parameters
 /// </summary>
 /// <param name="httpHeaders">HTTP headers</param>
 /// <param name="restClient">REST client</param>
 protected virtual void AddHttpHeaderParameters(IHttpHeaders httpHeaders, IRestClient restClient)
 {
     foreach (var param in restClient.DefaultParameters.Where(x => x.Type == ParameterType.HttpHeader))
     {
         if (httpHeaders.Contains(param.Name))
         {
             httpHeaders.Remove(param.Name);
         }
         var paramValue = param.ToRequestString();
         if (param.ValidateOnAdd)
         {
             httpHeaders.Add(param.Name, paramValue);
         }
         else
         {
             httpHeaders.TryAddWithoutValidation(param.Name, paramValue);
         }
     }
 }
        /// <summary>
        /// Returns a modified HTTP request message object with HTTP header parameters
        /// </summary>
        /// <param name="httpHeaders">HTTP headers</param>
        /// <param name="request">REST request</param>
        /// <param name="parameters">The request parameters for the REST request except the content header parameters (read-only)</param>
        protected virtual void AddHttpHeaderParameters(IHttpHeaders httpHeaders, IRestRequest request, IList<Parameter> parameters)
        {
            foreach (var param in parameters.Where(x => x.Type == ParameterType.HttpHeader))
            {
                if (httpHeaders.Contains(param.Name))
                {
                    httpHeaders.Remove(param.Name);
                }

                var paramValue = param.ToRequestString();
                if (param.ValidateOnAdd)
                {
                    httpHeaders.Add(param.Name, paramValue);
                }
                else
                {
                    httpHeaders.TryAddWithoutValidation(param.Name, paramValue);
                }
            }
        }