Fix missing BaseAddress on OData HttpClient#79
Conversation
PanoramicData.OData.Client passes relative URIs to HttpClient.SendAsync internally. Without BaseAddress set on the HttpClient, this causes an InvalidOperationException at runtime even though ODataClientOptions.BaseUrl is configured correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the OData client DI registration to set HttpClient.BaseAddress from ODataSettings.Url, preventing runtime InvalidOperationException when the PanoramicData OData client sends relative URIs.
Changes:
- Set
HttpClient.BaseAddressduring OData client registration based onODataSettings.Url.
Comments suppressed due to low confidence (2)
IntegratoR.OData/Common/Extensions/ApplicationDependencyInjection.cs:122
HttpClient.BaseAddressURI resolution is sensitive to a trailing slash. With a configured URL likehttps://.../data(no trailing/, as used in tests), resolving a relative request URI like$metadataorCustomerswill drop thedatasegment and producehttps://.../$metadata/https://.../Customers. Consider normalizingBaseAddressto ensure it ends with/(and keepODataClientOptions.BaseUrlconsistent) so relative OData paths stay under the intended/data/endpoint.
httpClient.BaseAddress = new Uri(settings.Url);
var options = new ODataClientOptions
{
BaseUrl = settings.Url,
HttpClient = httpClient
IntegratoR.OData/Common/Extensions/ApplicationDependencyInjection.cs:123
- This change introduces important runtime behavior (ensuring relative URIs can be sent via
HttpClient), but there’s no unit test asserting theODataClient’s underlyingHttpClienthas aBaseAddressset (or that a relative request no longer throwsInvalidOperationException). Consider adding a focused DI test that resolvesODataClientand verifies it can issue a relative request without throwing (using a fakeHttpMessageHandler), to prevent regressions.
httpClient.BaseAddress = new Uri(settings.Url);
var options = new ODataClientOptions
{
BaseUrl = settings.Url,
HttpClient = httpClient
};
| httpClient.Timeout = TimeSpan.FromSeconds(settings.Timeout); | ||
| httpClient.BaseAddress = new Uri(settings.Url); | ||
|
|
There was a problem hiding this comment.
new Uri(settings.Url) will throw (UriFormatException/ArgumentNullException) if ODataSettings.Url is empty or malformed. Since ODataSettings.Url defaults to string.Empty and there’s no options validation in this registration path, consider validating with Uri.TryCreate(..., UriKind.Absolute, out var uri) and throwing a clearer configuration error (e.g., indicating ODataSettings:Url must be a valid absolute URL).
Summary
HttpClient.BaseAddressfromODataSettings.Urlduring OData client registrationHttpClient.SendAsyncinternally, which requiresBaseAddressto be set — without it, anInvalidOperationExceptionis thrown at runtimeTest plan
dotnet buildpasses (0 errors)🤖 Generated with Claude Code