DefaultHttpRequestHandler Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| DefaultHttpRequestHandler() |
Initializes a new instance of the DefaultHttpRequestHandler class that uses an internally owned HttpClient for all requests. The internal client is disposed when DisposeAsync() is called. |
| DefaultHttpRequestHandler(Func<HttpRequestInfo,CancellationToken,Task<HttpClient>>) |
Initializes a new instance of the DefaultHttpRequestHandler class that selects an HttpClient per request via a caller-supplied callback — for example, to route different URLs through differently authenticated clients. |
| DefaultHttpRequestHandler(HttpClient) |
Initializes a new instance of the DefaultHttpRequestHandler class that uses the supplied HttpClient for all requests. |
DefaultHttpRequestHandler()
Initializes a new instance of the DefaultHttpRequestHandler class that uses an internally owned HttpClient for all requests. The internal client is disposed when DisposeAsync() is called.
public DefaultHttpRequestHandler();
Public Sub New ()
Applies to
DefaultHttpRequestHandler(Func<HttpRequestInfo,CancellationToken,Task<HttpClient>>)
Initializes a new instance of the DefaultHttpRequestHandler class that selects an HttpClient per request via a caller-supplied callback — for example, to route different URLs through differently authenticated clients.
public DefaultHttpRequestHandler(Func<Microsoft.Agents.AI.Workflows.Declarative.HttpRequestInfo,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Net.Http.HttpClient?>>? httpClientProvider);
new Microsoft.Agents.AI.Workflows.Declarative.DefaultHttpRequestHandler : Func<Microsoft.Agents.AI.Workflows.Declarative.HttpRequestInfo, System.Threading.CancellationToken, System.Threading.Tasks.Task<System.Net.Http.HttpClient>> -> Microsoft.Agents.AI.Workflows.Declarative.DefaultHttpRequestHandler
Public Sub New (httpClientProvider As Func(Of HttpRequestInfo, CancellationToken, Task(Of HttpClient)))
Parameters
- httpClientProvider
- Func<HttpRequestInfo,CancellationToken,Task<HttpClient>>
An optional callback invoked for each request. The callback receives the HttpRequestInfo
and should return a pre-configured HttpClient (e.g. with authentication or a custom
transport). Return null to fall back to the handler's shared internal
HttpClient.
Remarks
Ownership: the caller is solely responsible for the lifetime of clients returned by this callback. DefaultHttpRequestHandler will not dispose provider-returned clients; only the handler's internally owned fallback client is disposed by DisposeAsync().
Reuse: callers are expected to cache and reuse clients (for example, keyed by base URL or auth scope) across requests. Returning a newly allocated HttpClient on every invocation will leak sockets and handler resources.
Applies to
DefaultHttpRequestHandler(HttpClient)
Initializes a new instance of the DefaultHttpRequestHandler class that uses the supplied HttpClient for all requests.
public DefaultHttpRequestHandler(System.Net.Http.HttpClient httpClient);
new Microsoft.Agents.AI.Workflows.Declarative.DefaultHttpRequestHandler : System.Net.Http.HttpClient -> Microsoft.Agents.AI.Workflows.Declarative.DefaultHttpRequestHandler
Public Sub New (httpClient As HttpClient)
Parameters
- httpClient
- HttpClient
The HttpClient to use for all requests. The caller retains ownership of this instance; it is not disposed by DisposeAsync().
Exceptions
httpClient is null.