forked from MechanisM/Tofu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-fcgi.c
34 lines (24 loc) · 884 Bytes
/
example-fcgi.c
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
#include <tofu.h>
#include <stdlib.h>
tofu_rep_t *first_handler(tofu_req_t *req) {
tofu_rep_t *rep = tofu_rep_init();
tofu_head(rep, "Content-Type", "text/html");
tofu_write(rep, "<!DOCTYPE html>\n<head><title>First</title></head>\n");
tofu_writef(rep, "<body>First handler: %s</body>\n", tofu_param(req, "param"));
return rep;
}
tofu_rep_t *second_handler(tofu_req_t *req) {
tofu_rep_t *rep = tofu_rep_init();
tofu_head(rep, "Content-Type", "text/html");
tofu_write(rep, "<!DOCTYPE html>\n<head><title>Second</title></head>\n");
tofu_writef(rep, "<body>Second handler: %s</body>\n", tofu_param(req, "param"));
return rep;
}
int main() {
tofu_ctx_t *ctx = tofu_ctx_init(TOFU_FCGI, NULL);
tofu_handle_with(ctx, GET, "/first/:param", first_handler);
tofu_handle_with(ctx, GET, "/second/:param", second_handler);
tofu_loop(ctx);
tofu_ctx_free(ctx);
return 0;
}