root/trunk/VerboseLoop.d

Revision 34, 1.4 kB (checked in by xammy, 3 years ago)

Fixed some bugs due to changes in Tango API

Line 
1 import  fcgi.Request;
2 import  fcgi.Connection;
3
4 import tango.io.stream.Format;
5
6 int main (char[][] args)
7 {
8     FastCGIConnection connection = new FastCGIConnection ();
9     FastCGIRequest request = new FastCGIRequest(connection);
10     int counter = 0;
11
12     auto Stdout = new FormatOutput!(char) (request.stdout);
13     while ( request.accept () )
14     {
15         Stdout ("Content-type: text/html\r\n\r\n") ("<head><title>My first page</title></head>");
16         Stdout ("<body>");
17         Stdout ("<h1> Hello world </h1><br>") ("Request #") (++counter) ("<br><br>\n");
18
19         // Write IP
20         auto ip = ("REMOTE_ADDR" in request.args);
21         if (ip)
22             Stdout ("Your IP is ") (*ip) ("<br><br>\n");
23         else
24             Stdout ("Cannot extract IP :(<br><br>\n");
25
26         // Write stdin
27         Stdout ("Data: \"") ();
28         while (1)
29         {
30             char[10] string;
31             int rd = request.stdin.read(string);
32             if (rd > 0)
33                 Stdout(string[0 .. rd]) ();
34             if (rd != string.length)
35             {
36                 Stdout ("\"<br><br>");
37                 break;
38             }
39         }
40
41         // Write all
42         Stdout ("\nEnvironment:<br>");
43         foreach (key, value; request.args)
44         {
45             Stdout ("request.args[\"")(key) ("\"] = \"") (value) ("\"<br>\n");
46         }
47
48         Stdout ("</body>\n") ();
49
50         request.exitStatus = 0;
51     }
52
53     return request.exitStatus;
54 }
Note: See TracBrowser for help on using the browser.