]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/examples/_obsolete/hello/hello.c
5 // This function will be called by civetweb on every new request.
6 static int begin_request_handler(struct mg_connection
*conn
)
8 const struct mg_request_info
*request_info
= mg_get_request_info(conn
);
11 // Prepare the message we're going to send
12 int content_length
= snprintf(content
, sizeof(content
),
13 "Hello from civetweb! Remote port: %d",
14 request_info
->remote_port
);
16 // Send HTTP reply to the client
19 "Content-Type: text/plain\r\n"
20 "Content-Length: %d\r\n" // Always set Content-Length
23 content_length
, content
);
25 // Returning non-zero tells civetweb that our function has replied to
26 // the client, and civetweb should not send client any more data.
32 struct mg_context
*ctx
;
33 struct mg_callbacks callbacks
;
35 // List of options. Last element must be NULL.
36 const char *options
[] = {"listening_ports", "8080", NULL
};
38 // Prepare callbacks structure. We have only one callback, the rest are NULL.
39 memset(&callbacks
, 0, sizeof(callbacks
));
40 callbacks
.begin_request
= begin_request_handler
;
42 // Start the web server.
43 ctx
= mg_start(&callbacks
, NULL
, options
);
45 // Wait until user hits "enter". Server is running in separate thread.
46 // Navigating to http://localhost:8080 will invoke begin_request_handler().