Serving the same content via two ports (HTTP and HTTPS).
#include <ehs.h>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include "common.h"
using namespace std;
class MyEHS :
public EHS {
ostringstream oss;
oss <<
"ehs_mirror: Secure - " << (request->
Secure() ?
"yes" :
"no") << endl
response->
SetBody ( oss.str().c_str(), oss.str().length() );
return HTTPRESPONSECODE_200_OK;
}
};
int main ( int argc, char ** argv )
{
cout << getEHSconfig() << endl;
if ((argc != 2) && (argc != 5)) {
string cmd(basename(argv[0]));
cout << "Usage: " << cmd << " <port> [<sslport> <certificate file> <passphrase>]" << endl;
return 0;
}
MyEHS plainEHS;
MyEHS *sslEHS = NULL;
EHSServerParameters oSP;
oSP["port"] = argv[1];
oSP["mode"] = "threadpool";
try {
plainEHS.StartServer(oSP);
if (argc == 5) {
sslEHS = new MyEHS;
oSP["port"] = argv[2];
oSP["https"] = 1;
oSP["mode"] = "threadpool";
oSP["certificate"] = argv[3];
oSP["passphrase"] = argv[4];
sslEHS->SetSourceEHS(plainEHS);
sslEHS->StartServer(oSP);
}
kbdio kbd;
cout << "Press q to terminate ..." << endl;
while (!(plainEHS.ShouldTerminate() ||
(sslEHS && sslEHS->ShouldTerminate()) ||
kbd.qpressed()))
{
usleep(300000);
}
plainEHS.StopServer();
if (NULL != sslEHS) {
sslEHS->StopServer();
}
} catch (exception &e) {
cerr << "ERROR: " << e.what() << endl;
}
delete sslEHS;
return 0;
}
EHS provides HTTP server functionality to a child class.
This class represents a clients HTTP request.
std::string RemoteAddress()
Retrieves the peer's IP address.
bool Secure() const
Retrieves the security status.
int RemotePort()
Retrieves the peer's port.
This class represents what is sent back to the client.
void SetBody(const char *ipsBody, size_t inBodyLength)
Sets the body of this instance.