public static void CopyTo(this IHttpWebRequestOptions options, HttpWebRequestOptions other, bool copyIfNull = true) { if (copyIfNull || !string.IsNullOrEmpty(options.Accept)) { other.Accept = options.Accept; } if (copyIfNull || !string.IsNullOrEmpty(options.AcceptLanguage)) { other.AcceptLanguage = options.AcceptLanguage; } other.AutomaticDecompression = options.AutomaticDecompression; if (copyIfNull || !(options.Cookies is null)) { other.Cookies = options.Cookies; } if (copyIfNull || !(options.Credentials is null)) { other.Credentials = options.Credentials; } if (copyIfNull || !(options.Proxy is null)) { other.Proxy = options.Proxy; } if (copyIfNull || !string.IsNullOrEmpty(options.UserAgent)) { other.UserAgent = options.UserAgent; } }
public void TestCreateWithoutAddingReturnsDefault() { IHttpWebRequestOptions defaultOptions = new HttpWebRequestOptions() { UserAgent = "hello world", }; Assert.AreEqual(defaultOptions.UserAgent, new HttpWebRequestOptionsFactory(defaultOptions).Create("https://stackoverflow.com/").UserAgent); }