修复cookie过期判断不准的bug
This commit is contained in:
parent
327acdf562
commit
0603e95557
|
|
@ -255,7 +255,7 @@ void HttpClient::onResponseCompleted_l() {
|
||||||
onResponseCompleted();
|
onResponseCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpClient::checkCookie(const HttpClient::HttpHeader &headers) {
|
void HttpClient::checkCookie(HttpClient::HttpHeader &headers) {
|
||||||
//Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/
|
//Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/
|
||||||
auto it_set_cookie = headers.find("Set-Cookie");
|
auto it_set_cookie = headers.find("Set-Cookie");
|
||||||
if(it_set_cookie == headers.end()){
|
if(it_set_cookie == headers.end()){
|
||||||
|
|
@ -274,12 +274,17 @@ void HttpClient::checkCookie(const HttpClient::HttpHeader &headers) {
|
||||||
|
|
||||||
if(index++ == 0){
|
if(index++ == 0){
|
||||||
cookie->setKeyVal(key,val);
|
cookie->setKeyVal(key,val);
|
||||||
} else{
|
continue;
|
||||||
if(key == "path"){
|
|
||||||
cookie->setPath(val);
|
|
||||||
}else if(key == "expires"){
|
|
||||||
cookie->setExpires(val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(key == "path") {
|
||||||
|
cookie->setPath(val);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == "expires"){
|
||||||
|
cookie->setExpires(val,headers["Date"]);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ protected:
|
||||||
virtual void onManager() override;
|
virtual void onManager() override;
|
||||||
private:
|
private:
|
||||||
void onResponseCompleted_l();
|
void onResponseCompleted_l();
|
||||||
void checkCookie(const HttpHeader &headers );
|
void checkCookie(HttpHeader &headers );
|
||||||
protected:
|
protected:
|
||||||
bool _isHttps;
|
bool _isHttps;
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "HttpCookie.h"
|
#include "HttpCookie.h"
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
|
#include "Util/logger.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include "strptime_win.h"
|
#include "strptime_win.h"
|
||||||
|
|
@ -40,10 +41,17 @@ void HttpCookie::setPath(const string &path){
|
||||||
void HttpCookie::setHost(const string &host){
|
void HttpCookie::setHost(const string &host){
|
||||||
_host = host;
|
_host = host;
|
||||||
}
|
}
|
||||||
void HttpCookie::setExpires(const string &expires){
|
static uint32_t timeStrToInt(const string &date){
|
||||||
struct tm tt;
|
struct tm tt;
|
||||||
strptime(expires.data(),"%a, %b %d %Y %H:%M:%S %Z",&tt);
|
strptime(date.data(),"%a, %b %d %Y %H:%M:%S %Z",&tt);
|
||||||
_expire = mktime(&tt);
|
return mktime(&tt);
|
||||||
|
}
|
||||||
|
void HttpCookie::setExpires(const string &expires,const string &server_date){
|
||||||
|
_expire = timeStrToInt(expires);
|
||||||
|
if(!server_date.empty()){
|
||||||
|
_expire = time(NULL) + (_expire - timeStrToInt(server_date));
|
||||||
|
// DebugL << (timeStrToInt(expires) - timeStrToInt(server_date)) / 60;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void HttpCookie::setKeyVal(const string &key,const string &val){
|
void HttpCookie::setKeyVal(const string &key,const string &val){
|
||||||
_key = key;
|
_key = key;
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
void setPath(const string &path);
|
void setPath(const string &path);
|
||||||
void setHost(const string &host);
|
void setHost(const string &host);
|
||||||
void setExpires(const string &expires);
|
void setExpires(const string &expires,const string &server_date);
|
||||||
void setKeyVal(const string &key,const string &val);
|
void setKeyVal(const string &key,const string &val);
|
||||||
operator bool ();
|
operator bool ();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue