mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2025-02-23 13:39:13 +08:00
http客户端支持302跳转
修复HttpRequestSplitter可能内存越界的bug
This commit is contained in:
parent
7aa0c2ae33
commit
67f7c3dc8f
@ -148,6 +148,17 @@ void HttpClient::onErr(const SockException &ex) {
|
||||
|
||||
int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||
_parser.Parse(data);
|
||||
if(_parser.Url() == "302" || _parser.Url() == "301"){
|
||||
auto newUrl = _parser["Location"];
|
||||
if(newUrl.empty()){
|
||||
shutdown(SockException(Err_shutdown,"未找到Location字段(跳转url)"));
|
||||
return 0;
|
||||
}
|
||||
HttpClient::sendRequest(newUrl,_fTimeOutSec);
|
||||
HttpRequestSplitter::reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
checkCookie(_parser.getValues());
|
||||
_totalBodySize = onResponseHeader(_parser.Url(), _parser.getValues());
|
||||
|
||||
|
@ -59,24 +59,23 @@ void HttpRequestSplitter::input(const char *data,uint64_t len) {
|
||||
//_content_len == 0,这是请求头
|
||||
const char *header_ptr = ptr;
|
||||
int64_t header_size = index - ptr;
|
||||
|
||||
ptr = index;
|
||||
_remain_data_size = len - (ptr - data);
|
||||
|
||||
_content_len = onRecvHeader(header_ptr, header_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* 恢复末尾字节
|
||||
*/
|
||||
tail_ref = tail_tmp;
|
||||
|
||||
if(_remain_data_size <= 0){
|
||||
//没有剩余数据,清空缓存
|
||||
_remain_data.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 恢复末尾字节
|
||||
* 移动到这来,目的是防止HttpRequestSplitter::reset()导致内存失效
|
||||
*/
|
||||
tail_ref = tail_tmp;
|
||||
|
||||
if(_content_len == 0){
|
||||
//尚未找到http头,缓存定位到剩余数据部分
|
||||
string str(ptr,_remain_data_size);
|
||||
|
@ -198,7 +198,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
|
||||
sendDescribe();
|
||||
return;
|
||||
}
|
||||
if(parser.Url() == "302"){
|
||||
if(parser.Url() == "302" || parser.Url() == "301"){
|
||||
auto newUrl = parser["Location"];
|
||||
if(newUrl.empty()){
|
||||
throw std::runtime_error("未找到Location字段(跳转url)");
|
||||
|
Loading…
Reference in New Issue
Block a user