Skip to content

Commit 2174d2f

Browse files
committed
1 parent b9996bd commit 2174d2f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

inc/lift/request.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,14 @@ class request
472472
m_debug_info_handler = std::move(callback_functor);
473473
}
474474

475+
/**
476+
* @param cookie_file The filename to read cookies from;
477+
* empty string ("") enables the cookie engine without reading any initial cookies;
478+
* "-" (a single minus sign) reads from stdin instead;
479+
* std::nullopt disables the cookie engine and clears the list of files to read cookies from.
480+
*/
481+
auto cookie_file(std::optional<std::filesystem::path> cookie_file) -> void { m_cookie_file = cookie_file; }
482+
475483
private:
476484
/// The on complete handler callback or promise to fulfill, this is only used for async requests.
477485
impl::copy_but_actually_move<async_handlers_type> m_on_complete_handler{std::monostate{}};
@@ -525,6 +533,8 @@ class request
525533
std::optional<std::chrono::milliseconds> m_happy_eyeballs_timeout{};
526534
/// The debug callback functor for `debug_info_type` information. If nullptr will not be set.
527535
debug_info_callback_type m_debug_info_handler{nullptr};
536+
// The filename to read cookies from.
537+
std::optional<std::filesystem::path> m_cookie_file;
528538

529539
/**
530540
* Used by the client to set an async callback for on completion notification to the user.

src/executor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ auto executor::prepare() -> void
398398
curl_easy_setopt(m_curl_handle, CURLOPT_DEBUGFUNCTION, curl_debug_info_callback);
399399
curl_easy_setopt(m_curl_handle, CURLOPT_DEBUGDATA, this);
400400
}
401+
// https://curl.se/libcurl/c/CURLOPT_COOKIEFILE.html
402+
curl_easy_setopt(
403+
m_curl_handle, CURLOPT_COOKIEFILE, m_request->m_cookie_file ? m_request->m_cookie_file->string().c_str() : nullptr);
401404
}
402405

403406
auto executor::copy_curl_to_response() -> void

0 commit comments

Comments
 (0)