| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #pragma once
- #include "http_define.h"
- #if USE_NET_HTTP_WEBSITE
- #include <functional>
- #include <vector>
- #include <unordered_map>
- #include "util/map.hpp"
- #include "util/json.h"
- namespace ylib
- {
- namespace network
- {
- namespace http
- {
- /*绑定域名*/
- struct domain_info
- {
- domain_info() {
- https = false;
- }
- // 是否HTTPS
- bool https;
- // 域名
- std::string domain;
- };
- class server;
- class router;
- class website;
- /***************************************************************
- * Class:控制中心
- ***************************************************************/
- class center :public ylib::error_base
- {
- public:
- center();
- ~center();
- /******************************************************************
- * function:创建
- * param
- * config : 配置项
- * return:
- * 失败可通过 last_error() 返回错误信息。
- ******************************************************************/
- bool create(const start_config& config);
- bool start();
- /******************************************************************
- * function:关闭
- ******************************************************************/
- void close();
- network::http::server* server(ushort port);
- network::http::website* website(const std::string& host);
- network::http::website* website_byname(const std::string& name);
- const start_config& config() { return m_config; }
- private:
- //所有监听端口
- std::vector<ushort> listen_ports();
- //端口是否需要SSL
- bool port_have_ssl(ushort port);
- void rebuild_host_index();
- private:
- // HTTP 服务
- std::vector<network::http::server*> m_server;
- // 站点
- std::vector<network::http::website*> m_website;
- // Host -> 站点 精确匹配
- std::unordered_map<std::string, network::http::website*> m_host_index;
- // 通配站点(0.0.0.0 / *)
- std::vector<network::http::website*> m_catchall_websites;
- // 启动信息
- start_config m_config;
- public:
- uint64 m_temp[10];
- };
- }
- }
- }
- #endif
|