Derive the entrypoint URL scheme from the shared TLS predicate (closes #272)
All checks were successful
check / check (push) Successful in 3m44s

This commit was merged in pull request #286.
This commit is contained in:
2026-08-24 04:04:04 +02:00
parent 8d64259283
commit 48cf93ec7e
2 changed files with 293 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ import (
"gorm.io/gorm"
"sneak.berlin/go/webhooker/internal/database"
"sneak.berlin/go/webhooker/internal/delivery"
"sneak.berlin/go/webhooker/internal/reqtls"
)
// WebhookListItem holds data for the webhook list view.
@@ -427,16 +428,16 @@ func (h *Handlers) renderSourceDetail(
}
}
host := r.Host
scheme := "https"
if r.TLS == nil {
scheme = "http"
scheme := "http"
if reqtls.IsTLS(r) {
scheme = "https"
}
if fwdProto := r.Header.Get("X-Forwarded-Proto"); fwdProto != "" {
scheme = fwdProto
}
// The host is the client's Host header, unvalidated. It is
// inert only because source_detail.html renders BaseURL as
// text inside a <code> element; putting it in an href or any
// other URL context needs it constrained first.
baseURL := scheme + "://" + r.Host
// The template calls Webhook methods, which take pointer
// receivers; html/template cannot address a value stored in a map.
@@ -448,7 +449,7 @@ func (h *Handlers) renderSourceDetail(
"Entrypoints": NewEntrypointViews(entrypoints),
"Targets": delivery.NewTargetViews(targets),
"Events": events,
"BaseURL": scheme + "://" + host,
"BaseURL": baseURL,
}
h.renderTemplate(w, r, "source_detail.html", data)