Class ProtoHttpRequestBuilder<TResponse, TBuilder>
The state and fluent surface every HTTP-based request builder shares: the client, context, target, headers, authenticator resolution and base-address resolver, plus the hooks each protocol uses to record how its authentication and headers were configured. A protocol's request shape (a REST route, a GraphQL document) stays in the derived builder.
public abstract class ProtoHttpRequestBuilder<TResponse, TBuilder> where TResponse : ProtoHttpResponse where TBuilder : ProtoHttpRequestBuilder<TResponse, TBuilder>
Type Parameters
TResponseTBuilder
- Inheritance
-
ProtoHttpRequestBuilder<TResponse, TBuilder>
- Derived
- Inherited Members
- Extension Methods
Constructors
ProtoHttpRequestBuilder(HttpClient, ProtoExecutionContext, string, ProtoProtocol, string?)
protected ProtoHttpRequestBuilder(HttpClient client, ProtoExecutionContext context, string targetName, ProtoProtocol protocol, string? clientEntityName = null)
Parameters
clientHttpClientcontextProtoExecutionContexttargetNamestringprotocolProtoProtocolclientEntityNamestring
Properties
AuthenticatorFactory
The authenticator factory configured for this builder, if any.
protected Func<ProtoExecutionContext, IProtoHttpAuthenticator>? AuthenticatorFactory { get; set; }
Property Value
BaseAddressResolver
The per-test base-address resolver, when the client registered one.
protected Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>? BaseAddressResolver { get; set; }
Property Value
Client
The client the request is sent over.
protected HttpClient Client { get; }
Property Value
ClientEntityName
The registry key of the client the request actually uses; the client entity's id.
protected string ClientEntityName { get; }
Property Value
Context
The test execution context requests and traces belong to.
protected ProtoExecutionContext Context { get; }
Property Value
Headers
The configured headers; mutable so a derived builder can compose them directly.
protected Dictionary<string, string> Headers { get; }
Property Value
Protocol
The protocol identity: names, trace source, observation kinds and coverage category.
protected ProtoProtocol Protocol { get; }
Property Value
ResolvedAuthenticator
The authenticator an earlier request resolved, reused so it is created once.
protected IProtoHttpAuthenticator? ResolvedAuthenticator { get; set; }
Property Value
TargetName
The registered target name requests, observations and collectors agree on.
protected string TargetName { get; }
Property Value
Methods
ApplyAuthenticationAsync(HttpRequestMessage, ProtoTraceOperation?, CancellationToken)
Resolves and applies authentication for one request, caching the authenticator.
protected ValueTask<IProtoHttpAuthenticator?> ApplyAuthenticationAsync(HttpRequestMessage request, ProtoTraceOperation? operation, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageoperationProtoTraceOperationcancellationTokenCancellationToken
Returns
Auth(IProtoHttpAuthenticator)
Applies the request's explicit authenticator; inherited authentication is replaced.
public TBuilder Auth(IProtoHttpAuthenticator authenticator)
Parameters
authenticatorIProtoHttpAuthenticator
Returns
- TBuilder
Auth<TAuthenticator>(params object[])
Applies an authenticator created through ProtoAuthenticatorFactory.
public TBuilder Auth<TAuthenticator>(params object[] constructorArgs) where TAuthenticator : class, IProtoHttpAuthenticator
Parameters
constructorArgsobject[]
Returns
- TBuilder
Type Parameters
TAuthenticator
Header(string, string)
public TBuilder Header(string name, string value)
Parameters
Returns
- TBuilder
OnAuthenticationConfigured(string, Type?)
Records how authentication was configured; the protocol chooses attributes or events.
protected abstract void OnAuthenticationConfigured(string source, Type? authenticatorType)
Parameters
OnHeaderConfigured(string, bool)
Records a header configuration; isNewHeader is false on replacement.
protected virtual void OnHeaderConfigured(string name, bool isNewHeader)
Parameters
ResolveResponseOptions()
The response options this protocol registered.
protected ProtoHttpResponseOptions ResolveResponseOptions()
Returns
TraceConfiguration(string, string, IReadOnlyDictionary<string, string?>)
Writes a successful configuration event under the protocol's trace source.
protected void TraceConfiguration(string kind, string name, IReadOnlyDictionary<string, string?> attributes)
Parameters
kindstringnamestringattributesIReadOnlyDictionary<string, string>
UseAuthenticatorFactory(Func<ProtoExecutionContext, IProtoHttpAuthenticator>?)
Adopts the authenticator factory a protocol's lifecycle hook resolved for the test, so the builder resolves the same authenticators for its named client. A protocol integration calls this when it composes its request builder.
public TBuilder UseAuthenticatorFactory(Func<ProtoExecutionContext, IProtoHttpAuthenticator>? authenticatorFactory)
Parameters
authenticatorFactoryFunc<ProtoExecutionContext, IProtoHttpAuthenticator>The factory the protocol resolved, or null for none.
Returns
- TBuilder
UseBaseAddressResolver(Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>?)
Adopts the per-test base-address resolver the resolved client registered, when it has one; a request builder without one uses the client's own BaseAddress.
public TBuilder UseBaseAddressResolver(Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>? baseAddressResolver)
Parameters
baseAddressResolverFunc<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>The resolver the client resolution carries, or null for none.
Returns
- TBuilder
WithoutAuth()
Disables inherited or class-level authentication for this request builder.
public TBuilder WithoutAuth()
Returns
- TBuilder