parent
7aa0c2ae33
commit
67f7c3dc8f
|
|
@ -148,6 +148,17 @@ void HttpClient::onErr(const SockException &ex) {
|
||||||
|
|
||||||
int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||||
_parser.Parse(data);
|
_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());
|
checkCookie(_parser.getValues());
|
||||||
_totalBodySize = onResponseHeader(_parser.Url(), _parser.getValues());
|
_totalBodySize = onResponseHeader(_parser.Url(), _parser.getValues());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,24 +59,23 @@ void HttpRequestSplitter::input(const char *data,uint64_t len) {
|
||||||
//_content_len == 0,这是请求头
|
//_content_len == 0,这是请求头
|
||||||
const char *header_ptr = ptr;
|
const char *header_ptr = ptr;
|
||||||
int64_t header_size = index - ptr;
|
int64_t header_size = index - ptr;
|
||||||
|
|
||||||
ptr = index;
|
ptr = index;
|
||||||
_remain_data_size = len - (ptr - data);
|
_remain_data_size = len - (ptr - data);
|
||||||
|
|
||||||
_content_len = onRecvHeader(header_ptr, header_size);
|
_content_len = onRecvHeader(header_ptr, header_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* 恢复末尾字节
|
|
||||||
*/
|
|
||||||
tail_ref = tail_tmp;
|
|
||||||
|
|
||||||
if(_remain_data_size <= 0){
|
if(_remain_data_size <= 0){
|
||||||
//没有剩余数据,清空缓存
|
//没有剩余数据,清空缓存
|
||||||
_remain_data.clear();
|
_remain_data.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 恢复末尾字节
|
||||||
|
* 移动到这来,目的是防止HttpRequestSplitter::reset()导致内存失效
|
||||||
|
*/
|
||||||
|
tail_ref = tail_tmp;
|
||||||
|
|
||||||
if(_content_len == 0){
|
if(_content_len == 0){
|
||||||
//尚未找到http头,缓存定位到剩余数据部分
|
//尚未找到http头,缓存定位到剩余数据部分
|
||||||
string str(ptr,_remain_data_size);
|
string str(ptr,_remain_data_size);
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
|
||||||
sendDescribe();
|
sendDescribe();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(parser.Url() == "302"){
|
if(parser.Url() == "302" || parser.Url() == "301"){
|
||||||
auto newUrl = parser["Location"];
|
auto newUrl = parser["Location"];
|
||||||
if(newUrl.empty()){
|
if(newUrl.empty()){
|
||||||
throw std::runtime_error("未找到Location字段(跳转url)");
|
throw std::runtime_error("未找到Location字段(跳转url)");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue