aboutsummaryrefslogtreecommitdiff
path: root/src/tests/httpsrv
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/httpsrv')
-rw-r--r--src/tests/httpsrv/httpconnectionmonitor.cpp80
-rw-r--r--src/tests/httpsrv/httpconnectionmonitor.h16
-rw-r--r--src/tests/httpsrv/main.cpp22
3 files changed, 118 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
diff --git a/src/tests/httpsrv/httpconnectionmonitor.h b/src/tests/httpsrv/httpconnectionmonitor.h
new file mode 100644
index 0000000..30c0afd
--- /dev/null
+++ b/src/tests/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, int nPort );
13 bool onClosedConnection( Connection *pCon );
14};
15
16#endif
diff --git a/src/tests/httpsrv/main.cpp b/src/tests/httpsrv/main.cpp
new file mode 100644
index 0000000..2f1563c
--- /dev/null
+++ b/src/tests/httpsrv/main.cpp
@@ -0,0 +1,22 @@
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 printf("Listening on port 7331\n");
14 srv.startServer( 7331 );
15
16 for(;;)
17 {
18 srv.scanConnections( 5000, false );
19 }
20
21 return 0;
22}