Hosting: Make IHostingEnvironment.ApplicationMainUrl nullable#22558
Conversation
Update usage in HttpsCheck healthcheck and add unit tests to verify refactor.
|
Claude finished @AndyButland's task in 2m 51s —— View job PR ReviewTarget: Makes
Suggestions
ApprovedClean, correct implementation. The |
IHostingEnvironment.ApplicationMainUrl nullable
There was a problem hiding this comment.
Pull request overview
This PR updates Umbraco’s hosting abstraction to reflect that the application’s “main URL” is not always available, aligning the public IHostingEnvironment API with the existing nullable backing field behavior and adjusting the HTTPS health check + unit tests accordingly.
Changes:
- Change
IHostingEnvironment.ApplicationMainUrlfromUritoUri?and updateAspNetCoreHostingEnvironmentto return the nullable value without!. - Refactor
HttpsCheckto short-circuit cleanly when the application URL is unavailable, and widen per-check methods tointernalfor isolated unit testing. - Add
HttpsCheckTestscovering null-URL behavior and scheme /UseHttpsbranches.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/HealthChecks/HttpsCheckTests.cs | Adds unit tests for the nullable URL behavior and per-branch HTTPS check results. |
| src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs | Updates ApplicationMainUrl implementation to return Uri? without null-forgiving. |
| src/Umbraco.Core/Hosting/IHostingEnvironment.cs | Makes ApplicationMainUrl nullable in the public interface. |
| src/Umbraco.Core/HealthChecks/Checks/Security/HttpsCheck.cs | Refactors URL availability handling and exposes internal methods for test isolation. |
Description
In Umbraco 18 we can make
IHostingEnvironment.ApplicationMainUrlnullable to correctly reflect that it can benullwhenApplicationUrlDetectionisNoneand no explicit URL is configured. This comes from the changes in Follows on from #22307.The only compile error to resolve was in the
HttpsCheckhealth check, which I've done, and also took the opportunity to add unit tests for these checks.