aboutsummaryrefslogtreecommitdiff
path: root/src/test/httpsrv/httpconnectionmonitor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/httpsrv/httpconnectionmonitor.cpp')
-rw-r--r--src/test/httpsrv/httpconnectionmonitor.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/test/httpsrv/httpconnectionmonitor.cpp b/src/test/httpsrv/httpconnectionmonitor.cpp
new file mode 100644
index 0000000..4eb6817
--- /dev/null
+++ b/src/test/httpsrv/httpconnectionmonitor.cpp
@@ -0,0 +1,72 @@
1#include "httpconnectionmonitor.h"
2#include "http.h"
3#include <sys/stat.h>
4
5HttpConnectionMonitor::HttpConnectionMonitor()
6{
7}
8
9HttpConnectionMonitor::~HttpConnectionMonitor()
10{
11}
12
13bool HttpConnectionMonitor::onNewConnection( Connection *pCon )
14{
15 Http hp( pCon );
16
17 pCon->readInput( 60, 0 );
18 printf("#######################\n%s\n#######################\n", pCon->getInput() );
19
20 while( hp.parseRequest() == false );
21 printf("Done parsing.\n\n");
22
23 if( hp.getRequestType() == Http::reqGet )
24 {
25 printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() );
26 if( !strcmp( hp.getRequestURI(), "/" ) )
27 {
28 std::string content("<html><head><title>Server Test</test></head><body>This is a test of a new system where all the pages will be more or less dynamic...<br>If you want to try to login, you can do that here:<br><form method=\"post\" action=\"showvars\" enctype=\"multipart/form-data\">Name: <input type=\"text\" name=\"name\"><br>Password: <input type=\"password\" name=\"pass\"><br><input type=\"submit\" name=\"action\" value=\"login\"></form></body></html>");
29 hp.buildResponse();
30 hp.setResponseContent(
31 "text/html",
32 content.c_str(),
33 content.size()
34 );
35 hp.sendResponse();
36 }
37 else
38 {
39 std::string content("<html><head><title>URL Not Found</test></head><body>There is no content mapped to the URL you requested. Please try another one.</body></html>");
40 hp.buildResponse( 404, "File not found.");
41 hp.setResponseContent(
42 "text/html",
43 content.c_str(),
44 content.size()
45 );
46 hp.sendResponse();
47 }
48 }
49 else
50 {
51 printf("Non get: %s\n", hp.getRequestTypeStr() );
52 }
53 pCon->writeOutput();
54
55 if( pCon->hasInput() )
56 {
57 std::string s( pCon->getInput(), pCon->getInputAmnt() );
58
59 printf("Reamining data\n==============\n%s\n==============\n",
60 s.c_str() );
61 }
62
63 pCon->disconnect();
64
65 return true;
66}
67
68bool HttpConnectionMonitor::onClosedConnection( Connection *pCon )
69{
70 return true;
71}
72