代码润色
This commit is contained in:
parent
88dc59ec68
commit
98f7c37cd5
|
|
@ -8,13 +8,12 @@
|
|||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "Parser.h"
|
||||
#include "Common/macros.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Util/base64.h"
|
||||
#include "macros.h"
|
||||
#include "strCoding.h"
|
||||
#include <cinttypes>
|
||||
#include "Parser.h"
|
||||
#include "strCoding.h"
|
||||
#include "Util/base64.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Common/macros.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
|
@ -327,16 +326,16 @@ void splitUrl(const std::string &url, std::string &host, uint16_t &port) {
|
|||
checkHost(host);
|
||||
}
|
||||
|
||||
void parseProxyUrl(const std::string &proxy_url, std::string &proxy_host, uint16_t &proxy_port, std::string &proxy_auth){
|
||||
//判断是否包含http://, 如果是则去掉
|
||||
void parseProxyUrl(const std::string &proxy_url, std::string &proxy_host, uint16_t &proxy_port, std::string &proxy_auth) {
|
||||
// 判断是否包含http://, 如果是则去掉
|
||||
std::string host;
|
||||
auto pos = proxy_url.find("://");
|
||||
if (pos != string::npos) {
|
||||
host = proxy_url.substr(pos + 3);
|
||||
}else{
|
||||
} else {
|
||||
host = proxy_url;
|
||||
}
|
||||
//判断是否包含用户名和密码
|
||||
// 判断是否包含用户名和密码
|
||||
pos = host.rfind('@');
|
||||
if (pos != string::npos) {
|
||||
proxy_auth = encodeBase64(host.substr(0, pos));
|
||||
|
|
@ -344,6 +343,7 @@ void parseProxyUrl(const std::string &proxy_url, std::string &proxy_host, uint16
|
|||
}
|
||||
splitUrl(host, proxy_host, proxy_port);
|
||||
}
|
||||
|
||||
#if 0
|
||||
//测试代码
|
||||
static onceToken token([](){
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ void HttpClient::onConnect_l(const SockException &ex) {
|
|||
}
|
||||
_StrPrinter printer;
|
||||
//不使用代理或者代理服务器已经连接成功
|
||||
if(_proxy_connected || !isUsedProxy()) {
|
||||
if (_proxy_connected || !isUsedProxy()) {
|
||||
printer << _method + " " << _path + " HTTP/1.1\r\n";
|
||||
for (auto &pr : _header) {
|
||||
printer << pr.first + ": ";
|
||||
|
|
@ -171,10 +171,10 @@ void HttpClient::onConnect_l(const SockException &ex) {
|
|||
}
|
||||
_header.clear();
|
||||
_path.clear();
|
||||
}else{
|
||||
printer << "CONNECT "<< _last_host <<" HTTP/1.1\r\n";
|
||||
} else {
|
||||
printer << "CONNECT " << _last_host << " HTTP/1.1\r\n";
|
||||
printer << "Proxy-Connection: keep-alive\r\n";
|
||||
if(!_proxy_auth.empty()) {
|
||||
if (!_proxy_auth.empty()) {
|
||||
printer << "Proxy-Authorization: Basic " << _proxy_auth << "\r\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -411,9 +411,11 @@ void HttpClient::setBodyTimeout(size_t timeout_ms) {
|
|||
void HttpClient::setCompleteTimeout(size_t timeout_ms) {
|
||||
_wait_complete_ms = timeout_ms;
|
||||
}
|
||||
|
||||
bool HttpClient::isUsedProxy() const {
|
||||
return _used_proxy;
|
||||
}
|
||||
|
||||
bool HttpClient::isProxyConnected() const {
|
||||
return _proxy_connected;
|
||||
}
|
||||
|
|
@ -423,7 +425,7 @@ void HttpClient::setProxyUrl(const string &proxyUrl) {
|
|||
if (!_proxy_url.empty()) {
|
||||
parseProxyUrl(_proxy_url, _proxy_host, _proxy_port, _proxy_auth);
|
||||
_used_proxy = true;
|
||||
}else{
|
||||
} else {
|
||||
_used_proxy = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -434,5 +436,4 @@ bool HttpClient::checkProxyConnected(const char *data, size_t len) {
|
|||
return _proxy_connected;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
|
|
|||
|
|
@ -183,20 +183,17 @@ protected:
|
|||
void onFlush() override;
|
||||
void onManager() override;
|
||||
|
||||
bool checkProxyConnected(const char *data, size_t len);
|
||||
|
||||
bool isUsedProxy() const;
|
||||
|
||||
bool isProxyConnected() const;
|
||||
|
||||
void clearResponse();
|
||||
|
||||
bool checkProxyConnected(const char *data, size_t len);
|
||||
bool isUsedProxy() const;
|
||||
bool isProxyConnected() const;
|
||||
|
||||
private:
|
||||
void onResponseCompleted_l(const toolkit::SockException &ex);
|
||||
void onConnect_l(const toolkit::SockException &ex);
|
||||
void checkCookie(HttpHeader &headers);
|
||||
|
||||
|
||||
private:
|
||||
//for http response
|
||||
bool _complete = false;
|
||||
|
|
@ -225,12 +222,13 @@ private:
|
|||
toolkit::Ticker _wait_header;
|
||||
toolkit::Ticker _wait_body;
|
||||
toolkit::Ticker _wait_complete;
|
||||
|
||||
bool _used_proxy = false;
|
||||
bool _proxy_connected = false;
|
||||
uint16_t _proxy_port;
|
||||
std::string _proxy_url;
|
||||
std::string _proxy_host;
|
||||
std::string _proxy_auth;
|
||||
uint16_t _proxy_port;
|
||||
bool _proxy_connected = false;
|
||||
bool _used_proxy = false;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ namespace mediakit {
|
|||
|
||||
void HttpClientImp::onConnect(const SockException &ex) {
|
||||
if (isUsedProxy() && !isProxyConnected()) {
|
||||
//连接代理服务器
|
||||
// 连接代理服务器
|
||||
setDoNotUseSSL();
|
||||
HttpClient::onConnect(ex);
|
||||
} else {
|
||||
if (!isHttps()) {
|
||||
//https 302跳转 http时,需要关闭ssl
|
||||
// https 302跳转 http时,需要关闭ssl
|
||||
setDoNotUseSSL();
|
||||
HttpClient::onConnect(ex);
|
||||
} else {
|
||||
|
|
@ -29,9 +29,10 @@ void HttpClientImp::onConnect(const SockException &ex) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t HttpClientImp::onRecvHeader(const char *data, size_t len) {
|
||||
if (isUsedProxy() && !isProxyConnected()) {
|
||||
if(checkProxyConnected(data, len)) {
|
||||
if (checkProxyConnected(data, len)) {
|
||||
clearResponse();
|
||||
onConnect(SockException(Err_success, "proxy connected"));
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ const char *TSSegment::onSearchPacketTail(const char *data, size_t len) {
|
|||
if (((uint8_t *) data)[_size] == TS_SYNC_BYTE) {
|
||||
return data + _size;
|
||||
}
|
||||
//搜索ts包头
|
||||
auto pos = memchr(data, TS_SYNC_BYTE, len);
|
||||
auto pos = memchr(data + _size, TS_SYNC_BYTE, len - _size);
|
||||
if (pos) {
|
||||
return (char *) pos;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue