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(proxy): omit redirect metadata when disabled (#90396)

Reece Jonesba9307c7cac4
diff --git a/posthog/temporal/proxy_service/cloudflare.py b/posthog/temporal/proxy_service/cloudflare.py
index 0cc62283bf2f..5cbbf22f6871 100644
--- a/posthog/temporal/proxy_service/cloudflare.py
+++ b/posthog/temporal/proxy_service/cloudflare.py
@@ -263,8 +263,9 @@ def create_custom_hostname(domain: str, root_redirect_url: str | None = None) ->
"min_tls_version": CLOUDFLARE_MIN_TLS_VERSION,
},
},
- "custom_metadata": {"root_redirect_url": root_redirect_url or ""},
}
+ if root_redirect_url:
+ payload["custom_metadata"] = {"root_redirect_url": root_redirect_url}
response = requests.post(url, headers=_get_headers(), json=payload, timeout=CLOUDFLARE_API_TIMEOUT_S)
data = _handle_response(response)
diff --git a/posthog/temporal/proxy_service/test/test_cloudflare.py b/posthog/temporal/proxy_service/test/test_cloudflare.py
index d66d9e6fd41a..058e54255218 100644
--- a/posthog/temporal/proxy_service/test/test_cloudflare.py
+++ b/posthog/temporal/proxy_service/test/test_cloudflare.py
@@ -147,6 +147,17 @@ class TestCreateCustomHostname(SimpleTestCase):
timeout=8.0,
)
+ @patch("posthog.temporal.proxy_service.cloudflare.requests.post")
+ def test_omits_redirect_metadata_when_root_redirect_is_disabled(self, post_request):
+ response = Mock()
+ response.json.return_value = {"success": True, "result": _hostname_payload()}
+ post_request.return_value = response
+
+ create_custom_hostname("p.example.com")
+
+ request_payload = post_request.call_args.kwargs["json"]
+ assert "custom_metadata" not in request_payload
+
@patch("posthog.temporal.proxy_service.cloudflare.requests.patch")
def test_preserves_existing_metadata(self, patch_request):
hostname = _parse_hostname(_hostname_payload(custom_metadata={"existing": "value"}))