@@ -2,7 +2,7 @@ use crate::error::Error::GenericError;
22use crate :: error:: Result ;
33use crate :: render:: render_http_request;
44use crate :: response_err;
5- use log:: debug;
5+ use log:: { debug, warn } ;
66use reqwest_cookie_store:: { CookieStore , CookieStoreMutex } ;
77use std:: sync:: Arc ;
88use std:: time:: { Duration , Instant } ;
@@ -19,8 +19,8 @@ use yaak_http::sender::ReqwestSender;
1919use yaak_http:: transaction:: HttpTransaction ;
2020use yaak_http:: types:: { SendableHttpRequest , SendableHttpRequestOptions , append_query_params} ;
2121use yaak_models:: models:: {
22- CookieJar , Environment , HttpRequest , HttpResponse , HttpResponseEvent , HttpResponseHeader ,
23- HttpResponseState , ProxySetting , ProxySettingAuth ,
22+ Cookie , CookieJar , Environment , HttpRequest , HttpResponse , HttpResponseEvent ,
23+ HttpResponseHeader , HttpResponseState , ProxySetting , ProxySettingAuth ,
2424} ;
2525use yaak_models:: query_manager:: QueryManagerExt ;
2626use yaak_models:: util:: UpdateSource ;
@@ -207,6 +207,29 @@ async fn send_http_request_inner<R: Runtime>(
207207 )
208208 . await ;
209209
210+ // Persist cookies back to the database after the request completes
211+ if let Some ( ( cookie_store, mut cj) ) = maybe_cookie_manager {
212+ match cookie_store. lock ( ) {
213+ Ok ( store) => {
214+ let cookies: Vec < Cookie > = store
215+ . iter_any ( )
216+ . filter_map ( |c| {
217+ // Convert cookie_store::Cookie -> yaak_models::Cookie via serde
218+ let json_cookie = serde_json:: to_value ( c) . ok ( ) ?;
219+ serde_json:: from_value ( json_cookie) . ok ( )
220+ } )
221+ . collect ( ) ;
222+ cj. cookies = cookies;
223+ if let Err ( e) = window. db ( ) . upsert_cookie_jar ( & cj, & update_source) {
224+ warn ! ( "Failed to persist cookies to database: {}" , e) ;
225+ }
226+ }
227+ Err ( e) => {
228+ warn ! ( "Failed to lock cookie store: {}" , e) ;
229+ }
230+ }
231+ }
232+
210233 match final_resp {
211234 Ok ( r) => Ok ( r) ,
212235 Err ( e) => match app_handle. db ( ) . get_http_response ( & resp_id) {
0 commit comments