Skip to content
Snippets Groups Projects
index.php 871 B
Newer Older
  • Learn to ignore specific revisions
  • Maxime Veber's avatar
    Maxime Veber committed
    <?php
    
    
    $vars = [];
    
    if (!$_POST) {
        $_POST = json_decode(file_get_contents('php://input'), true);
        $_POST['content-type'] = $_SERVER['HTTP_CONTENT_TYPE'] ?? '?';
    }
    
    foreach ($_SERVER as $k => $v) {
        switch ($k) {
            default:
                if (0 !== strpos($k, 'HTTP_')) {
                    continue 2;
                }
            // no break
            case 'SERVER_NAME':
            case 'SERVER_PROTOCOL':
            case 'REQUEST_URI':
            case 'REQUEST_METHOD':
            case 'PHP_AUTH_USER':
            case 'PHP_AUTH_PW':
                $vars[$k] = $v;
        }
    }
    
    $json = json_encode($vars, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    
    
    switch ($vars['REQUEST_URI']) {
        case '/long-to-execute':
            sleep(5);
            break;
        case '/faster':
            sleep(1);
            break;
    }
    
    header('Content-Type: application/json', true);
    
    echo $json;