src/HTTPServer.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 09 Apr 2022 17:50:46 +0200
branchv_0
changeset 4 37a86904145c
parent 3 1184f3de5533
child 8 90990c8b6aef
permissions -rw-r--r--
partial implementation of response and header templates

/**
 * 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;

		Header(std::string name, std::string value) : name(name), value(value) {
		}

		virtual ~Header() {
		}
	};

	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) = 0;

		virtual ~RequestHandler() = default;

	};

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

};

}
}
}