#ifndef cpps_socket_httpserver_h__#define cpps_socket_httpserver_h__#include <cpps/cpps.h>#include <uv.h>#include <unordered_map>#include <string>#include "cpps_socket_server.h"namespace cpps {typedef phmap::flat_hash_map<std::string, std::string> http_request_header;static std::string CACHE_CONTROL = "Cache-Control";static std::string CONTENT_TYPE = "Content-Type";static std::string SERVER_HEADER = "Server";static std::string CONNECTION = "Connection";struct http_request {std::string method;std::string path;std::string uri;bool support_gzip;http_request_header headers;cpps_integer socket_index;std::string chunk;std::string body;std::string field;int32 keepalive;const char* body_buf;const char* header_buf;size_t body_len;size_t header_len;std::string ip_address;usint16 port;};class cpps_socket_httpserver_option{public:cpps_socket_httpserver_option(){option_ip = "0.0.0.0";}std::string option_ip;cpps::object exceptionfunc;cpps::object writefunc;cpps::object userdata;cpps::object notfoundfunc;cpps::object option_ssl;cpps::object option_certificate_file;cpps::object option_privatekey_file;};class cpps_socket_httpserver_session;class cpps_socket_httpserver_cachefile;class cpps_socket_httpserver_request;typedef phmap::flat_hash_map<std::string, cpps::object> http_route;typedef phmap::flat_hash_map<std::string, std::string> http_mime_type;typedef phmap::flat_hash_map<std::string, cpps_socket_httpserver_session*> http_session_list;typedef phmap::flat_hash_map<std::string, cpps_socket_httpserver_cachefile*> http_cachefile_list;typedef phmap::flat_hash_map<cpps_integer, cpps::cpps_value> http_request_list;class cpps_socket_httpserver : public cpps_socket_server{public:cpps_socket_httpserver();virtual ~cpps_socket_httpserver();void setcstate(cpps::C* cstate);cpps_socket_httpserver* setoption(cpps::object opt);cpps_socket_httpserver* listen(cpps::C* cstate, cpps::usint16 port, cpps::object _ssl_port);void register_handlefunc(std::string path, cpps::object func);void register_controller(cpps::object cls,cpps_value defaultset);bool isrunning();virtual void run();void update_session();void stop();void add_type(std::string mime, std::string ext);const std::string& get_type_ref(std::string& ext);std::string get_type(std::string ext);cpps::object gethandlefunc(std::string path);cpps::object getcontroller(std::string controllername);cpps_socket_httpserver_session* create_seesion(cpps::C* c);cpps_socket_httpserver_session* get_session(std::string session_id);cpps_socket_httpserver_cachefile* create_cachefile(std::string &filepath,std::string &content, cpps_integer last_write_time);cpps_socket_httpserver_cachefile* get_cachefile(std::string filepath);virtual void onReadCallback(cpps_socket* sock, ssize_t nread, const char* buf);virtual void onWriteCallback(cpps_socket* sock, ssize_t nread, const char* buf);virtual void onClsoeCallback(cpps_socket* sock);std::string getwwwroot();void setwwwroot(std::string wwwroot);void setuserdata(cpps::object userdata);cpps_value getuserdata();cpps_value get_request(cpps_integer socket_index);public:static void cb_listener(uv_stream_t* server, int status);static void generic_handler(struct http_request& req, void* handler);static void cpps_socket_httpserver_bindsession(cpps_socket_httpserver* httpserver, cpps_socket_httpserver_request* cpps_request_ptr, bool create_session=false);public:http_route http_route_list;http_route http_class_route_list;cpps::object http_default_class_route;cpps_socket_httpserver_option http_option;bool http_running;http_mime_type mime_types;http_session_list session_list;http_cachefile_list cachefile_list;http_request_list request_list;std::string _wwwroot;private:object createuuidfunc;bool SESSION_ENABLED;std::string SESSION_ENGINE;std::string SESSION_FILE_PATH;std::string SESSION_COOKIE_NAME;std::string SESSION_COOKIE_PATH;std::string SESSION_COOKIE_DOMAIN;bool SESSION_COOKIE_SECURE;bool SESSION_COOKIE_HTTPONLY;cpps_integer SESSION_COOKIE_AGE;bool SESSION_EXPIRE_AT_BROWSER_CLOSE;bool SESSION_SAVE_EVERY_REQUEST;};}#endif // cpps_socket_httpserver_h__
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型