src/HTTPServer.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 07 Apr 2022 23:04:12 +0200
branchv_0
changeset 2 4b05b16b97e6
parent 0 7b70918c30af
child 3 1184f3de5533
permissions -rw-r--r--
configurable TCP listener port + RequestHandler interface

/**
 * Relational pipes
 * Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <vector>
#include <string>
#include <ctype.h>
#include <memory>

namespace relpipe {
namespace tr {
namespace httpd {

class HTTPServer {
private:
	class HTTPServerImpl;
	HTTPServerImpl* impl;

	HTTPServer(HTTPServerImpl* impl) : impl(impl) {
	}


public:

	class Header {
	public:
		std::string name;
		std::string value;
	};

	class Request {
	public:
		std::vector<Header> header;
		std::string host;
		std::string method;
		std::string url;
		std::string body;
	};

	class Response {
	public:
		std::vector<Header> header;
		uint16_t code;
		std::string body;
	};

	class RequestHandler {
	public:

		virtual const Response handle(const Request& request);
	};

	class Options {
	public:
		uint16_t tcpPort = 8080;
	};

	virtual ~HTTPServer();
	HTTPServer(const HTTPServer&) = delete;
	HTTPServer& operator=(const HTTPServer&) = delete;

	void setRequestHandler(std::shared_ptr<RequestHandler> handler);

	static HTTPServer* create(Options options);

};

}
}
}