acl/lib_acl_cpp/include/acl_cpp/http/http_response.hpp

140 lines
5.4 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include "../stdlib/noncopyable.hpp"
2017-06-02 14:47:24 +08:00
#include "http_header.hpp"
2014-11-19 00:25:21 +08:00
namespace acl {
class http_client;
class http_pipe;
class socket_stream;
class xml;
class json;
class ACL_CPP_API http_response : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
/**
* socket_stream
*
* @param client {socket_stream*}
* 使使
* get_body->response
2014-11-19 00:25:21 +08:00
*/
http_response(socket_stream* client);
virtual ~http_response(void);
/////////////////////////////////////////////////////////////////////
// 与读取请求数据相关的方法
2014-11-19 00:25:21 +08:00
/**
* HTTP HTTP
* get_body/read_body HTTP
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool read_header();
/**
* xml HTTP
* response
*
* @param out {xml&} HTTP xml
* @param to_charset {const char*}
* xml
* @return {bool}
* read_header
*
2014-11-19 00:25:21 +08:00
*/
bool get_body(xml& out, const char* to_charset = NULL);
/**
* json HTTP
* response
*
* @param out {json&} HTTP json
* @param to_charset {const char*}
* json
* @return {bool}
* read_header
*
2014-11-19 00:25:21 +08:00
*/
bool get_body(json& out, const char* to_charset = NULL);
/*
* HTTP
* @param out {string&}
* @param to_charset {const char*}
* out
*
* read_header
2014-11-19 00:25:21 +08:00
*/
bool get_body(string& out, const char* to_charset = NULL);
/*
* HTTP
*
* @param buf {char*}
* @param size {size_t} buf
* @return {int} == 0 < 0
* > 0
* <= 0
* HTTP
* read_header
*
2014-11-19 00:25:21 +08:00
*/
int read_body(char* buf, size_t size);
/////////////////////////////////////////////////////////////////////
// 与数据响应相关的方法函数
2014-11-19 00:25:21 +08:00
/**
* HTTP HTTP
* http_header::reset()
* http_header
2014-11-19 00:25:21 +08:00
* @return {http_header&}
*/
http_header& response_header(void);
/**
* HTTP
* <b></b>
* 1 read_header && get_body HTTP
* 2 response_header http_header
* set_status, set_keep_alive
* <b></b>
* 1 HTTP
* 2 http_header::set_chunked chunked
* chunked
* 3使 chunked
* 0
* @param data {const void*}
* @param len {size_t} data
* @return {bool} false
2014-11-19 00:25:21 +08:00
*/
bool response(const void* data, size_t len);
//////////////////////////////////////////////////////////////////////////
/**
* http_client HTTP
* http_client
* @return {http_client*}
2014-11-19 00:25:21 +08:00
*/
http_client* get_client(void) const;
/**
* HTTP
2014-11-19 00:25:21 +08:00
*/
void close(void);
2014-11-19 00:25:21 +08:00
private:
bool debug_;
bool header_ok_;
http_client* client_;
http_header header_;
bool head_sent_;
http_pipe* get_pipe(const char* to_charset);
};
} // namespace acl