GopeedLab/gopeed · error

webhook URL is empty

Error message

webhook URL is empty

What it means

Returned by sendWebhookToUrl (webhook.go:99-102) when it is invoked with an empty string as the URL. The internal delivery path (sendWebhooks, webhook.go:147-151) filters empty entries before calling, so in practice this surfaces through the public test endpoint TestWebhookUrl, which the REST API calls with the raw request body (pkg/rest/api.go:416-424). It is a pure input-validation guard: no HTTP request is attempted.

Source

Thrown at pkg/download/webhook.go:101

		for _, urlInterface := range urlsInterface {
			if url, ok := urlInterface.(string); ok && url != "" {
				urls = append(urls, url)
			}
		}
		if len(urls) == 0 {
			return nil
		}
		return urls
	}

	return nil
}

// sendWebhookToUrl sends webhook data to a single URL
// Returns the HTTP status code and any error that occurred
func (d *Downloader) sendWebhookToUrl(url string, data *WebhookData) (int, error) {
	if url == "" {
		return 0, fmt.Errorf("webhook URL is empty")
	}

	jsonData, err := json.Marshal(data)
	if err != nil {
		return 0, err
	}

	client := &http.Client{
		Timeout: webhookTimeout,
	}

	req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonData))
	if err != nil {
		return 0, err
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("User-Agent", "Gopeed-Webhook/1.0")

View on GitHub (pinned to 7b7327ffb3)

Solutions

  1. Provide the full webhook URL in the test request body
  2. Trim and validate the input client-side before submitting the test call
  3. If integrating the Go API, guard with strings.TrimSpace(url) != "" before calling TestWebhookUrl

Example fix

// before
err := downloader.TestWebhookUrl(req.URL) // req.URL == ""

// after
url := strings.TrimSpace(req.URL)
if url == "" {
	writeError(w, "webhook url is required")
	return
}
err := downloader.TestWebhookUrl(url)
Defensive patterns

Strategy: validation

Validate before calling

url := strings.TrimSpace(req.URL)
if url == "" {
	writeError(w, "webhook url is required")
	return
}

Try / catch

if err := downloader.TestWebhookUrl(url); err != nil {
	w.WriteHeader(http.StatusBadRequest)
	json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
}

Prevention

When it happens

Trigger: POSTing the webhook-test API with {"url": ""} or an omitted url field; calling downloader.TestWebhookUrl("") from Go; UI code submitting the test form before the user typed a URL.

Common situations: Frontend forms that submit on empty input; automation scripts testing webhook config before filling the URL; whitespace-only URLs pass the empty check but then fail later in http.NewRequest, so trimmed validation upstream is the real fix.

Related errors


AI-assisted analysis of GopeedLab/gopeed@7b7327ffb3 (2026-08-16). Data as JSON: /api/errors/8753f7d990fc7d8b. Report an issue: GitHub.