private static void AddRange(HttpWebRequest r, string range)
        {
            var m = AddRangeRegex.Match(range);

            if (!m.Success)
            {
                return;
            }

            string rangeSpecifier = m.Groups[1].Value;
            long   from           = Convert.ToInt64(m.Groups[2].Value);
            long   to             = Convert.ToInt64(m.Groups[3].Value);

            r.AddRange(rangeSpecifier, from, to);
        }
 // handle restricted headers the .NET way - thanks @dimebrain!
 // http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.headers.aspx
 private void AppendHeaders(HttpWebRequest webRequest)
 {
     foreach (var header in Headers)
     {
         Action <HttpWebRequest, string> restrictedHeaderAction;
         if (restrictedHeaderActions.TryGetValue(header.Name, out restrictedHeaderAction))
         {
             restrictedHeaderAction.Invoke(webRequest, header.Value);
         }
         else
         {
             webRequest.Headers.Add(header.Name, header.Value);
         }
     }
 }
        private void AppendCookies(HttpWebRequest webRequest)
        {
            webRequest.CookieContainer = CookieContainer ?? new CookieContainer();

            foreach (var httpCookie in Cookies)
            {
                var cookie = new Cookie
                {
                    Name   = httpCookie.Name,
                    Value  = httpCookie.Value,
                    Domain = webRequest.RequestUri.Host
                };

                webRequest.CookieContainer.Add(cookie);
            }
        }