2020-11-25 00:20:41 +01:00
|
|
|
#ifndef HTTP_SERVER_H
|
|
|
|
#define HTTP_SERVER_H
|
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <iostream>
|
2021-02-09 01:25:24 +01:00
|
|
|
#include <map>
|
2021-02-09 09:48:08 +01:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
#include <brynet/base/AppStatus.hpp>
|
|
|
|
#include <brynet/net/http/HttpFormat.hpp>
|
|
|
|
#include <brynet/net/http/HttpService.hpp>
|
|
|
|
#include <brynet/net/http/WebSocketFormat.hpp>
|
|
|
|
#include <brynet/net/wrapper/HttpServiceBuilder.hpp>
|
|
|
|
#include <brynet/net/wrapper/ServiceBuilder.hpp>
|
|
|
|
|
2021-02-08 11:01:15 +01:00
|
|
|
using namespace brynet;
|
|
|
|
using namespace brynet::net;
|
|
|
|
using namespace brynet::net::http;
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
class Request;
|
2021-04-28 22:50:05 +02:00
|
|
|
class Application;
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
class HTTPServer {
|
|
|
|
public:
|
|
|
|
int port;
|
|
|
|
int threads;
|
2021-02-08 11:01:15 +01:00
|
|
|
std::shared_ptr<TcpService> service;
|
2021-02-09 09:48:08 +01:00
|
|
|
wrapper::HttpListenerBuilder *listenBuilder;
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2021-04-28 21:17:57 +02:00
|
|
|
void http_callback_handler(Request *response);
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2021-04-28 21:17:57 +02:00
|
|
|
void httpEnterCallbackDefault(const HTTPParser &httpParser, const HttpSession::Ptr &session);
|
|
|
|
void wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload);
|
|
|
|
void closedCallbackDefault(const HttpSession::Ptr &session);
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2021-02-09 09:48:08 +01:00
|
|
|
virtual void configure();
|
2021-02-03 02:18:37 +01:00
|
|
|
virtual void initialize();
|
|
|
|
|
|
|
|
void main_loop();
|
|
|
|
|
2021-02-09 09:48:08 +01:00
|
|
|
HTTPServer();
|
|
|
|
virtual ~HTTPServer();
|
2021-02-09 01:25:24 +01:00
|
|
|
|
2021-04-28 22:50:05 +02:00
|
|
|
//move this to a sublcass
|
|
|
|
Application *application;
|
|
|
|
|
2021-02-09 01:25:24 +01:00
|
|
|
protected:
|
2021-04-28 21:17:57 +02:00
|
|
|
std::map<HttpSession *, Request *> _request_map;
|
|
|
|
std::mutex _request_map_mutex;
|
2020-11-25 00:20:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|