-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
120 lines (112 loc) · 3.87 KB
/
Copy pathtest.html
File metadata and controls
120 lines (112 loc) · 3.87 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page for HTTP Server</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background-color: #f5f5f5;
}
h1 {
color: #333;
}
.test-section {
background: white;
padding: 20px;
margin: 20px 0;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background-color: #45a049;
}
pre {
background-color: #f4f4f4;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
</style>
</head>
<body>
<h1>HTTP Server Test Page</h1>
<div class="test-section">
<h2>GET Requests</h2>
<button onclick="testGet('/')">Test GET /</button>
<button onclick="testGet('/hello')">Test GET /hello</button>
<button onclick="testGet('/api/status')">Test GET /api/status</button>
<button onclick="testGet('/api/custom')">Test GET /api/custom</button>
<pre id="get-result"></pre>
</div>
<div class="test-section">
<h2>POST Request</h2>
<button onclick="testPost()">Test POST /api/data</button>
<pre id="post-result"></pre>
</div>
<div class="test-section">
<h2>Authentication Test</h2>
<button onclick="testSecret(false)">Test /api/secret (no auth)</button>
<button onclick="testSecret(true)">Test /api/secret (with auth)</button>
<pre id="auth-result"></pre>
</div>
<script>
const baseUrl = 'http://127.0.0.1:8080';
async function testGet(path) {
const resultEl = document.getElementById('get-result');
try {
const response = await fetch(baseUrl + path);
const text = await response.text();
resultEl.textContent = `Status: ${response.status} ${response.statusText}\n\n${text}`;
} catch (error) {
resultEl.textContent = `Error: ${error.message}`;
}
}
async function testPost() {
const resultEl = document.getElementById('post-result');
try {
const response = await fetch(baseUrl + '/api/data', {
method: 'POST',
headers: {
'Content-Type': 'text/plain'
},
body: 'Hello from browser POST request'
});
const text = await response.text();
resultEl.textContent = `Status: ${response.status} ${response.statusText}\n\n${text}`;
} catch (error) {
resultEl.textContent = `Error: ${error.message}`;
}
}
async function testSecret(withAuth) {
const resultEl = document.getElementById('auth-result');
try {
const headers = {};
if (withAuth) {
headers['Authorization'] = 'Bearer secret-token';
}
const response = await fetch(baseUrl + '/api/secret', {
headers: headers
});
const text = await response.text();
resultEl.textContent = `Status: ${response.status} ${response.statusText}\n\n${text}`;
} catch (error) {
resultEl.textContent = `Error: ${error.message}`;
}
}
</script>
</body>
</html>