mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 12:05:58 +08:00
整理http相关代码
This commit is contained in:
@@ -23,8 +23,8 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HttpStringBody::HttpStringBody(const string &str){
|
||||
_str = str;
|
||||
HttpStringBody::HttpStringBody(string str){
|
||||
_str = std::move(str);
|
||||
}
|
||||
|
||||
ssize_t HttpStringBody::remainSize() {
|
||||
@@ -43,6 +43,7 @@ Buffer::Ptr HttpStringBody::readData(size_t size) {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
HttpFileBody::HttpFileBody(const string &filePath){
|
||||
std::shared_ptr<FILE> fp(fopen(filePath.data(), "rb"), [](FILE *fp) {
|
||||
if(fp){
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
class HttpStringBody : public HttpBody{
|
||||
public:
|
||||
typedef std::shared_ptr<HttpStringBody> Ptr;
|
||||
HttpStringBody(const string &str);
|
||||
HttpStringBody(string str);
|
||||
~HttpStringBody() override = default;
|
||||
|
||||
ssize_t remainSize() override;
|
||||
|
||||
@@ -14,13 +14,6 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
|
||||
HttpClient::HttpClient() {
|
||||
}
|
||||
|
||||
HttpClient::~HttpClient() {
|
||||
}
|
||||
|
||||
void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
|
||||
_aliveTicker.resetTime();
|
||||
_url = strUrl;
|
||||
@@ -60,7 +53,8 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
|
||||
_header.emplace("Connection", "keep-alive");
|
||||
_header.emplace("Accept", "*/*");
|
||||
_header.emplace("Accept-Language", "zh-CN,zh;q=0.8");
|
||||
_header.emplace("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36");
|
||||
_header.emplace("User-Agent",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36");
|
||||
|
||||
if (_body && _body->remainSize()) {
|
||||
_header.emplace("Content-Length", to_string(_body->remainSize()));
|
||||
@@ -72,19 +66,17 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
|
||||
_isHttps = isHttps;
|
||||
_fTimeOutSec = fTimeOutSec;
|
||||
|
||||
auto cookies = HttpCookieStorage::Instance().get(_lastHost,_path);
|
||||
auto cookies = HttpCookieStorage::Instance().get(_lastHost, _path);
|
||||
_StrPrinter printer;
|
||||
for(auto &cookie : cookies){
|
||||
for (auto &cookie : cookies) {
|
||||
printer << cookie->getKey() << "=" << cookie->getVal() << ";";
|
||||
}
|
||||
if(!printer.empty()){
|
||||
if (!printer.empty()) {
|
||||
printer.pop_back();
|
||||
_header.emplace("Cookie", printer);
|
||||
}
|
||||
|
||||
|
||||
if (!alive() || bChanged) {
|
||||
//InfoL << "reconnet:" << _lastHost;
|
||||
startConnect(host, port, fTimeOutSec);
|
||||
} else {
|
||||
SockException ex;
|
||||
@@ -92,6 +84,51 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClient::clear() {
|
||||
_header.clear();
|
||||
_body.reset();
|
||||
_method.clear();
|
||||
_path.clear();
|
||||
_parser.Clear();
|
||||
_recvedBodySize = 0;
|
||||
_totalBodySize = 0;
|
||||
_aliveTicker.resetTime();
|
||||
_chunkedSplitter.reset();
|
||||
HttpRequestSplitter::reset();
|
||||
}
|
||||
|
||||
void HttpClient::setMethod(string method) {
|
||||
_method = std::move(method);
|
||||
}
|
||||
|
||||
void HttpClient::setHeader(HttpHeader header) {
|
||||
_header = std::move(header);
|
||||
}
|
||||
|
||||
HttpClient &HttpClient::addHeader(string key, string val, bool force) {
|
||||
if (!force) {
|
||||
_header.emplace(std::move(key), std::move(val));
|
||||
} else {
|
||||
_header[std::move(key)] = std::move(val);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void HttpClient::setBody(string body) {
|
||||
_body.reset(new HttpStringBody(std::move(body)));
|
||||
}
|
||||
|
||||
void HttpClient::setBody(HttpBody::Ptr body) {
|
||||
_body = std::move(body);
|
||||
}
|
||||
|
||||
const Parser &HttpClient::response() const {
|
||||
return _parser;
|
||||
}
|
||||
|
||||
const string &HttpClient::getUrl() const {
|
||||
return _url;
|
||||
}
|
||||
|
||||
void HttpClient::onConnect(const SockException &ex) {
|
||||
_aliveTicker.resetTime();
|
||||
@@ -131,16 +168,16 @@ void HttpClient::onErr(const SockException &ex) {
|
||||
|
||||
ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
||||
_parser.Parse(data);
|
||||
if(_parser.Url() == "302" || _parser.Url() == "301"){
|
||||
if (_parser.Url() == "302" || _parser.Url() == "301") {
|
||||
auto newUrl = _parser["Location"];
|
||||
if(newUrl.empty()){
|
||||
shutdown(SockException(Err_shutdown,"未找到Location字段(跳转url)"));
|
||||
if (newUrl.empty()) {
|
||||
shutdown(SockException(Err_shutdown, "未找到Location字段(跳转url)"));
|
||||
return 0;
|
||||
}
|
||||
if(onRedirectUrl(newUrl,_parser.Url() == "302")){
|
||||
if (onRedirectUrl(newUrl, _parser.Url() == "302")) {
|
||||
HttpClient::clear();
|
||||
setMethod("GET");
|
||||
HttpClient::sendRequest(newUrl,_fTimeOutSec);
|
||||
HttpClient::sendRequest(newUrl, _fTimeOutSec);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -148,26 +185,26 @@ ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
||||
checkCookie(_parser.getHeader());
|
||||
_totalBodySize = onResponseHeader(_parser.Url(), _parser.getHeader());
|
||||
|
||||
if(!_parser["Content-Length"].empty()){
|
||||
if (!_parser["Content-Length"].empty()) {
|
||||
//有Content-Length字段时忽略onResponseHeader的返回值
|
||||
_totalBodySize = atoll(_parser["Content-Length"].data());
|
||||
}
|
||||
|
||||
if(_parser["Transfer-Encoding"] == "chunked"){
|
||||
if (_parser["Transfer-Encoding"] == "chunked") {
|
||||
//如果Transfer-Encoding字段等于chunked,则认为后续的content是不限制长度的
|
||||
_totalBodySize = -1;
|
||||
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data,size_t len){
|
||||
if(len > 0){
|
||||
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data, size_t len) {
|
||||
if (len > 0) {
|
||||
auto recvedBodySize = _recvedBodySize + len;
|
||||
onResponseBody(data, len, recvedBodySize, SIZE_MAX);
|
||||
_recvedBodySize = recvedBodySize;
|
||||
}else{
|
||||
} else {
|
||||
onResponseCompleted_l();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(_totalBodySize == 0){
|
||||
if (_totalBodySize == 0) {
|
||||
//后续没content,本次http请求结束
|
||||
onResponseCompleted_l();
|
||||
return 0;
|
||||
@@ -182,12 +219,12 @@ ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
||||
}
|
||||
|
||||
void HttpClient::onRecvContent(const char *data, size_t len) {
|
||||
if(_chunkedSplitter){
|
||||
_chunkedSplitter->input(data,len);
|
||||
if (_chunkedSplitter) {
|
||||
_chunkedSplitter->input(data, len);
|
||||
return;
|
||||
}
|
||||
auto recvedBodySize = _recvedBodySize + len;
|
||||
if(_totalBodySize < 0){
|
||||
if (_totalBodySize < 0) {
|
||||
//不限长度的content,最大支持SIZE_MAX个字节
|
||||
onResponseBody(data, len, recvedBodySize, SIZE_MAX);
|
||||
_recvedBodySize = recvedBodySize;
|
||||
@@ -195,7 +232,7 @@ void HttpClient::onRecvContent(const char *data, size_t len) {
|
||||
}
|
||||
|
||||
//固定长度的content
|
||||
if (recvedBodySize < (size_t)_totalBodySize ) {
|
||||
if (recvedBodySize < (size_t) _totalBodySize) {
|
||||
//content还未接收完毕
|
||||
onResponseBody(data, len, recvedBodySize, _totalBodySize);
|
||||
_recvedBodySize = recvedBodySize;
|
||||
@@ -204,9 +241,9 @@ void HttpClient::onRecvContent(const char *data, size_t len) {
|
||||
|
||||
//content接收完毕
|
||||
onResponseBody(data, _totalBodySize - _recvedBodySize, _totalBodySize, _totalBodySize);
|
||||
bool biggerThanExpected = recvedBodySize > (size_t)_totalBodySize;
|
||||
bool biggerThanExpected = recvedBodySize > (size_t) _totalBodySize;
|
||||
onResponseCompleted_l();
|
||||
if(biggerThanExpected) {
|
||||
if (biggerThanExpected) {
|
||||
//声明的content数据比真实的小,那么我们只截取前面部分的并断开链接
|
||||
shutdown(SockException(Err_shutdown, "http response content size bigger than expected"));
|
||||
}
|
||||
@@ -214,7 +251,7 @@ void HttpClient::onRecvContent(const char *data, size_t len) {
|
||||
|
||||
void HttpClient::onFlush() {
|
||||
_aliveTicker.resetTime();
|
||||
GET_CONFIG(uint32_t,sendBufSize,Http::kSendBufSize);
|
||||
GET_CONFIG(uint32_t, sendBufSize, Http::kSendBufSize);
|
||||
while (_body && _body->remainSize() && !isSocketBusy()) {
|
||||
auto buffer = _body->readData(sendBufSize);
|
||||
if (!buffer) {
|
||||
@@ -250,34 +287,34 @@ void HttpClient::onResponseCompleted_l() {
|
||||
|
||||
void HttpClient::checkCookie(HttpClient::HttpHeader &headers) {
|
||||
//Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/
|
||||
for(auto it_set_cookie = headers.find("Set-Cookie") ; it_set_cookie != headers.end() ; ++it_set_cookie ){
|
||||
auto key_val = Parser::parseArgs(it_set_cookie->second,";","=");
|
||||
for (auto it_set_cookie = headers.find("Set-Cookie"); it_set_cookie != headers.end(); ++it_set_cookie) {
|
||||
auto key_val = Parser::parseArgs(it_set_cookie->second, ";", "=");
|
||||
HttpCookie::Ptr cookie = std::make_shared<HttpCookie>();
|
||||
cookie->setHost(_lastHost);
|
||||
|
||||
int index = 0;
|
||||
auto arg_vec = split(it_set_cookie->second, ";");
|
||||
for (string &key_val : arg_vec) {
|
||||
auto key = FindField(key_val.data(),NULL,"=");
|
||||
auto val = FindField(key_val.data(),"=", NULL);
|
||||
auto key = FindField(key_val.data(), NULL, "=");
|
||||
auto val = FindField(key_val.data(), "=", NULL);
|
||||
|
||||
if(index++ == 0){
|
||||
cookie->setKeyVal(key,val);
|
||||
if (index++ == 0) {
|
||||
cookie->setKeyVal(key, val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key == "path") {
|
||||
if (key == "path") {
|
||||
cookie->setPath(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key == "expires"){
|
||||
cookie->setExpires(val,headers["Date"]);
|
||||
if (key == "expires") {
|
||||
cookie->setExpires(val, headers["Date"]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(!(*cookie)){
|
||||
if (!(*cookie)) {
|
||||
//无效的cookie
|
||||
continue;
|
||||
}
|
||||
@@ -285,6 +322,4 @@ void HttpClient::checkCookie(HttpClient::HttpHeader &headers) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
} /* namespace mediakit */
|
||||
@@ -24,84 +24,88 @@
|
||||
#include "HttpChunkedSplitter.h"
|
||||
#include "strCoding.h"
|
||||
#include "HttpBody.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpArgs : public map<string, variant, StrCaseCompare> {
|
||||
class HttpArgs : public map<string, variant, StrCaseCompare> {
|
||||
public:
|
||||
HttpArgs(){}
|
||||
virtual ~HttpArgs(){}
|
||||
HttpArgs() = default;
|
||||
~HttpArgs() = default;
|
||||
|
||||
string make() const {
|
||||
string ret;
|
||||
for(auto &pr : *this){
|
||||
for (auto &pr : *this) {
|
||||
ret.append(pr.first);
|
||||
ret.append("=");
|
||||
ret.append(strCoding::UrlEncode(pr.second));
|
||||
ret.append("&");
|
||||
}
|
||||
if(ret.size()){
|
||||
if (ret.size()) {
|
||||
ret.pop_back();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
class HttpClient : public TcpClient , public HttpRequestSplitter{
|
||||
class HttpClient : public TcpClient, public HttpRequestSplitter {
|
||||
public:
|
||||
typedef StrCaseMap HttpHeader;
|
||||
typedef std::shared_ptr<HttpClient> Ptr;
|
||||
HttpClient();
|
||||
virtual ~HttpClient();
|
||||
virtual void sendRequest(const string &url,float fTimeOutSec);
|
||||
using HttpHeader = StrCaseMap;
|
||||
using Ptr = std::shared_ptr<HttpClient>;
|
||||
|
||||
virtual void clear(){
|
||||
_header.clear();
|
||||
_body.reset();
|
||||
_method.clear();
|
||||
_path.clear();
|
||||
_parser.Clear();
|
||||
_recvedBodySize = 0;
|
||||
_totalBodySize = 0;
|
||||
_aliveTicker.resetTime();
|
||||
_chunkedSplitter.reset();
|
||||
HttpRequestSplitter::reset();
|
||||
}
|
||||
HttpClient() = default;
|
||||
~HttpClient() override = default;
|
||||
|
||||
void setMethod(const string &method){
|
||||
_method = method;
|
||||
}
|
||||
void setHeader(const HttpHeader &header){
|
||||
_header = header;
|
||||
}
|
||||
HttpClient & addHeader(const string &key,const string &val,bool force = false){
|
||||
if(!force){
|
||||
_header.emplace(key,val);
|
||||
}else{
|
||||
_header[key] = val;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
void setBody(const string &body){
|
||||
_body.reset(new HttpStringBody(body));
|
||||
}
|
||||
void setBody(const HttpBody::Ptr &body){
|
||||
_body = body;
|
||||
}
|
||||
const string &responseStatus() const{
|
||||
return _parser.Url();
|
||||
}
|
||||
const HttpHeader &responseHeader() const{
|
||||
return _parser.getHeader();
|
||||
}
|
||||
const Parser& response() const{
|
||||
return _parser;
|
||||
}
|
||||
/**
|
||||
* 发送http[s]请求
|
||||
* @param url 请求url
|
||||
* @param fTimeOutSec 超时时间
|
||||
*/
|
||||
virtual void sendRequest(const string &url, float fTimeOutSec);
|
||||
|
||||
/**
|
||||
* 重置对象
|
||||
*/
|
||||
virtual void clear();
|
||||
|
||||
/**
|
||||
* 设置http方法
|
||||
* @param method GET/POST等
|
||||
*/
|
||||
void setMethod(string method);
|
||||
|
||||
/**
|
||||
* 覆盖http头
|
||||
* @param header
|
||||
*/
|
||||
void setHeader(HttpHeader header);
|
||||
|
||||
HttpClient &addHeader(string key, string val, bool force = false);
|
||||
|
||||
/**
|
||||
* 设置http content
|
||||
* @param body http content
|
||||
*/
|
||||
void setBody(string body);
|
||||
|
||||
/**
|
||||
* 设置http content
|
||||
* @param body http content
|
||||
*/
|
||||
void setBody(HttpBody::Ptr body);
|
||||
|
||||
/**
|
||||
* 获取回复,在收到完整回复后有效
|
||||
*/
|
||||
const Parser &response() const;
|
||||
|
||||
/**
|
||||
* 获取请求url
|
||||
*/
|
||||
const string &getUrl() const;
|
||||
|
||||
const string &getUrl() const{
|
||||
return _url;
|
||||
}
|
||||
protected:
|
||||
/**
|
||||
* 收到http回复头
|
||||
@@ -110,7 +114,7 @@ protected:
|
||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
||||
*/
|
||||
virtual ssize_t onResponseHeader(const string &status,const HttpHeader &headers){
|
||||
virtual ssize_t onResponseHeader(const string &status, const HttpHeader &headers) {
|
||||
//无Content-Length字段时默认后面全是content
|
||||
return -1;
|
||||
}
|
||||
@@ -129,7 +133,7 @@ protected:
|
||||
/**
|
||||
* 接收http回复完毕,
|
||||
*/
|
||||
virtual void onResponseCompleted(){
|
||||
virtual void onResponseCompleted() {
|
||||
DebugL;
|
||||
}
|
||||
|
||||
@@ -137,7 +141,7 @@ protected:
|
||||
* http链接断开回调
|
||||
* @param ex 断开原因
|
||||
*/
|
||||
virtual void onDisconnect(const SockException &ex){}
|
||||
virtual void onDisconnect(const SockException &ex) {}
|
||||
|
||||
/**
|
||||
* 重定向事件
|
||||
@@ -145,22 +149,23 @@ protected:
|
||||
* @param temporary 是否为临时重定向
|
||||
* @return 是否继续
|
||||
*/
|
||||
virtual bool onRedirectUrl(const string &url,bool temporary){ return true;};
|
||||
virtual bool onRedirectUrl(const string &url, bool temporary) { return true; };
|
||||
|
||||
//HttpRequestSplitter override
|
||||
ssize_t onRecvHeader(const char *data,size_t len) override;
|
||||
void onRecvContent(const char *data,size_t len) override;
|
||||
//// HttpRequestSplitter override ////
|
||||
ssize_t onRecvHeader(const char *data, size_t len) override;
|
||||
void onRecvContent(const char *data, size_t len) override;
|
||||
|
||||
protected:
|
||||
virtual void onConnect(const SockException &ex) override;
|
||||
virtual void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
virtual void onErr(const SockException &ex) override;
|
||||
virtual void onFlush() override;
|
||||
virtual void onManager() override;
|
||||
//// TcpClient override ////
|
||||
void onConnect(const SockException &ex) override;
|
||||
void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
void onErr(const SockException &ex) override;
|
||||
void onFlush() override;
|
||||
void onManager() override;
|
||||
|
||||
private:
|
||||
void onResponseCompleted_l();
|
||||
void checkCookie(HttpHeader &headers );
|
||||
void checkCookie(HttpHeader &headers);
|
||||
|
||||
protected:
|
||||
bool _isHttps;
|
||||
|
||||
@@ -10,42 +10,36 @@
|
||||
|
||||
#include "HttpRequester.h"
|
||||
|
||||
namespace mediakit{
|
||||
namespace mediakit {
|
||||
|
||||
HttpRequester::HttpRequester(){
|
||||
|
||||
}
|
||||
HttpRequester::~HttpRequester(){
|
||||
|
||||
}
|
||||
|
||||
ssize_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) {
|
||||
ssize_t HttpRequester::onResponseHeader(const string &status, const HttpHeader &headers) {
|
||||
_strRecvBody.clear();
|
||||
return HttpClientImp::onResponseHeader(status, headers);
|
||||
}
|
||||
|
||||
void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) {
|
||||
_strRecvBody.append(buf,size);
|
||||
|
||||
void HttpRequester::onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) {
|
||||
_strRecvBody.append(buf, size);
|
||||
}
|
||||
|
||||
|
||||
void HttpRequester::onResponseCompleted() {
|
||||
if(_onResult){
|
||||
_onResult(SockException(),responseStatus(),responseHeader(),_strRecvBody);
|
||||
const_cast<Parser &> (response()).setContent(std::move(_strRecvBody));
|
||||
if (_onResult) {
|
||||
_onResult(SockException(), response());
|
||||
_onResult = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpRequester::onDisconnect(const SockException &ex){
|
||||
if(_onResult){
|
||||
const_cast<Parser &>(response()).setContent(_strRecvBody);
|
||||
_onResult(ex,responseStatus(),responseHeader(),_strRecvBody);
|
||||
|
||||
void HttpRequester::onDisconnect(const SockException &ex) {
|
||||
const_cast<Parser &> (response()).setContent(std::move(_strRecvBody));
|
||||
if (_onResult) {
|
||||
_onResult(ex, response());
|
||||
_onResult = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpRequester::startRequester(const string &url,const HttpRequesterResult &onResult , float timeOutSecond){
|
||||
|
||||
void HttpRequester::startRequester(const string &url, const HttpRequesterResult &onResult, float timeOutSecond) {
|
||||
_onResult = onResult;
|
||||
sendRequest(url,timeOutSecond);
|
||||
sendRequest(url, timeOutSecond);
|
||||
}
|
||||
|
||||
void HttpRequester::clear() {
|
||||
|
||||
@@ -13,23 +13,26 @@
|
||||
|
||||
#include "HttpClientImp.h"
|
||||
|
||||
namespace mediakit{
|
||||
namespace mediakit {
|
||||
|
||||
class HttpRequester : public HttpClientImp
|
||||
{
|
||||
class HttpRequester : public HttpClientImp {
|
||||
public:
|
||||
typedef std::shared_ptr<HttpRequester> Ptr;
|
||||
typedef std::function<void(const SockException &ex,const string &status,const HttpHeader &header,const string &strRecvBody)> HttpRequesterResult;
|
||||
HttpRequester();
|
||||
virtual ~HttpRequester();
|
||||
using Ptr = std::shared_ptr<HttpRequester>;
|
||||
using HttpRequesterResult = std::function<void(const SockException &ex, const Parser &response)>;
|
||||
|
||||
HttpRequester() = default;
|
||||
~HttpRequester() override = default;
|
||||
|
||||
void setOnResult(const HttpRequesterResult &onResult);
|
||||
void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10);
|
||||
void clear() override ;
|
||||
void startRequester(const string &url, const HttpRequesterResult &onResult, float timeOutSecond = 10);
|
||||
void clear() override;
|
||||
|
||||
private:
|
||||
ssize_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||
ssize_t onResponseHeader(const string &status, const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) override;
|
||||
void onResponseCompleted() override;
|
||||
void onDisconnect(const SockException &ex) override;
|
||||
|
||||
private:
|
||||
string _strRecvBody;
|
||||
HttpRequesterResult _onResult;
|
||||
|
||||
Reference in New Issue
Block a user