summaryrefslogtreecommitdiff
path: root/test/it_url.testserver.php
blob: 64e6674499f6509a93efe343397dc1a59f749dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
$stderr = fopen('php://stderr', 'w');
fwrite($stderr, "Got Request: '" . $_SERVER['REQUEST_URI'] . "'\n");
$base = 'http://' . $_SERVER['HTTP_HOST'];

switch ($_SERVER['PHP_SELF'])
{
	case "/":
		echo 'Testserver root output';
		break;

	case "/temp_redirect":
		header("Location: $base/redirect_target?type=temporary", true, 303);
		break;

	case "/perm_redirect":
		header("Location: $base/redirect_target?type=permanent", true, 301);
		break;

	case "/created_redirect":
		header("Location: $base/redirect_target?type=created", true, 201);
		echo "Testserver output *before* created redirect";
		break;

	case "/redirect_loop":
		if ($_REQUEST['num'] > 0)
			header("Location: $base/redirect_loop?num=" . ($_REQUEST['num'] - 1), true, 303);
		break;

	case "/nohost_redirect":
		header('Location: /redirect_target?type=nohost', true, 301);
		exit;

	case "/relative_redirect":
		header('Location: ../redirect_target?type=relative', true, 301);
		exit;

	case "/redirect_target":
		echo 'Testserver output after ' . $_REQUEST['type'] . ' redirect';
		break;

	case "/long_sleep":
		sleep(6);
		echo 'Testserver output after long sleep';
		break;

	case "/short_sleep":
		sleep(4);
		echo 'Testserver output after short sleep';
		break;

	case "/slow_response":
		for ($i = 0; $i < 6; $i++) {
			sleep(1);
			echo "Testserver slow output $i\n";
		}
		break;

	case "/get_server_value":
		echo $_SERVER[$_REQUEST['key']];
		break;

	case "/repeat":
		for ($i = 0; $i < $_REQUEST['num']; $i++)
			echo $_REQUEST['string'];
		break;

	case "/empty":
		http_response_code(204);
		break;

	default:
		http_response_code(404);
		fwrite($stderr, "Unknown path '$_SERVER[PHP_SELF]' not handled!\n");
}