-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.jai
More file actions
62 lines (50 loc) · 1.62 KB
/
test.jai
File metadata and controls
62 lines (50 loc) · 1.62 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
#import "SimpleHTTP"(USE_MIDDLEWARE=false);
#import "Basic";
HELLO_RESPONSE :: "<html><head></head><body>Hello, world!</body></html>";
POST_RESPONSE :: "<html><head></head><body>Post response!</body></html>";
root :: (client: *HTTPRequest) -> HTTPResponse {
response : HTTPResponse;
response.status = 200;
response.body = copy_string(HELLO_RESPONSE);
return response;
}
post_only :: (client: *HTTPRequest) -> HTTPResponse {
response : HTTPResponse;
response.status = 200;
response.body = copy_string(POST_RESPONSE);
return response;
}
urldecode_test :: () {
tests := string.[
"hello", "hello",
"hello+world", "hello world",
"hello%20world", "hello world",
"%3Chtml%3e", "<html>"
];
passed := 0;
failed := 0;
for i:0..(tests.count/2)-1 {
in := tests[2*i];
out := tests[2*i+1];
if out != decode_uri_component(in) {
print("Test: Failed decoding '%'\n", in);
failed += 1;
} else {
passed += 1;
}
}
print("URLDecode test done.\n - Passed: %\n - Failed: %\n", passed, failed);
}
main :: () {
print("Running some tests:\n");
urldecode_test();
print("Now starting test server:\n");
server := http_server_setup("0.0.0.0", 2101);
http_register_url(*server, "/", .GET, root);
http_register_url(*server, "/post/", .POST, post_only);
print("Starting server on %:%\n", server.listen_host, server.listen_port);
err := http_server_run_single_threaded(*server);
if err != .NoProblem {
print("Server error: %\n", err);
}
}