/**
* 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:
/** Attribute-value pair – header, cookie, GET or POST parameter */
class AVP {
public:
std::string name;
std::string value;
AVP(std::string name, std::string value) : name(name), value(value) {
}
virtual ~AVP() {
}
};
class Request {
public:
std::vector<AVP> header;
std::vector<AVP> cookie;
std::vector<AVP> getParameter;
std::vector<AVP> postParameter;
std::string host;
std::string method;
std::string url;
std::string body;
};
class Response {
public:
std::vector<AVP> header;
std::vector<AVP> cookie;
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);
};
}
}
}