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