public async Task UsesAssemblyNameAndInformationalVersionForTelemetryPolicySettingsWithSetTelemetryPackageInfo() { var transport = new MockTransport(new MockResponse(503), new MockResponse(200)); var options = new TestOptions { Transport = transport }; HttpPipeline pipeline = HttpPipelineBuilder.Build(options); var message = pipeline.CreateMessage(); message.SetUserAgentString(UserAgentValue.FromType <string>()); using Request request = message.Request; request.Method = RequestMethod.Get; request.Uri.Reset(new Uri("http://example.com")); await pipeline.SendAsync(message, CancellationToken.None); var informationalVersion = typeof(string).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; var i = informationalVersion.IndexOf('+'); if (i > 0) { informationalVersion = informationalVersion.Substring(0, i); } Assert.True(request.Headers.TryGetValue("User-Agent", out string value)); #if NETFRAMEWORK StringAssert.StartsWith($"azsdk-net-mscorlib/{informationalVersion} ", value); #else StringAssert.StartsWith($"azsdk-net-System.Private.CoreLib/{informationalVersion} ", value); #endif }
[DataRow("Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25", false)] // iPhone 6 public void IsTabletUserAgentString_Decodes_Common_Tablet_User_Agent_String(string userAgent, bool expected) { var value = new UserAgentValue(userAgent); var actual = value.IsTabletUserAgentString; Assert.AreEqual(expected, actual); }
public Task <HttpResponseMessage> PostAsync(Uri target, string postContent, string contentType) { const string UserAgent = "user-agent"; const string UserAgentValue = "EveHQ v{0}"; if (target != null) { var handler = new HttpClientHandler(); // This is never null if (_proxyInfo != null && _proxyInfo.ProxyServerAddress != null) { // set proxy if required. var proxy = new WebProxy(_proxyInfo.ProxyServerAddress); if (_proxyInfo.UseDefaultCredential) { proxy.UseDefaultCredentials = true; } else { var credential = new NetworkCredential(_proxyInfo.ProxyUserName, _proxyInfo.ProxyPassword); proxy.Credentials = _proxyInfo.UseBasicAuth ? credential.GetCredential(_proxyInfo.ProxyServerAddress, "Basic") : credential; } handler.Proxy = proxy; handler.UseProxy = true; } handler.AutomaticDecompression = DecompressionMethods.GZip; handler.AllowAutoRedirect = true; var requestClient = new HttpClient(handler); requestClient.DefaultRequestHeaders.Add(UserAgent, UserAgentValue.FormatInvariant(Version)); HttpContent content = !postContent.IsNullOrWhiteSpace() ? new StringContent(postContent, Encoding.UTF8, contentType) : null; return(requestClient.PostAsync(target, content)); } return(Task <HttpResponseMessage> .Factory.StartNew(() => null)); }
public TelemetryPolicy(UserAgentValue userAgentValue) { _defaultHeader = userAgentValue.ToString(); }
public void Ctor_Handles_Null_UserAgent() { var value = new UserAgentValue(null); Assert.AreEqual("", value.UserAgent); }
public void Ctor_Sets_UserAgent() { var value = new UserAgentValue(Samsung_Galaxy_S6); Assert.AreEqual(Samsung_Galaxy_S6, value.UserAgent); }
public void Ctor_Defaults_UserAgent() { var value = new UserAgentValue(); Assert.AreEqual("", value.UserAgent); }
/// <summary> /// Sets the package name and version portion of the UserAgent telemetry value. /// Note: If <see cref="DiagnosticsOptions.IsTelemetryEnabled"/> is false, this value is never used. /// </summary> /// <param name="message">The <see cref="HttpMessage"/>.</param> /// <param name="userAgentValue">The <see cref="SetUserAgentString"/>.</param> public static void SetUserAgentString(this HttpMessage message, UserAgentValue userAgentValue) { message.SetInternalProperty(typeof(UserAgentValueKey), userAgentValue.ToString()); }