Ejemplo n.º 1
0
    $response = array("error" => "TooManyRequests", "message" => "Your monthly limit has been exceeded");
    return json_encode($response);
}
$request_headers = apache_request_headers();
$basic_auth = base64_decode(str_replace('Basic ', '', $request_headers['Authorization']));
$api_key_elements = explode(':', $basic_auth);
$api_key = $api_key_elements[1];
header("Content-Type: application/json; charset=utf-8");
if ($api_key == 'PNG123') {
    if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
        echo mock_empty_response();
    } else {
        echo mock_png_response();
    }
} else {
    if ($api_key == 'JPG123') {
        if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
            echo mock_empty_response();
        } else {
            echo mock_jpg_response();
        }
    } else {
        if ($api_key == 'LIMIT123') {
            echo mock_limit_reached_response();
        } else {
            echo mock_invalid_response();
        }
    }
}
file_put_contents(SESSION_FILE, serialize($session));
ob_end_flush();
Ejemplo n.º 2
0
{
    header("Location: http://webservice/output/2351zxcf2359.png");
    header("Content-Type: application/json; charset=utf-8");
    header("Compression-Count: 1");
    $response = array("input" => array("size" => 12345, "type" => "image/png"), "output" => array("size" => 1234, "type" => "image.png", "ratio" => 0.307));
    return json_encode($response);
}
function mock_jpg_response()
{
    header("Location: http://webservice/output/2351zxcf2359.jpg");
    header("Content-Type: application/json; charset=utf-8");
    header("Compression-Count: 1");
    $response = array("input" => array("size" => 12345, "type" => "image/jpg"), "output" => array("size" => 1234, "type" => "image/jpg", "ratio" => 0.307));
    return json_encode($response);
}
$request_headers = apache_request_headers();
$basic_auth = base64_decode(str_replace('Basic ', '', $request_headers['Authorization']));
$api_key_elements = explode(':', $basic_auth);
$api_key = $api_key_elements[1];
header('HTTP/1.1 201 Created');
if ($api_key == 'PNG123') {
    print_r(mock_png_response());
} else {
    if ($api_key == 'JPG123') {
        print_r(mock_jpg_response());
    } else {
        header('HTTP/1.1 401 Unauthorized');
        print_r(json_encode(array("error" => "Unauthorized", "message" => "Credentials are invalid")));
    }
}
ob_end_flush();