Class RecordingHandler
A DelegatingHandler that passes requests on to an inner handler and records each exchange, so a test can inspect the traffic of a real or emulated DynamoDB: the signed request and the response as they went over the wire. Pass it as HttpHandler.
public sealed class RecordingHandler : DelegatingHandler, IDisposable
- Inheritance
-
RecordingHandler
- Implements
- Inherited Members
Examples
using var recorder = new RecordingHandler(); // sends to the real service with its own SocketsHttpHandler
using var client = new DynamoDbClient(new DynamoDbClientOptions { HttpHandler = recorder });
await client.GetItemAsync(new GetItemRequest { TableName = "Shop", Key = new Item { ["pk"] = "USER#alice", ["sk"] = "PROFILE" } }, ct);
var wire = recorder.Exchanges.Single().Response!.BodyText;
Remarks
Recordings contain data you may not want to keep. Requests carry the items you write and, in the Authorization and
X-Amz-Security-Token headers, the access key id and the session token (the signature does not reveal the secret
key, but a valid session token is a credential). Responses carry the items you read. Do not log, print or publish recordings
of real traffic, and do not attach them to bug reports without removing both.
The response body is read into memory before the client sees it and replaced by a copy, so the client reads it as usual. That makes every call wait for the whole body and keeps it in memory: use the handler to look at traffic in a test, not in production code or load tests.
The client retries throttling errors and server errors, so one call can be several exchanges: Exchanges lists every attempt. The handler is thread-safe; with concurrent calls, exchanges are listed in the order they completed.
Disposing this handler disposes the inner handler, as for every DelegatingHandler. The client does not dispose a handler it was given, so dispose the recording handler when the test is done.
Constructors
RecordingHandler()
Initializes a new instance of the RecordingHandler class that sends requests with a SocketsHttpHandler of its own, configured as the client configures the one it owns. Disposing this handler disposes it.
public RecordingHandler()
RecordingHandler(HttpMessageHandler)
Initializes a new instance of the RecordingHandler class that sends requests with innerHandler,
for example a StubHandler to look at what the client sends and receives in a test with canned responses.
Disposing this handler disposes innerHandler.
public RecordingHandler(HttpMessageHandler innerHandler)
Parameters
innerHandlerHttpMessageHandlerThe handler that sends the requests.
Exceptions
- ArgumentNullException
innerHandleris null.
Properties
Exchanges
Gets the exchanges recorded so far, oldest first. The list is a snapshot; get it again after more requests.
public IReadOnlyList<RecordedExchange> Exchanges { get; }
Property Value
Methods
SendAsync(HttpRequestMessage, CancellationToken)
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessagecancellationTokenCancellationToken