summaryrefslogtreecommitdiff
path: root/src/test/httpsrv
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/httpsrv')
-rw-r--r--src/test/httpsrv/httpconnectionmonitor.cpp72
-rw-r--r--src/test/httpsrv/httpconnectionmonitor.h16
-rw-r--r--src/test/httpsrv/main.cpp21
3 files changed, 109 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
diff --git a/src/test/httpsrv/httpconnectionmonitor.h b/src/test/httpsrv/httpconnectionmonitor.h
new file mode 100644
index 0000000..63f29e4
--- /dev/null
+++ b/src/test/httpsrv/httpconnectionmonitor.h
@@ -0,0 +1,16 @@
1#ifndef HTTPCONNECTIONMONITOR_H
2#define HTTPCONNECTIONMONITOR_H
3
4#include "connectionmonitor.h"
5
6class HttpConnectionMonitor : public ConnectionMonitor
7{
8public:
9 HttpConnectionMonitor();
10 ~HttpConnectionMonitor();
11
12 bool onNewConnection( Connection *pCon );
13 bool onClosedConnection( Connection *pCon );
14};
15
16#endif
diff --git a/src/test/httpsrv/main.cpp b/src/test/httpsrv/main.cpp
new file mode 100644
index 0000000..4ee1ad3
--- /dev/null
+++ b/src/test/httpsrv/main.cpp
@@ -0,0 +1,21 @@
1#include "connectionmanager.h"
2#include "httpconnectionmonitor.h"
3
4int main()
5{
6 printf("Starting server...\n");
7
8 ConnectionManager srv;
9 HttpConnectionMonitor http;
10
11 srv.setConnectionMonitor( &http );
12
13 srv.startServer( 7331, 40 );
14
15 for(;;)
16 {
17 srv.scanConnections( 5000, false );
18 }
19
20 return 0;
21}