From 02fe3541ea57ceb8191b9b6d55a1e0cbaf7fa911 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Sat, 9 Nov 2024 07:39:33 +0000 Subject: [PATCH] Burl: add --junk-session-cookies option --- example/client/burl/cookie.cpp | 13 +++++++++++++ example/client/burl/cookie.hpp | 3 +++ example/client/burl/main.cpp | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/example/client/burl/cookie.cpp b/example/client/burl/cookie.cpp index dcbc1e1..e2bf778 100644 --- a/example/client/burl/cookie.cpp +++ b/example/client/burl/cookie.cpp @@ -313,6 +313,19 @@ cookie_jar::make_field(const urls::url_view& url) return rs; } +void +cookie_jar::clear_session_cookies() +{ + cookies_.erase( + std::remove_if( + cookies_.begin(), + cookies_.end(), + [](const pair_t& p) { + return !p.c.expires.has_value(); + }), + cookies_.end()); +} + std::ostream& operator<<(std::ostream& os, const cookie_jar& cj) { diff --git a/example/client/burl/cookie.hpp b/example/client/burl/cookie.hpp index 5361a44..d0b1908 100644 --- a/example/client/burl/cookie.hpp +++ b/example/client/burl/cookie.hpp @@ -77,6 +77,9 @@ class cookie_jar std::string make_field(const urls::url_view& url); + void + clear_session_cookies(); + friend std::ostream& operator<<(std::ostream& os, const cookie_jar& cj); diff --git a/example/client/burl/main.cpp b/example/client/burl/main.cpp index 2325d92..ecd0593 100644 --- a/example/client/burl/main.cpp +++ b/example/client/burl/main.cpp @@ -1243,6 +1243,7 @@ main(int argc, char* argv[]) "Pass custom header(s) to server") ("help,h", "produce help message") ("http1.0", "Use HTTP 1.0") + ("junk-session-cookies,j", "Ignore session cookies read from file") ("location,L", "Follow redirects") ("output,o", po::value()->value_name(""), @@ -1412,6 +1413,9 @@ main(int argc, char* argv[]) } } + if(vm.count("junk-session-cookies") && cookie_jar.has_value()) + cookie_jar->clear_session_cookies(); + asio::co_spawn( ioc, request(