2019-06-05 17:36:47 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include "../stream/aio_socket_stream.hpp"
|
|
|
|
|
|
|
|
|
|
struct HTTP_HDR;
|
|
|
|
|
struct HTTP_HDR_RES;
|
|
|
|
|
struct HTTP_RES;
|
|
|
|
|
struct HTTP_HDR_REQ;
|
|
|
|
|
struct HTTP_REQ;
|
|
|
|
|
|
|
|
|
|
struct ACL_ASTREAM;
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class aio_handle;
|
|
|
|
|
class aio_socket_stream;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
class socket_stream;
|
2019-06-10 16:08:21 +08:00
|
|
|
|
class zlib_stream;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
class websocket;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
class polarssl_conf;
|
|
|
|
|
class polarssl_io;
|
|
|
|
|
class http_header;
|
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-06-10 16:08:21 +08:00
|
|
|
|
* HTTP <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽ͨ<EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֱ<EFBFBD> HTTP ͨ<EFBFBD><EFBFBD>Э<EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> Websocket ͨ<EFBFBD>ţ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP Э<EFBFBD>鼰 Websocket ͨ<EFBFBD>ž<EFBFBD>֧<EFBFBD><EFBFBD> SSL <EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD>䣻
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP Э<EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ѹ GZIP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻص<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> on_http_res_body() <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ǽ<EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
class ACL_CPP_API http_aclient : public aio_open_callback
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param handle {aio_handle&} <EFBFBD>첽ͨ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param ssl_conf {polarssl_conf*} <EFBFBD><EFBFBD> NULL ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SSL ͨ<EFBFBD>ŷ<EFBFBD>ʽ
|
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
http_aclient(aio_handle& handle, polarssl_conf* ssl_conf = NULL);
|
2019-06-06 13:46:23 +08:00
|
|
|
|
virtual ~http_aclient(void);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void destroy(void) = 0;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>е<EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {http_header&}
|
|
|
|
|
*/
|
|
|
|
|
http_header& request_header(void);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-10 16:08:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ѹ
|
|
|
|
|
* @param on {bool}
|
|
|
|
|
* @return {http_aclient&}
|
|
|
|
|
*/
|
|
|
|
|
http_aclient& unzip_body(bool on);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GZIP ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ѹ
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool is_unzip_body(void) const
|
|
|
|
|
{
|
|
|
|
|
return unzip_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>ʼ<EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} Զ<EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD>
|
|
|
|
|
* domain:port <EFBFBD><EFBFBD> ip:port, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> aio_handle::set_dns() <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַΪ IP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @param conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<EFBFBD>䣨<EFBFBD>룩
|
|
|
|
|
* @param rw_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> IO <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD>䣨<EFBFBD>룩
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool open(const char* addr, int conn_timeout, int rw_timeout);
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
protected:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ڸ÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ﹹ<EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> send_request <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
virtual bool on_connect(void) = 0;
|
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_connect_timeout(void) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܺ<EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_connect_failed(void) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_read_timeout(void) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӹرպ<EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_disconnect(void) {};
|
|
|
|
|
|
|
|
|
|
/**
|
2019-06-06 23:43:04 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>Ӧͷʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
* @param header {const http_header&}
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-06-06 23:43:04 +08:00
|
|
|
|
virtual bool on_http_res_hdr(const http_header& header)
|
|
|
|
|
{
|
|
|
|
|
(void) header;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-06 13:46:23 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-06-06 23:43:04 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܻᱻ<EFBFBD><EFBFBD><EFBFBD>λص<EFBFBD>
|
|
|
|
|
* ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
* @param data {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dlen {size_t} <EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> data <EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-06-06 23:43:04 +08:00
|
|
|
|
virtual bool on_http_res_body(char* data, size_t dlen)
|
|
|
|
|
{
|
|
|
|
|
(void) data;
|
|
|
|
|
(void) dlen;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-06 13:46:23 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-06-06 23:43:04 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
* @param success {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-06-06 23:43:04 +08:00
|
|
|
|
virtual bool on_http_res_finish(bool success)
|
|
|
|
|
{
|
|
|
|
|
(void) success;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-10 13:00:25 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD> websocket <EFBFBD><EFBFBD><EFBFBD>ֳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>Ҫ<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_handshake(void)
|
|
|
|
|
{
|
|
|
|
|
// <20><>ʼ<EFBFBD>첽<EFBFBD><ECB2BD> websocket <20><><EFBFBD><EFBFBD>
|
|
|
|
|
this->ws_read_wait(0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD> websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܺ<EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param status {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ״̬<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_ws_handshake_failed(int status) { (void) status; }
|
|
|
|
|
|
2019-06-09 22:46:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> text <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>֡ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_frame_text(void) { return true; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> binary <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>֡ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_frame_binary(void) { return true; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_ws_frame_closed(void) {}
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD> websocket ͨ<EFBFBD>ŷ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param data {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
|
|
|
|
|
* @param dlen {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-06-09 22:46:07 +08:00
|
|
|
|
virtual bool on_ws_frame_data(char* data, size_t dlen)
|
2019-06-06 23:43:04 +08:00
|
|
|
|
{
|
|
|
|
|
(void) data;
|
|
|
|
|
(void) dlen;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-09 22:46:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_frame_finish(void) { return true; }
|
|
|
|
|
|
2019-06-10 13:00:25 +08:00
|
|
|
|
public:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD>ͺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param body {const void*} HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><EFBFBD>Ϊ NULL ʱ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP GET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} body <EFBFBD><EFBFBD> NULL ʱ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
void send_request(const void* body, size_t len);
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WEBSOCKET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void ws_handshake(void);
|
|
|
|
|
|
2019-06-10 13:00:25 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>ʼ<EFBFBD>첽<EFBFBD><EFBFBD> websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void ws_read_wait(int timeout = 0);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_TEXT <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {char*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_text(char* data, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_BINARY <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {void*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_binary(void* data, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_PING <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {void*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_ping(void* data, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_PONG <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {void*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_pong(void* data, size_t len);
|
|
|
|
|
|
2019-06-05 17:36:47 +08:00
|
|
|
|
protected:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
// @override dummy
|
|
|
|
|
bool open_callback(void) { return true; }
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
bool timeout_callback(void);
|
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
void close_callback(void);
|
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
bool read_wakeup(void);
|
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
bool read_callback(char* data, int len);
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-06-10 13:00:25 +08:00
|
|
|
|
unsigned status_;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
aio_handle& handle_;
|
|
|
|
|
polarssl_conf* ssl_conf_;
|
2019-06-06 13:46:23 +08:00
|
|
|
|
int rw_timeout_;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
aio_socket_stream* conn_;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
socket_stream* stream_;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
http_header* header_;
|
|
|
|
|
HTTP_HDR_RES* hdr_res_;
|
|
|
|
|
HTTP_RES* http_res_;
|
2019-06-06 13:46:23 +08:00
|
|
|
|
bool keep_alive_;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
websocket* ws_in_;
|
|
|
|
|
websocket* ws_out_;
|
2019-06-09 22:46:07 +08:00
|
|
|
|
string* buff_;
|
2019-06-10 16:08:21 +08:00
|
|
|
|
bool unzip_; // <20>Ƿ<EFBFBD><C7B7>Զ<EFBFBD><D4B6><EFBFBD>ѹ<EFBFBD><D1B9>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
zlib_stream* zstream_; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
|
|
|
|
|
int gzip_header_left_; // gzip <20><><EFBFBD><EFBFBD>ʱѹ<CAB1><D1B9>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 23:43:04 +08:00
|
|
|
|
|
2019-06-10 16:34:23 +08:00
|
|
|
|
bool handle_connect(ACL_ASTREAM* stream);
|
2019-06-10 13:00:25 +08:00
|
|
|
|
bool handle_ssl_handshake(void);
|
|
|
|
|
|
2019-06-10 16:34:23 +08:00
|
|
|
|
bool handle_res_hdr(int status);
|
|
|
|
|
|
2019-06-10 16:08:21 +08:00
|
|
|
|
bool handle_res_body(char* data, int dlen);
|
|
|
|
|
bool res_plain(char* data, int dlen);
|
|
|
|
|
bool res_unzip(zlib_stream& zstream, char* data, int dlen);
|
|
|
|
|
|
|
|
|
|
bool handle_res_body_finish(char* data, int dlen);
|
|
|
|
|
bool res_plain_finish(char* data, int dlen);
|
|
|
|
|
bool res_unzip_finish(zlib_stream& zstream, char* data, int dlen);
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
bool handle_websocket(void);
|
2019-06-09 22:46:07 +08:00
|
|
|
|
bool handle_ws_data(void);
|
|
|
|
|
bool handle_ws_ping(void);
|
|
|
|
|
bool handle_ws_pong(void);
|
|
|
|
|
bool handle_ws_other(void);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static int connect_callback(ACL_ASTREAM* stream, void* ctx);
|
|
|
|
|
static int http_res_hdr_cllback(int status, void* ctx);
|
|
|
|
|
static int http_res_callback(int status, char* data, int dlen, void* ctx);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|