diff --git a/ZLToolKit b/ZLToolKit index 8e90a8db..ea623e89 160000 --- a/ZLToolKit +++ b/ZLToolKit @@ -1 +1 @@ -Subproject commit 8e90a8dbefe9060fdb86b9dc8036345aa69faf41 +Subproject commit ea623e89153b7f5e4f693e3f2d4c5e60b79540ed diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index 51446c0a..9cb316d7 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -100,7 +100,6 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) { if (!alive() || bChanged) { //InfoL << "reconnet:" << _lastHost; - onBeforeConnect(host, port , fTimeOutSec); startConnect(host, port, fTimeOutSec); } else { SockException ex; @@ -132,12 +131,8 @@ void HttpClient::onConnect(const SockException &ex) { } void HttpClient::onRecv(const Buffer::Ptr &pBuf) { - onRecvBytes(pBuf->data(), pBuf->size()); -} - -void HttpClient::onRecvBytes(const char *data, int size) { _aliveTicker.resetTime(); - HttpRequestSplitter::input(data, size); + HttpRequestSplitter::input(pBuf->data(), pBuf->size()); } void HttpClient::onErr(const SockException &ex) { diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 4e01699d..d1b291e9 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -283,13 +283,6 @@ protected: DebugL; } - /** - * 收到http回复数据回调 - * @param data 数据指针 - * @param size 数据大小 - */ - virtual void onRecvBytes(const char *data,int size); - /** * http链接断开回调 * @param ex 断开原因 @@ -299,9 +292,6 @@ protected: //HttpRequestSplitter override int64_t onRecvHeader(const char *data,uint64_t len) override ; void onRecvContent(const char *data,uint64_t len) override; - - //在连接服务器前调用一次 - virtual void onBeforeConnect(string &strUrl, uint16_t &iPort,float &fTimeOutSec) {}; protected: virtual void onConnect(const SockException &ex) override; virtual void onRecv(const Buffer::Ptr &pBuf) override; diff --git a/src/Http/HttpClientImp.cpp b/src/Http/HttpClientImp.cpp index d71b05cf..8e88718e 100644 --- a/src/Http/HttpClientImp.cpp +++ b/src/Http/HttpClientImp.cpp @@ -28,37 +28,13 @@ namespace mediakit { -#if defined(ENABLE_OPENSSL) -void HttpClientImp::onBeforeConnect(string &strUrl, uint16_t &iPort,float &fTimeOutSec) { - if(_isHttps){ - _sslBox.reset(new SSL_Box(false)); - _sslBox->setOnDecData([this](const char *data, uint32_t len){ - public_onRecvBytes(data,len); - }); - _sslBox->setOnEncData([this](const char *data, uint32_t len){ - public_send(data,len); - }); - }else{ - _sslBox.reset(); +void HttpClientImp::onConnect(const SockException &ex) { + if(!_isHttps){ + HttpClient::onConnect(ex); + } else { + TcpClientWithSSL::onConnect(ex); } -} -void HttpClientImp::onRecvBytes(const char* data, int size) { - if(_sslBox){ - _sslBox->onRecv(data,size); - }else{ - HttpClient::onRecvBytes(data,size); - } } -int HttpClientImp::send(const Buffer::Ptr &buf) { - if(_sslBox){ - _sslBox->onSend(buf->data(),buf->size()); - return buf->size(); - } - return HttpClient::send(buf); -} - -#endif //defined(ENABLE_OPENSSL) - } /* namespace mediakit */ diff --git a/src/Http/HttpClientImp.h b/src/Http/HttpClientImp.h index 5fa6721b..b6727588 100644 --- a/src/Http/HttpClientImp.h +++ b/src/Http/HttpClientImp.h @@ -28,41 +28,21 @@ #define SRC_HTTP_HTTPCLIENTIMP_H_ #include "HttpClient.h" -#ifdef ENABLE_OPENSSL #include "Util/SSLBox.h" -#endif //ENABLE_OPENSSL using namespace toolkit; namespace mediakit { -#if defined(ENABLE_OPENSSL) -class HttpClientImp: public HttpClient { +class HttpClientImp: public TcpClientWithSSL { public: typedef std::shared_ptr Ptr; HttpClientImp() {} virtual ~HttpClientImp() {} - - inline void public_onRecvBytes(const char *data,int len){ - HttpClient::onRecvBytes(data,len); - } - inline void public_send(const char *data, uint32_t len){ - HttpClient::send(obtainBuffer(data,len)); - } -private: - void onRecvBytes(const char *data,int size) override; - int send(const Buffer::Ptr &buf) override; - void onBeforeConnect(string &strUrl, uint16_t &iPort,float &fTimeOutSec) override; -private: - std::shared_ptr _sslBox; +protected: + void onConnect(const SockException &ex) override ; }; -#else - -typedef HttpClient HttpClientImp; - -#endif // defined(ENABLE_OPENSSL) - } /* namespace mediakit */ #endif /* SRC_HTTP_HTTPCLIENTIMP_H_ */