src/HTTPServer.h
branchv_0
changeset 2 4b05b16b97e6
parent 0 7b70918c30af
child 3 1184f3de5533
equal deleted inserted replaced
1:23c516259cc5 2:4b05b16b97e6
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    16  */
    17 
    17 
    18 #pragma once
    18 #pragma once
    19 
    19 
       
    20 #include <vector>
       
    21 #include <string>
       
    22 #include <ctype.h>
       
    23 #include <memory>
       
    24 
    20 namespace relpipe {
    25 namespace relpipe {
    21 namespace tr {
    26 namespace tr {
    22 namespace httpd {
    27 namespace httpd {
    23 
    28 
    24 class HTTPServer {
    29 class HTTPServer {
    29 	HTTPServer(HTTPServerImpl* impl) : impl(impl) {
    34 	HTTPServer(HTTPServerImpl* impl) : impl(impl) {
    30 	}
    35 	}
    31 
    36 
    32 
    37 
    33 public:
    38 public:
       
    39 
       
    40 	class Header {
       
    41 	public:
       
    42 		std::string name;
       
    43 		std::string value;
       
    44 	};
       
    45 
       
    46 	class Request {
       
    47 	public:
       
    48 		std::vector<Header> header;
       
    49 		std::string host;
       
    50 		std::string method;
       
    51 		std::string url;
       
    52 		std::string body;
       
    53 	};
       
    54 
       
    55 	class Response {
       
    56 	public:
       
    57 		std::vector<Header> header;
       
    58 		uint16_t code;
       
    59 		std::string body;
       
    60 	};
       
    61 
       
    62 	class RequestHandler {
       
    63 	public:
       
    64 
       
    65 		virtual const Response handle(const Request& request);
       
    66 	};
       
    67 
       
    68 	class Options {
       
    69 	public:
       
    70 		uint16_t tcpPort = 8080;
       
    71 	};
       
    72 
    34 	virtual ~HTTPServer();
    73 	virtual ~HTTPServer();
    35 	HTTPServer(const HTTPServer&) = delete;
    74 	HTTPServer(const HTTPServer&) = delete;
    36 	HTTPServer& operator=(const HTTPServer&) = delete;
    75 	HTTPServer& operator=(const HTTPServer&) = delete;
    37 
    76 
    38 	static HTTPServer* create();
    77 	void setRequestHandler(std::shared_ptr<RequestHandler> handler);
       
    78 
       
    79 	static HTTPServer* create(Options options);
    39 
    80 
    40 };
    81 };
    41 
    82 
    42 }
    83 }
    43 }
    84 }