添加onRedirectUrl事件

This commit is contained in:
xiongziliang 2019-07-01 20:55:31 +08:00
parent ed78f152ee
commit 818d26aa66
2 changed files with 14 additions and 4 deletions

View File

@ -155,10 +155,12 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
shutdown(SockException(Err_shutdown,"未找到Location字段(跳转url)"));
return 0;
}
HttpClient::clear();
setMethod("GET");
HttpClient::sendRequest(newUrl,_fTimeOutSec);
return 0;
if(onRedirectUrl(newUrl,_parser.Url() == "302")){
HttpClient::clear();
setMethod("GET");
HttpClient::sendRequest(newUrl,_fTimeOutSec);
return 0;
}
}
checkCookie(_parser.getValues());

View File

@ -296,6 +296,14 @@ protected:
*/
virtual void onDisconnect(const SockException &ex){}
/**
*
* @param url url
* @param temporary
* @return
*/
virtual bool onRedirectUrl(const string &url,bool temporary){ return true;};
//HttpRequestSplitter override
int64_t onRecvHeader(const char *data,uint64_t len) override ;
void onRecvContent(const char *data,uint64_t len) override;