HttpsServer.cpp 1.19 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * HttpsServer.cpp
 *
 *  Created on: 25.05.2018
 *      Author: Micha Mueller
 */

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

struct HttpsServer::requestHandler {
    void 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 << '!';

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

    void log(const server::string_type& message) {
        LOG(error) << message;
    }
};

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