From 745875139b5ee46e469927d410364bfeeedb2995 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 11 Oct 2006 15:47:45 +0000 Subject: Despite some svn oddness, I'm now moving to a new setup for the tests, that's very much like the original one, but now using build. You will need the latest build in order to build the tests. --- src/tests/httpsrv/httpconnectionmonitor.cpp | 80 +++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/tests/httpsrv/httpconnectionmonitor.cpp (limited to 'src/tests/httpsrv/httpconnectionmonitor.cpp') 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 @@ +#include "httpconnectionmonitor.h" +#include "http.h" +#include + +HttpConnectionMonitor::HttpConnectionMonitor() +{ +} + +HttpConnectionMonitor::~HttpConnectionMonitor() +{ +} + +bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) +{ + printf("Got connection on port %d\n", nPort ); + Http hp( pCon ); + + pCon->readInput( 60, 0 ); + printf("#######################\n%s\n#######################\n", pCon->getInput() ); + + while( hp.parseRequest() == false ); + printf("Done parsing.\n\n"); + + if( hp.getRequestType() == Http::reqGet ) + { + printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() ); + if( !strcmp( hp.getRequestURI(), "/" ) ) + { + std::string content("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>"); + hp.buildResponse(); + hp.setResponseContent( + "text/html", + content.c_str(), + content.size() + ); + hp.sendResponse(); + } + else + { + 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>"); + hp.buildResponse( 404, "File not found."); + hp.setResponseContent( + "text/html", + content.c_str(), + content.size() + ); + hp.sendResponse(); + } + } + else + { + printf("Non get: %s\n", hp.getRequestTypeStr() ); + pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n"); + } + pCon->writeOutput(); + //for( int j = 0; j < 50; j++ ) + { + pCon->readInput( 1, 0 ); + //printf("Size so far: %d\n", pCon->getInputAmnt() ); + } + + if( pCon->hasInput() ) + { + std::string s( pCon->getInput(), pCon->getInputAmnt() ); + + pCon->printInputDebug(); + //printf("Reamining data\n==============\n%s\n==============\n", + // s.c_str() ); + } + + pCon->disconnect(); + + return true; +} + +bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) +{ + return true; +} + -- cgit v1.2.3