<?php
// Debug endpoint para ver headers y response
error_log("=== DEBUG SSE ===");
error_log("Request URI: " . $_SERVER['REQUEST_URI']);
error_log("HTTP Accept: " . ($_SERVER['HTTP_ACCEPT'] ?? 'not set'));
error_log("Content-Type antes: " . (headers_sent() ? 'Already sent' : 'Not sent'));

// Forzar headers
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Access-Control-Allow-Origin: *');

error_log("Content-Type después: " . (headers_sent() ? 'Already sent' : 'Not sent'));

echo "event: debug\n";
echo "data: " . json_encode([
    'uri' => $_SERVER['REQUEST_URI'],
    'accept' => $_SERVER['HTTP_ACCEPT'] ?? 'not set',
    'time' => date('H:i:s'),
    'headers_sent' => headers_sent()
]) . "\n\n";

flush();
?>