fix: isWebBricksBackendResource() must extract path from full URLs before matching /public

Bug: when fetchUi('/public') resolves to http://host:port/public, the
isWebBricksBackendResource() check compared the full URL string against
'/public' and always returned false, so _webbricks_=1 was never added.

Fix: extract the path component from full URLs (strip scheme+host) before
running the .ui/.dspy/public/root detection logic. All HTTP methods
(getText/getJson/postJson/postForm) delegate to withBackendContextIfNeeded
which calls isWebBricksBackendResource, so this fix covers all code paths.
This commit is contained in:
yumoqing 2026-05-20 22:54:59 +08:00
parent b7cffab3f9
commit 2b3dd84a13

View File

@ -54,9 +54,21 @@ fun withWebBricksRequestContext(
* Detect URLs that need WebBricks backend context (_webbricks_=1).
* Covers both direct .ui/.dspy paths and index fallback paths that the
* server resolves to .ui files (e.g. "/" index.ui, "/public" index.ui).
*
* Handles both full URLs (http://host:port/public) and path-only strings (/public).
*/
fun String.isWebBricksBackendResource(): Boolean {
val path = substringBefore('?').substringBefore('#')
val withoutQuery = substringBefore('?').substringBefore('#')
// Extract path component: strip scheme+host for full URLs, keep as-is for paths
val path = if (withoutQuery.contains("://")) {
// Full URL: find first '/' after "://"
val afterScheme = withoutQuery.substringAfter("://")
"/" + afterScheme.substringAfter('/', missingDelimiterValue = "")
} else {
withoutQuery
}
val normalized = path.trimEnd('/')
// Direct .ui/.dspy resource