|
Revision 34, 1.6 kB
(checked in by xammy, 3 years ago)
|
Fixed some bugs due to changes in Tango API
|
| Line | |
|---|
| 1 |
import fcgi.Thread; |
|---|
| 2 |
import fcgi.Connection; |
|---|
| 3 |
import fcgi.Request; |
|---|
| 4 |
|
|---|
| 5 |
import tango.io.stream.Format; |
|---|
| 6 |
|
|---|
| 7 |
public int run (FastCGIRequest request) |
|---|
| 8 |
{ |
|---|
| 9 |
static int counter = 0; |
|---|
| 10 |
|
|---|
| 11 |
auto stdout = new FormatOutput !(char) (request.stdout); |
|---|
| 12 |
|
|---|
| 13 |
stdout ("Content-type: text/html\r\n\r\n") ("<head><title>My first page</title></head>"); |
|---|
| 14 |
stdout ("<body>"); |
|---|
| 15 |
|
|---|
| 16 |
// some counters |
|---|
| 17 |
synchronized |
|---|
| 18 |
counter++; |
|---|
| 19 |
stdout ("<h1> Hello world </h1><br>") ("Request #") (counter) ("<br><br>\n"); |
|---|
| 20 |
|
|---|
| 21 |
// Write IP |
|---|
| 22 |
auto ip = ("REMOTE_ADDR" in request.args); |
|---|
| 23 |
if (ip) |
|---|
| 24 |
{ |
|---|
| 25 |
stdout ("Your IP is ") (*ip) ("<br><br>\n"); |
|---|
| 26 |
} |
|---|
| 27 |
else |
|---|
| 28 |
{ |
|---|
| 29 |
stdout ("Cannot extract IP :(<br><br>\n"); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
// Write stdin |
|---|
| 33 |
stdout ("Data: \"") (); |
|---|
| 34 |
while (1) |
|---|
| 35 |
{ |
|---|
| 36 |
char[10] string; |
|---|
| 37 |
int rd = request.stdin.read (string); |
|---|
| 38 |
if (rd > 0) |
|---|
| 39 |
stdout (string [0 .. rd]); |
|---|
| 40 |
if (rd != string.length) |
|---|
| 41 |
{ |
|---|
| 42 |
stdout ("\"<br><br>"); |
|---|
| 43 |
break; |
|---|
| 44 |
} |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
// Write all arguments |
|---|
| 48 |
stdout ("\nYour environment:<br>\n"); |
|---|
| 49 |
foreach (key, value; request.args) |
|---|
| 50 |
{ |
|---|
| 51 |
stdout ("request.args[\"") (key) ("\"] = \"") (value) ("\"<br>\n"); |
|---|
| 52 |
} |
|---|
| 53 |
stdout ("</body>\n") (); |
|---|
| 54 |
|
|---|
| 55 |
return 0; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
int main (char[][] args) |
|---|
| 59 |
{ |
|---|
| 60 |
FastCGIConnection connection = new FastCGIConnection (); |
|---|
| 61 |
|
|---|
| 62 |
return FastCGIThread.loop (connection, &run, true, 10); |
|---|
| 63 |
} |
|---|