Add to git.
[rws.git] / examples / hello.c
1 /* Simplest possible example of a shared object script.
2  * - by Richard W.M. Jones <rich@annexia.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * $Id: hello.c,v 1.3 2002/12/01 16:16:04 rich Exp $
19  */
20
21 #include "rws_request.h"
22
23 int
24 handle_request (rws_request rq)
25 {
26   http_request http_request = rws_request_http_request (rq);
27   io_handle io = rws_request_io (rq);
28
29   int close;
30   http_response http_response;
31
32   /* Begin response. */
33   http_response = new_http_response (pth_get_pool (current_pth),
34                                      http_request, io,
35                                      200, "OK");
36   http_response_send_headers (http_response,
37                               /* Content type. */
38                               "Content-Type", "text/plain",
39                               /* End of headers. */
40                               NULL);
41   close = http_response_end_headers (http_response);
42
43   if (http_request_is_HEAD (http_request)) return close;
44
45   io_fprintf (io, "hello, world!");
46
47   return close;
48 }