public async Task ConfiguringPipeline() { // this instance will hold pipeline creation options var options = new HttpPipeline.Options(); // specify custon HttpClient options.Transport = new HttpClientTransport(s_client); // remove logging policy options.LoggingPolicy = null; // specify custom retry policy options options.RetryPolicy = RetryPolicy.CreateFixed( maxRetries: 10, delay: TimeSpan.FromSeconds(1), retriableCodes: new int[] { 500, // Internal Server Error 504 // Gateway Timeout } ); // add a policy (custom behavior) that executes once per client call options.PerCallPolicies = new HttpPipelinePolicy[] { new AddHeaderPolicy() }; // add a policy that executes once per retry options.PerRetryPolicies = new HttpPipelinePolicy[] { new CustomLogPolicy() }; var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION"); // pass the policy options to the client var client = new ConfigurationClient(connectionString, options); await client.SetAsync(new ConfigurationSetting("some_key", "some_value")); await client.DeleteAsync("some_key"); }
public async Task HelloWorld() { var cancellation = new CancellationTokenSource(); var options = new HttpPipeline.Options(); HttpPipeline pipeline = HttpPipeline.Create(options, sdkName: "test", sdkVersion: "1.0"); using (HttpMessage message = pipeline.CreateMessage(options, cancellation: default)) { var uri = new Uri(@"https://raw.githubusercontent.com/Azure/azure-sdk-for-net/master/src/SDKs/Azure.Base/data-plane/Azure.Base.sln"); message.SetRequestLine(HttpVerb.Get, uri); message.AddHeader("Host", uri.Host); await pipeline.SendMessageAsync(message).ConfigureAwait(false); Response response = message.Response; if (response.Status == 200) { var reader = new StreamReader(response.ContentStream); string responseText = reader.ReadToEnd(); } else { throw new RequestFailedException(response); } } }
public ConfigurationClient(string connectionString, HttpPipeline.Options options) { if (connectionString == null) { throw new ArgumentNullException(nameof(connectionString)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _options = options; Pipeline = HttpPipeline.Create(_options, SdkName, SdkVersion); ParseConnectionString(connectionString, out _baseUri, out _credential, out _secret); }
public void Basics() { var options = new HttpPipeline.Options(); options.Transport = new MockTransport(500, 1); options.RetryPolicy = new CustomRetryPolicy(); var listener = new TestEventListener(); listener.EnableEvents(EventLevel.LogAlways); var pipeline = HttpPipeline.Create(options, "test", "1.0.0"); using (var message = pipeline.CreateMessage(options, cancellation: default)) { message.SetRequestLine(HttpVerb.Get, new Uri("https://contoso.a.io")); pipeline.SendMessageAsync(message).Wait(); Assert.AreEqual(1, message.Response.Status); var result = listener.ToString(); Assert.AreEqual(expected, result); } }
public async Task ConfiguringRetries() { // specify retry policy options var options = new HttpPipeline.Options(); options.RetryPolicy = RetryPolicy.CreateFixed( maxRetries: 10, delay: TimeSpan.FromSeconds(1), retriableCodes: new int[] { 500, // Internal Server Error 504 // Gateway Timeout } ); var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION"); // pass the policy options to the client var client = new ConfigurationClient(connectionString, options); await client.SetAsync(new ConfigurationSetting("some_key", "some_value")); await client.DeleteAsync("some_key"); }
public Message(ref HttpPipeline.Options options, CancellationToken cancellation) : base(cancellation) { }
public abstract HttpMessage CreateMessage(HttpPipeline.Options options, CancellationToken cancellation);