Skip to content

Commit

Permalink
Link to proxy doc on Learn (#47241)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottaddie authored Nov 19, 2024
1 parent 50441a5 commit 7a804c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
29 changes: 4 additions & 25 deletions sdk/core/Azure.Core/samples/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SecretClientOptions options = new SecretClientOptions()

## Setting a custom retry policy

Using `RetryOptions` to configure retry behavior is sufficient for the vast majority of scenarios. For more advanced scenarios, it's possible to use a custom retry policy by setting the `RetryPolicy` property of client options class. This can be accomplished by implementing a retry policy that derives from the `RetryPolicy` class, or by passing in a `DelayStrategy` into the existing `RetryPolicy` constructor. The `RetryPolicy` class contains hooks to determine if a request should be retried and how long to wait before retrying.
Using `RetryOptions` to configure retry behavior is sufficient for the vast majority of scenarios. For more advanced scenarios, it's possible to use a custom retry policy by setting the `RetryPolicy` property of client options class. This can be accomplished by implementing a retry policy that derives from the `RetryPolicy` class, or by passing in a `DelayStrategy` into the existing `RetryPolicy` constructor. The `RetryPolicy` class contains hooks to determine if a request should be retried and how long to wait before retrying.

In the following example, we implement a policy that will prevent retries from taking place if the overall processing time has exceeded a configured threshold. Notice that the policy takes in `RetryOptions` as one of the constructor parameters and passes it to the base constructor. By doing this, we are able to delegate to the base `RetryPolicy` as needed (either by explicitly invoking the base methods, or by not overriding methods that we do not need to customize) which will respect the `RetryOptions`.

Expand Down Expand Up @@ -68,7 +68,7 @@ SecretClientOptions options = new SecretClientOptions()
};
```

Another scenario where it may be helpful to use a custom retry policy is when you need to customize the delay behavior, but don't need to adjust the logic used to determine whether a request should be retried or not. In this case, it isn't necessary to create a custom `RetryPolicy` class - instead, you can pass in a `DelayStrategy` into the `RetryPolicy` constructor.
Another scenario where it may be helpful to use a custom retry policy is when you need to customize the delay behavior, but don't need to adjust the logic used to determine whether a request should be retried or not. In this case, it isn't necessary to create a custom `RetryPolicy` class - instead, you can pass in a `DelayStrategy` into the `RetryPolicy` constructor.

In the below example, we create a customized delay strategy that uses a fixed sequence of delays that are iterated through as the number of retries increases. We then pass the strategy into the `RetryPolicy` constructor and set the constructed policy in our options.
```C# Snippet:SequentialDelayStrategy
Expand Down Expand Up @@ -153,7 +153,7 @@ SecretClientOptions options = new SecretClientOptions()
```

> **_A note to library authors:_**
Library-specific response classifiers _will_ be respected if a user sets a custom policy deriving from `RetryPolicy` as long as they call into the base `ShouldRetry` method. If a user doesn't call the base method, or sets a `HttpPipelinePolicy` in the `RetryPolicy` property, then the library-specific response classifiers _will not_ be respected.
Library-specific response classifiers _will_ be respected if a user sets a custom policy deriving from `RetryPolicy` as long as they call into the base `ShouldRetry` method. If a user doesn't call the base method, or sets a `HttpPipelinePolicy` in the `RetryPolicy` property, then the library-specific response classifiers _will not_ be respected.

## User provided HttpClient instance

Expand All @@ -168,25 +168,4 @@ SecretClientOptions options = new SecretClientOptions

## Configuring a proxy

```C# Snippet:HttpClientProxyConfiguration
using HttpClientHandler handler = new HttpClientHandler()
{
Proxy = new WebProxy(new Uri("http://example.com"))
};

SecretClientOptions options = new SecretClientOptions
{
Transport = new HttpClientTransport(handler)
};
```

## Configuring a proxy using environment variables

You can also configure a proxy using the following environment variables:

* `HTTP_PROXY`: the proxy server used on HTTP requests.
* `HTTPS_PROXY`: the proxy server used on HTTPS requests.
* `ALL_PROXY`: the proxy server used on HTTP and HTTPS requests in case `HTTP_PROXY` or `HTTPS_PROXY` are not defined.
* `NO_PROXY`: a comma-separated list of hostnames that should be excluded from proxying.

**Warning:** setting these environment variables will affect every new client created within the current process.
This guidance has moved to [Configure a proxy when using the Azure SDK for .NET](https://learn.microsoft.com/dotnet/azure/sdk/configure-proxy).
20 changes: 0 additions & 20 deletions sdk/core/Azure.Core/tests/samples/ConfigurationSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Azure.Core.Pipeline;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
Expand Down Expand Up @@ -71,24 +69,6 @@ public void SettingHttpClient()
#endregion
}

[Test]
public void HttpClientProxyConfiguration()
{
#region Snippet:HttpClientProxyConfiguration

using HttpClientHandler handler = new HttpClientHandler()
{
Proxy = new WebProxy(new Uri("http://example.com"))
};

SecretClientOptions options = new SecretClientOptions
{
Transport = new HttpClientTransport(handler)
};

#endregion
}

[Test]
public void SetPollyRetryPolicy()
{
Expand Down

0 comments on commit 7a804c5

Please sign in to comment.