diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index a609aa18..3f98c60c 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -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()); diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 642cbc2c..1f8287e5 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -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;