diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-04-06 19:13:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-04-06 19:13:51 +0000 |
commit | 514721c24c7212c084ad2530e8239ff121097818 (patch) | |
tree | bfe5d346e767df47d10a5631e33a2e0540d72604 /src/tests/fastcgi.cpp | |
parent | aaeaa599a14642e916bbd8a32a208ee96a26eaac (diff) | |
download | libbu++-514721c24c7212c084ad2530e8239ff121097818.tar.gz libbu++-514721c24c7212c084ad2530e8239ff121097818.tar.bz2 libbu++-514721c24c7212c084ad2530e8239ff121097818.tar.xz libbu++-514721c24c7212c084ad2530e8239ff121097818.zip |
Ok, I rearranged some things, we have a tools dir now, those build by default.
Also I added a bunch of classes that I've been tinkering with that are almost
ready for use, so I figured I may as well throw them in here.
Diffstat (limited to 'src/tests/fastcgi.cpp')
-rw-r--r-- | src/tests/fastcgi.cpp | 81 |
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 | |||
3 | class Cgi : public Bu::FastCgi | ||
4 | { | ||
5 | public: | ||
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 | |||
73 | int main() | ||
74 | { | ||
75 | Cgi c( 8789 ); | ||
76 | |||
77 | c.run(); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||