http客户端支持302跳转

修复HttpRequestSplitter可能内存越界的bug
This commit is contained in:
xiongziliang 2019-07-01 09:53:58 +08:00
parent 7aa0c2ae33
commit 67f7c3dc8f
3 changed files with 18 additions and 8 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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)");