HttpsServer.cpp 1.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * HttpsServer.cpp
 *
 *  Created on: 25.05.2018
 *      Author: Micha Mueller
 */

#include "HttpsServer.h"
#include <iostream>

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void HttpsServer::requestHandler::operator()(server::request const &request, server::connection_ptr connection) {
	server::string_type ip = source(request);
	unsigned int port = request.source_port;
	std::ostringstream data;

	server::response_header headers[] = { {"Connection", "close"}, {"Content-Type", "text/plain"} };
	data << "Hello, " << ip << ':' << port << '!' << std::endl;

	connection->set_status(server::connection::ok);
	connection->set_headers(boost::make_iterator_range(headers, headers + 2));
	connection->write(data.str());
}

void HttpsServer::requestHandler::log(const server::string_type& message) {
	LOG(error) << message;
}
27
28
29
30
31
32
33
34
35
36
37
38
39

HttpsServer::HttpsServer(const std::string& host, const std::string& port,
		pluginVector_t& plugins) :
		_host(host), _port(port), _plugins(plugins) {

	server::options options(_handler);
	_server = new server(options.address(_host).port(_port));
}

HttpsServer::~HttpsServer() {
	delete _server;
}