summaryrefslogtreecommitdiff
path: root/src/tests/httpsrv/httpconnectionmonitor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/httpsrv/httpconnectionmonitor.cpp')
-rw-r--r--src/tests/httpsrv/httpconnectionmonitor.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/tests/httpsrv/httpconnectionmonitor.cpp b/src/tests/httpsrv/httpconnectionmonitor.cpp
new file mode 100644
index 0000000..ee1eab3
--- /dev/null
+++ b/src/tests/httpsrv/httpconnectionmonitor.cpp
@@ -0,0 +1,80 @@
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, int nPort )
14{
15 printf("Got connection on port %d\n", nPort );
16 Http hp( pCon );
17
18 pCon->readInput( 60, 0 );
19 printf("#######################\n%s\n#######################\n", pCon->getInput() );
20
21 while( hp.parseRequest() == false );
22 printf("Done parsing.\n\n");
23
24 if( hp.getRequestType() == Http::reqGet )
25 {
26 printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() );
27 if( !strcmp( hp.getRequestURI(), "/" ) )
28 {
29 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>");
30 hp.buildResponse();
31 hp.setResponseContent(
32 "text/html",
33 content.c_str(),
34 content.size()
35 );
36 hp.sendResponse();
37 }
38 else
39 {
40 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>");
41 hp.buildResponse( 404, "File not found.");
42 hp.setResponseContent(
43 "text/html",
44 content.c_str(),
45 content.size()
46 );
47 hp.sendResponse();
48 }
49 }
50 else
51 {
52 printf("Non get: %s\n", hp.getRequestTypeStr() );
53 pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n");
54 }
55 pCon->writeOutput();
56 //for( int j = 0; j < 50; j++ )
57 {
58 pCon->readInput( 1, 0 );
59 //printf("Size so far: %d\n", pCon->getInputAmnt() );
60 }
61
62 if( pCon->hasInput() )
63 {
64 std::string s( pCon->getInput(), pCon->getInputAmnt() );
65
66 pCon->printInputDebug();
67 //printf("Reamining data\n==============\n%s\n==============\n",
68 // s.c_str() );
69 }
70
71 pCon->disconnect();
72
73 return true;
74}
75
76bool HttpConnectionMonitor::onClosedConnection( Connection *pCon )
77{
78 return true;
79}
80