[integration URL, headers to drop] 'api.anthropic.com' => ['https://llm.int.exe.xyz', ['x-api-key', 'authorization']], 'api.openai.com' => ['https://llm.int.exe.xyz', ['authorization']], ]; add_filter('pre_http_request', function ($response, $args, $url) { if ($response !== false) { return $response; } $to = wp_parse_url($url); $route = EXE_DEV_INTEGRATIONS[strtolower($to['host'] ?? '')] ?? null; if ($route === null || ($to['scheme'] ?? '') !== 'https' || isset($to['port'])) { return false; } [$integration, $drop] = $route; $drop[] = 'host'; $headers = $args['headers'] ?? []; if (!is_array($headers)) { $headers = WP_Http::processHeaders($headers)['headers']; } foreach (array_keys($headers) as $name) { if (in_array(strtolower($name), $drop, true)) { unset($headers[$name]); } } $args['headers'] = $headers; // Integrations live on exe.dev's private network, which WordPress's // "safe" requests would refuse. $args['reject_unsafe_urls'] = false; $path = ($to['path'] ?? '/') . (isset($to['query']) ? '?' . $to['query'] : ''); return wp_remote_request($integration . $path, $args); }, 10, 3);