root/trunk/VerboseApp.d

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

Fixed some bugs due to changes in Tango API

Line 
1 import  fcgi.Application;
2 import  fcgi.Connection;
3 import  fcgi.Request;
4
5 import tango.io.stream.Format;
6 import tango.text.convert.Layout;
7
8 class MyApp : FastCGIApplication
9 {
10     private FormatOutput!(char) stdout;
11     private FormatOutput!(char) stderr;
12     private static int counter = 0;
13
14     this (int id, FastCGIRequest request)
15     {
16         auto layout = new Layout!(char) ();
17        
18         stdout = new FormatOutput!(char) (layout, request.stdout);
19         stderr = new FormatOutput!(char) (layout, request.stderr);
20
21     }
22    
23     int run()
24     {
25         stdout ("Content-type: text/html\r\n\r\n") ("<head><title>My first page</title></head>");
26         stdout ("<body>");
27
28         // some counters
29         synchronized
30             counter++;
31         stdout ("<h1> Hello world </h1><br>") ("Request #") (counter) (", Thread #") (id) ("<br><br>\n");
32
33         // Write IP
34         auto ip = ("REMOTE_ADDR" in request.args);
35         if (ip)
36         {
37             stdout ("Your IP is ") (*ip) ("<br><br>\n");
38         }
39         else
40         {
41             stdout ("Cannot extract IP :(<br><br>\n");
42         }
43
44         // Write stdin
45         stdout ("Data: \"") ();
46         while (1)
47         {
48             char[10] string;
49             int rd = request.stdin.read(string);
50             if (rd > 0)
51                 stdout(string[0 .. rd]);
52             if (rd != string.length)
53             {
54                 stdout ("\"<br><br>");
55                 break;
56             }
57         }
58
59         // Write all arguments
60         stdout ("\nYour environment:<br>\n");
61         foreach (key, value; request.args)
62         {
63             stdout ("request.args[\"")(key) ("\"] = \"") (value) ("\"<br>\n");
64         }
65         stdout ("</body>\n") ();
66
67         return 0;
68     }
69 }
70
71 int main(char[][] args)
72 {
73     FastCGIConnection connection = new FastCGIConnection ();
74
75     return FastCGIApplication.loop!(MyApp) (connection, true, 10);
76 }
Note: See TracBrowser for help on using the browser.