mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
修复http相关的bug
This commit is contained in:
parent
6d8bdefa31
commit
022838a7d3
@ -153,11 +153,10 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
|||||||
|
|
||||||
if(_parser["Content-Length"].empty()){
|
if(_parser["Content-Length"].empty()){
|
||||||
//没有Content-Length字段
|
//没有Content-Length字段
|
||||||
// if(_parser.Content().empty()){
|
auto ret = onResponseCompleted_l();
|
||||||
// //content长度为0,本次http请求结束
|
if(ret){
|
||||||
// onResponseCompleted_l();
|
return 0;
|
||||||
// return 0;
|
}
|
||||||
// }
|
|
||||||
//如果http回复未声明Content-Length字段,但是却有content内容,那说明可能是个不限长度的content
|
//如果http回复未声明Content-Length字段,但是却有content内容,那说明可能是个不限长度的content
|
||||||
_totalBodySize = INT64_MAX;
|
_totalBodySize = INT64_MAX;
|
||||||
_recvedBodySize = 0;
|
_recvedBodySize = 0;
|
||||||
@ -228,26 +227,29 @@ void HttpClient::onManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpClient::onResponseCompleted_l() {
|
bool HttpClient::onResponseCompleted_l() {
|
||||||
_totalBodySize = 0;
|
_totalBodySize = 0;
|
||||||
_recvedBodySize = 0;
|
_recvedBodySize = 0;
|
||||||
HttpRequestSplitter::reset();
|
bool ret = onResponseCompleted();
|
||||||
onResponseCompleted();
|
if(ret){
|
||||||
|
HttpRequestSplitter::reset();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpClient::checkCookie(HttpClient::HttpHeader &headers) {
|
void HttpClient::checkCookie(const HttpClient::HttpHeader &headers) {
|
||||||
//Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/
|
//Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/
|
||||||
auto set_cookie = headers["Set-Cookie"];
|
auto it_set_cookie = headers.find("Set-Cookie");
|
||||||
if(set_cookie.empty()){
|
if(it_set_cookie == headers.end()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto key_val = Parser::parseArgs(set_cookie,";","=");
|
auto key_val = Parser::parseArgs(it_set_cookie->second,";","=");
|
||||||
|
|
||||||
HttpCookie::Ptr cookie = std::make_shared<HttpCookie>();
|
HttpCookie::Ptr cookie = std::make_shared<HttpCookie>();
|
||||||
cookie->setHost(_lastHost);
|
cookie->setHost(_lastHost);
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
auto arg_vec = split(set_cookie, ";");
|
auto arg_vec = split(it_set_cookie->second, ";");
|
||||||
for (string &key_val : arg_vec) {
|
for (string &key_val : arg_vec) {
|
||||||
auto key = FindField(key_val.data(),NULL,"=");
|
auto key = FindField(key_val.data(),NULL,"=");
|
||||||
auto val = FindField(key_val.data(),"=", NULL);
|
auto val = FindField(key_val.data(),"=", NULL);
|
||||||
|
@ -264,10 +264,12 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收http回复完毕
|
* 接收http回复完毕,
|
||||||
|
* @return 是否真的结束数据接收
|
||||||
*/
|
*/
|
||||||
virtual void onResponseCompleted(){
|
virtual bool onResponseCompleted(){
|
||||||
DebugL;
|
DebugL;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -293,8 +295,8 @@ protected:
|
|||||||
virtual void onSend() override;
|
virtual void onSend() override;
|
||||||
virtual void onManager() override;
|
virtual void onManager() override;
|
||||||
private:
|
private:
|
||||||
void onResponseCompleted_l();
|
bool onResponseCompleted_l();
|
||||||
void checkCookie(HttpHeader &headers );
|
void checkCookie(const HttpHeader &headers );
|
||||||
protected:
|
protected:
|
||||||
bool _isHttps;
|
bool _isHttps;
|
||||||
private:
|
private:
|
||||||
|
@ -83,7 +83,7 @@ void HttpDownloader::onResponseBody(const char* buf, size_t size, size_t recvedS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpDownloader::onResponseCompleted() {
|
bool HttpDownloader::onResponseCompleted() {
|
||||||
closeFile();
|
closeFile();
|
||||||
//InfoL << "md5Sum:" << getMd5Sum(_filePath);
|
//InfoL << "md5Sum:" << getMd5Sum(_filePath);
|
||||||
_bDownloadSuccess = true;
|
_bDownloadSuccess = true;
|
||||||
@ -91,6 +91,7 @@ void HttpDownloader::onResponseCompleted() {
|
|||||||
_onResult(Err_success,"success",_filePath.data());
|
_onResult(Err_success,"success",_filePath.data());
|
||||||
_onResult = nullptr;
|
_onResult = nullptr;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpDownloader::onDisconnect(const SockException &ex) {
|
void HttpDownloader::onDisconnect(const SockException &ex) {
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void onResponseHeader(const string &status,const HttpHeader &headers) override;
|
void onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||||
void onResponseCompleted() override;
|
bool onResponseCompleted() override;
|
||||||
void onDisconnect(const SockException &ex) override;
|
void onDisconnect(const SockException &ex) override;
|
||||||
void closeFile();
|
void closeFile();
|
||||||
private:
|
private:
|
||||||
|
@ -42,11 +42,12 @@ void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize
|
|||||||
_strRecvBody.append(buf,size);
|
_strRecvBody.append(buf,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpRequester::onResponseCompleted() {
|
bool HttpRequester::onResponseCompleted() {
|
||||||
if(_onResult){
|
if(_onResult){
|
||||||
_onResult(SockException(),responseStatus(),responseHeader(),_strRecvBody);
|
_onResult(SockException(),responseStatus(),responseHeader(),_strRecvBody);
|
||||||
_onResult = nullptr;
|
_onResult = nullptr;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpRequester::onDisconnect(const SockException &ex){
|
void HttpRequester::onDisconnect(const SockException &ex){
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void onResponseHeader(const string &status,const HttpHeader &headers) override;
|
void onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||||
void onResponseCompleted() override;
|
bool onResponseCompleted() override;
|
||||||
void onDisconnect(const SockException &ex) override;
|
void onDisconnect(const SockException &ex) override;
|
||||||
private:
|
private:
|
||||||
string _strRecvBody;
|
string _strRecvBody;
|
||||||
|
@ -515,7 +515,7 @@ inline bool HttpSession::makeMeun(const string &strFullPath,const string &vhost,
|
|||||||
}
|
}
|
||||||
inline void HttpSession::sendResponse(const char* pcStatus, const KeyValue& header, const string& strContent) {
|
inline void HttpSession::sendResponse(const char* pcStatus, const KeyValue& header, const string& strContent) {
|
||||||
_StrPrinter printer;
|
_StrPrinter printer;
|
||||||
printer << "HTTP/1.1 " << pcStatus << " \r\n";
|
printer << "HTTP/1.1 " << pcStatus << "\r\n";
|
||||||
for (auto &pr : header) {
|
for (auto &pr : header) {
|
||||||
printer << pr.first << ": " << pr.second << "\r\n";
|
printer << pr.first << ": " << pr.second << "\r\n";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user