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;
}