From 818d26aa66207f82c8fec5dfeb8e110cecf5a81d Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 1 Jul 2019 20:55:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0onRedirectUrl=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpClient.cpp | 10 ++++++---- src/Http/HttpClient.h | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) 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;