aboutsummaryrefslogtreecommitdiff
path: root/examples/fastcgi.c
blob: 5d3c4b1ad9203e86726ed5408556b2495f8a7557 (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
#include <magi.h>


void response(magi_request *r)
{
    magi_response(r,
        "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' "
            "'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>"
        "<html xmlns='http://www.w3.org/1999/xhtml'>"
        "<head><title>Fast CGI</title></head>"
        "<body>Hi!</body>"
        "</html>");
}

int main(int argc, char const *argv[])
{
    magi_session session;
    magi_request request;
    magi_request_init(&request);
    magi_session_init(&session);
    magi_session_inet(&session, "localhost", "9973");
    magi_session_unix(&session, "unix.sock");
    while (magi_fastcgi(&session, &request)) {
        if (request.error) {
            magi_response_error(&request);
        } else {
            response(&request);
        }
        magi_request_free(&request);
    }
    magi_request_free(&request);
    magi_session_free(&session);
    return 0;
}