acl/app/master/daemon/manage/http_client.h

69 lines
1.3 KiB
C
Raw Normal View History

2017-06-14 17:42:05 +08:00
/**
* Copyright (C) 2015-2018
* All rights reserved.
*
* AUTHOR(S)
* Zheng Shuxin
* E-mail: zhengshuxin@qiyi.com
*
* VERSION
* Wed 14 Jun 2017 12:21:44 PM CST
*/
#pragma once
2017-06-16 17:00:49 +08:00
#include "json/serialize.h"
2017-06-14 17:42:05 +08:00
class service_reload;
2017-06-14 17:42:05 +08:00
class http_client
{
public:
http_client(acl::aio_socket_stream* client, int rw_timeout = 10);
void wait(void);
public:
template<typename T>
void reply(int status, const char* cmd, T& o, bool save = true)
{
acl::string buf;
serialize<T>(o, buf);
do_reply(status, cmd, buf, save);
buf.clear();
}
void on_finish(void);
2017-06-14 17:42:05 +08:00
private:
~http_client(void);
private:
ACL_ASTREAM* conn_;
int rw_timeout_;
HTTP_HDR_REQ* hdr_req_;
HTTP_REQ* req_;
http_off_t content_length_;
acl::json json_;
public:
2017-06-16 17:00:49 +08:00
bool handle_list(void);
bool handle_stat(void);
bool handle_kill(void);
2017-06-16 17:00:49 +08:00
bool handle_stop(void);
bool handle_start(void);
bool handle_restart(void);
2017-06-27 17:11:04 +08:00
bool handle_reload(void);
bool handle_master_config(void);
2017-06-14 17:42:05 +08:00
private:
void reset(void);
bool handle(void);
void do_reply(int status, const char* cmd,
const acl::string& buf, bool save);
2017-06-14 17:42:05 +08:00
static int on_head(int status, void* ctx);
static int on_body(int status, char* data, int dlen, void* ctx);
static int on_close(ACL_ASTREAM* conn, void* ctx);
2017-06-26 13:19:43 +08:00
static int on_timeo(ACL_ASTREAM* conn, void* ctx);
2017-06-14 17:42:05 +08:00
};