aboutsummaryrefslogtreecommitdiff
path: root/src/tests/fastcgi.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tests/fastcgi.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/tests/fastcgi.cpp b/src/tests/fastcgi.cpp
new file mode 100644
index 0000000..53dd68a
--- /dev/null
+++ b/src/tests/fastcgi.cpp
@@ -0,0 +1,81 @@
1#include "bu/fastcgi.h"
2
3class Cgi : public Bu::FastCgi
4{
5public:
6 Cgi() :
7 Bu::FastCgi::FastCgi()
8 {
9 }
10
11 Cgi( int iPort ) :
12 Bu::FastCgi::FastCgi( iPort )
13 {
14 }
15
16 virtual ~Cgi()
17 {
18 }
19
20 virtual int request( const StrHash &hParams,
21 const Bu::FString &sStdIn, Bu::Stream &sStdOut,
22 Bu::Stream &sStdErr )
23 {
24 Bu::FString sOut("Content-Type: text/html\r\n\r\n");
25 sOut += "<html><body><h1>Environment:</h1><ul>";
26 for( StrHash::const_iterator i = hParams.begin(); i; i++ )
27 {
28 sOut += "<li>" + i.getKey() + " = " +
29 i.getValue() + "</li>";
30 }
31 sOut += "</ul>";
32 char buf[2048];
33 sOut += "<h1>Cwd:</h1><ul><li>";
34 sOut += getcwd( buf, 2048 );
35 sOut += "</li></ul>";
36 sOut += "<h1>Stdin:</h1>";
37 sOut.formatAppend("%d bytes<pre>", sStdIn.getSize() );
38 Bu::FString sL, sR;
39 for( Bu::FString::const_iterator i = sStdIn.begin();
40 i; i++ )
41 {
42 sL.formatAppend("%02X ",
43 (unsigned int)((unsigned char)*i) );
44 if( *i < 27 )
45 sR += ". ";
46 else
47 sR.formatAppend("&#%d; ",
48 (unsigned int)((unsigned char)*i) );
49 if( sL.getSize()/3 == 8 )
50 {
51 sOut += sL + " | " + sR + "\n";
52 sL = sR = "";
53 }
54 }
55 if( sL != "" )
56 {
57 while( sL.getSize()/3 < 8 )
58 sL += " ";
59 sOut += sL + " | " + sR + "\n";
60 }
61 sOut += "</pre><hr/><pre>";
62 sOut += sStdIn;
63 sOut += "</pre>";
64 sOut += "<form method=\"post\" enctype=\"multipart/form-data\"><textarea name=\"bob\"></textarea><br /><input type=\"file\" name=\"somefile\" /><br /><input type=\"submit\" name=\"yeah\" value=\"try it\" /></form>";
65 sOut += "</body></html>";
66
67 sStdOut.write( sOut );
68
69 return 0;
70 }
71};
72
73int main()
74{
75 Cgi c( 8789 );
76
77 c.run();
78
79 return 0;
80}
81