#include "HttpServer.h"
void HandleFunction(int client_fd,
std::string requested_URL,
std::string client_IP,
unsigned short client_port) {
std::cout << "In handlefunction, URL '"
<< requested_URL << "', IP "
<< client_IP << ", port "
<< client_port << std::endl;
// Write our response.
FILE *f = fdopen(client_fd, "w+");
if (f == NULL) {
return;
}
std::stringstream ss;
ss << "HTTP/1.1 200 OK\r\n"
<< "Content-type: text/html\r\n"
<< "\r\n"
<< "\n"
<< "Hello, " << client_IP << ":" << client_port << "!\n"
<< "You asked for:\n"
<< "
\n"
<< " " << requested_URL << "\n"
<< "
\n"
<< "\n";
fwrite(ss.str().c_str(), ss.str().size(), 1, f);
fclose(f);
}
int main(int argc, char **argv) {
HttpServer hs(argv[1]);
hs.AcceptDispatch(&HandleFunction);
return EXIT_SUCCESS;
}