actually check if the requestCrawl endpoint exists via HEAD

This commit is contained in:
Evan Jarrett
2026-02-21 14:24:37 -06:00
parent f90a46e0a4
commit 356f9d529a
3 changed files with 45 additions and 3 deletions
+41 -1
View File
@@ -30,6 +30,9 @@ var KnownRelays = []KnownRelay{
{Name: "Microcosm France", URL: "https://relay3.fr.hose.cam"},
{Name: "Upcloud", URL: "https://relay.upcloud.world"},
{Name: "Blacksky", URL: "https://atproto.africa"},
{Name: "Hayes", URL: "https://relay.hayescmd.net"},
{Name: "Xero", URL: "https://relay.xero.systems"},
{Name: "Feeds Blue", URL: "https://relay.feeds.blue"},
}
// RelayHTTPError indicates the relay responded with a non-200 status code.
@@ -62,6 +65,7 @@ type HostStatus struct {
type RelayStatus struct {
Online bool
Error string
HasRequestCrawl bool
HasListReposByCollection bool
RepoStatus *RepoStatus
HostStatus *HostStatus
@@ -73,7 +77,7 @@ func CheckRelayStatus(relayURL, hostname, did string) *RelayStatus {
result := &RelayStatus{}
var mu sync.Mutex
var wg sync.WaitGroup
wg.Add(3)
wg.Add(4)
// Mark relay as online if any check gets an HTTP response
markOnline := func() {
@@ -82,6 +86,20 @@ func CheckRelayStatus(relayURL, hostname, did string) *RelayStatus {
mu.Unlock()
}
// Probe requestCrawl
go func() {
defer wg.Done()
supported, online := probeRequestCrawl(relayURL)
if online {
markOnline()
}
if supported {
mu.Lock()
result.HasRequestCrawl = true
mu.Unlock()
}
}()
// Check host status
go func() {
defer wg.Done()
@@ -139,6 +157,28 @@ func CheckRelayStatus(relayURL, hostname, did string) *RelayStatus {
return result
}
// probeRequestCrawl checks if a relay supports the requestCrawl endpoint using a HEAD request.
// A 4xx response (e.g. 405 Method Not Allowed) means the endpoint exists.
// A 5xx or connection failure means it's broken or unsupported.
func probeRequestCrawl(relayURL string) (supported bool, online bool) {
client := &http.Client{Timeout: 5 * time.Second}
req, err := http.NewRequest("HEAD", relayURL+SyncRequestCrawl, nil)
if err != nil {
return false, false
}
resp, err := client.Do(req)
if err != nil {
return false, false
}
defer resp.Body.Close()
// Any HTTP response means the relay is online.
// 4xx (typically 405 Method Not Allowed) = endpoint exists.
// 5xx = endpoint is broken.
return resp.StatusCode >= 400 && resp.StatusCode < 500, true
}
// probeListReposByCollection checks if a relay supports the listReposByCollection endpoint.
// Returns (supported, online) — online is true if we got any HTTP response.
func probeListReposByCollection(relayURL string) (supported bool, online bool) {
+2
View File
@@ -21,6 +21,7 @@ type RelayStatusView struct {
URL string
Online bool
Error string
HasRequestCrawl bool
HasListReposByCollection bool
RepoStatus *atproto.RepoStatus
HostStatus *atproto.HostStatus
@@ -75,6 +76,7 @@ func (ui *AdminUI) handleRelayStatus(w http.ResponseWriter, r *http.Request) {
URL: relayURL,
Online: status.Online,
Error: status.Error,
HasRequestCrawl: status.HasRequestCrawl,
HasListReposByCollection: status.HasListReposByCollection,
RepoStatus: status.RepoStatus,
HostStatus: status.HostStatus,
@@ -22,7 +22,7 @@
<td>
<div class="flex flex-wrap gap-1">
{{if .Online}}
<span class="badge badge-ghost badge-sm">requestCrawl</span>
{{if .HasRequestCrawl}}<span class="badge badge-ghost badge-sm">requestCrawl</span>{{end}}
{{if .HasListReposByCollection}}<span class="badge badge-ghost badge-sm">listReposByCollection</span>{{end}}
{{else}}
<span class="text-base-content/30 text-sm">-</span>
@@ -47,7 +47,7 @@
{{end}}
</td>
<td class="text-right">
{{if .Online}}
{{if and .Online .HasRequestCrawl}}
<button class="btn btn-ghost btn-sm gap-1"
hx-post="/admin/relays/crawl?url={{.URL}}&name={{.Name}}"
hx-target="closest tr"