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