Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(custom): explain when a base URL includes an HTTP method (#89911)

Tom Owers583d2a5b68e9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py
index 2f8c87a16018..da4c7e65f707 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py
@@ -529,11 +529,26 @@ def validate_manifest_urls(manifest: dict[str, Any], team_id: int) -> tuple[bool
return True, None
+_HTTP_METHODS = frozenset({"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"})
+
+
+def _has_leading_http_method(url: str) -> bool:
+ """True when a URL starts with an HTTP verb, e.g. a "POST https://..." pasted from API docs.
+ urlparse then reads no host, so the URL is rejected for a missing hostname it plainly has."""
+ head, _, rest = url.strip().partition(" ")
+ return bool(rest) and head.upper() in _HTTP_METHODS
+
+
def _check_url(url: str, team_id: int) -> tuple[bool, str | None]:
# `_url_hostname` mirrors the real connect host (backslash/whitespace-normalized) so the
# validator can't be fooled into vetting a different host than the request reaches.
hostname = _url_hostname(url)
if not hostname:
+ if _has_leading_http_method(url):
+ return (
+ False,
+ "Remove the HTTP method from the URL and enter just the address (for example, https://api.example.com).",
+ )
return False, f"URL {url!r} is missing a hostname"
if is_cloud() and urlparse(url).scheme != "https":
return False, f"URL {url!r} must use https:// on PostHog Cloud"
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py
index 7a9df96036c7..f7251d26a9e8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py
@@ -316,6 +316,14 @@ class TestValidateManifestUrls(SimpleTestCase):
ok, err = validate_manifest_urls(manifest, team_id=999)
assert not ok, err
+ def test_rejects_base_url_with_http_method_prefix(self):
+ # A user who pastes "POST https://..." from API docs used to get an unhelpful
+ # "missing a hostname" — the message must instead tell them to drop the method.
+ manifest = _minimal_manifest(base_url="POST https://api.example.com/v1")
+ ok, err = validate_manifest_urls(manifest, team_id=999)
+ assert not ok
+ assert "Remove the HTTP method" in (err or "")
+
@override_settings(CLOUD_DEPLOYMENT="US")
@patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.custom.source._is_host_safe",