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