HttpRecordingHandler Class
A delegating handler that records and replays HTTP interactions for testing.
public sealed class HttpRecordingHandler : DelegatingHandler, IAsyncDisposable- Inheritance
DelegatingHandlerHttpRecordingHandler- Implements
Constructors
| Name | Description |
|---|---|
| HttpRecordingHandler(IHttpRecordingStore, HttpRecordingOptions?) | Initializes a new instance of the HttpRecordingHandler class without an inner handler. |
| HttpRecordingHandler(HttpMessageHandler, IHttpRecordingStore, HttpRecordingOptions?) | Initializes a new instance of the HttpRecordingHandler class with an inner handler. |
HttpRecordingHandler overloads
HttpRecordingHandler(IHttpRecordingStore, HttpRecordingOptions?)
HttpRecordingHandler.csInitializes a new instance of the HttpRecordingHandler class without an inner handler.
public HttpRecordingHandler(IHttpRecordingStore store, HttpRecordingOptions? options = null)Parameters
storeIHttpRecordingStore- The store used to load and save recorded entries.
optionsHttpRecordingOptions?- The recording options. Because there is no inner handler, no real HTTP call can be made, so the mode must be
HttpRecordingMode.Replayand the miss behavior must not beHttpRecordingMissBehavior.Passthrough.
HttpRecordingHandler(HttpMessageHandler, IHttpRecordingStore, HttpRecordingOptions?)
HttpRecordingHandler.csInitializes a new instance of the HttpRecordingHandler class with an inner handler.
public HttpRecordingHandler(HttpMessageHandler innerHandler, IHttpRecordingStore store, HttpRecordingOptions? options = null)Parameters
innerHandlerHttpMessageHandler- The inner handler.
storeIHttpRecordingStore- The store used to load and save recorded entries.
optionsHttpRecordingOptions?- The recording options.
Methods
| Name | Description |
|---|---|
| DisposeAsync() | Saves the recordings when HttpRecordingOptions.AutoSave is enabled, then disposes the handler. |
| InitializeAsync(CancellationToken) | Loads existing recordings from the store. If not called explicitly, the first HttpRecordingHandler.SendAsync call will call it automatically. |
| SaveAsync(CancellationToken) | Saves all recorded entries to the store, waiting for any in-flight recording to complete first. |
DisposeAsync()
HttpRecordingHandler.csSaves the recordings when HttpRecordingOptions.AutoSave is enabled, then disposes the handler.
net10.0
public ValueTask DisposeAsync()net11.0
public ValueTask DisposeAsync()Returns
Remarks
The save is not skipped when the handler has already been disposed synchronously: an HttpClient owns its handler by default and disposes it first, so by the time this runs the handler is usually disposed already. The recorded entries are still in memory and are what needs persisting.
InitializeAsync(CancellationToken)
HttpRecordingHandler.csLoads existing recordings from the store. If not called explicitly, the first HttpRecordingHandler.SendAsync call will call it automatically.
net10.0
public Task InitializeAsync(CancellationToken cancellationToken = default)net11.0
public Task InitializeAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
Remarks
Nothing is loaded in HttpRecordingMode.Record mode: saving there replaces the store's content instead of appending to it.
SaveAsync(CancellationToken)
HttpRecordingHandler.csSaves all recorded entries to the store, waiting for any in-flight recording to complete first.
public Task SaveAsync(CancellationToken cancellationToken = default)