mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +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()){
|
||||
//没有Content-Length字段
|
||||
// if(_parser.Content().empty()){
|
||||
// //content长度为0,本次http请求结束
|
||||
// onResponseCompleted_l();
|
||||
// return 0;
|
||||
// }
|
||||
auto ret = onResponseCompleted_l();
|
||||
if(ret){
|
||||
return 0;
|
||||
}
|
||||
//如果http回复未声明Content-Length字段,但是却有content内容,那说明可能是个不限长度的content
|
||||
_totalBodySize = INT64_MAX;
|
||||
_recvedBodySize = 0;
|
||||
@ -228,26 +227,29 @@ void HttpClient::onManager() {
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClient::onResponseCompleted_l() {
|
||||
bool HttpClient::onResponseCompleted_l() {
|
||||
_totalBodySize = 0;
|
||||
_recvedBodySize = 0;
|
||||
HttpRequestSplitter::reset();
|
||||
onResponseCompleted();
|
||||
bool ret = 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/
|
||||
auto set_cookie = headers["Set-Cookie"];
|
||||
if(set_cookie.empty()){
|
||||
auto it_set_cookie = headers.find("Set-Cookie");
|
||||
if(it_set_cookie == headers.end()){
|
||||
return;
|
||||
}
|
||||
auto key_val = Parser::parseArgs(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(set_cookie, ";");
|
||||
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);
|
||||
|
@ -264,10 +264,12 @@ protected:
|
||||
};
|
||||
|
||||
/**
|
||||
* 接收http回复完毕
|
||||
* 接收http回复完毕,
|
||||
* @return 是否真的结束数据接收
|
||||
*/
|
||||
virtual void onResponseCompleted(){
|
||||
virtual bool onResponseCompleted(){
|
||||
DebugL;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,8 +295,8 @@ protected:
|
||||
virtual void onSend() override;
|
||||
virtual void onManager() override;
|
||||
private:
|
||||
void onResponseCompleted_l();
|
||||
void checkCookie(HttpHeader &headers );
|
||||
bool onResponseCompleted_l();
|
||||
void checkCookie(const HttpHeader &headers );
|
||||
protected:
|
||||
bool _isHttps;
|
||||
private:
|
||||
|
@ -83,7 +83,7 @@ void HttpDownloader::onResponseBody(const char* buf, size_t size, size_t recvedS
|
||||
}
|
||||
}
|
||||
|
||||
void HttpDownloader::onResponseCompleted() {
|
||||
bool HttpDownloader::onResponseCompleted() {
|
||||
closeFile();
|
||||
//InfoL << "md5Sum:" << getMd5Sum(_filePath);
|
||||
_bDownloadSuccess = true;
|
||||
@ -91,6 +91,7 @@ void HttpDownloader::onResponseCompleted() {
|
||||
_onResult(Err_success,"success",_filePath.data());
|
||||
_onResult = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HttpDownloader::onDisconnect(const SockException &ex) {
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
private:
|
||||
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 onResponseCompleted() override;
|
||||
bool onResponseCompleted() override;
|
||||
void onDisconnect(const SockException &ex) override;
|
||||
void closeFile();
|
||||
private:
|
||||
|
@ -42,11 +42,12 @@ void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize
|
||||
_strRecvBody.append(buf,size);
|
||||
}
|
||||
|
||||
void HttpRequester::onResponseCompleted() {
|
||||
bool HttpRequester::onResponseCompleted() {
|
||||
if(_onResult){
|
||||
_onResult(SockException(),responseStatus(),responseHeader(),_strRecvBody);
|
||||
_onResult = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HttpRequester::onDisconnect(const SockException &ex){
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
private:
|
||||
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 onResponseCompleted() override;
|
||||
bool onResponseCompleted() override;
|
||||
void onDisconnect(const SockException &ex) override;
|
||||
private:
|
||||
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) {
|
||||
_StrPrinter printer;
|
||||
printer << "HTTP/1.1 " << pcStatus << " \r\n";
|
||||
printer << "HTTP/1.1 " << pcStatus << "\r\n";
|
||||
for (auto &pr : header) {
|
||||
printer << pr.first << ": " << pr.second << "\r\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user