From 2e31ae9fd07a4697a63e41a69bd3b88ee60119c3 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Wed, 9 Mar 2022 15:51:39 -0800 Subject: [PATCH] NativeHTTPRequest: manage cookies for the current session if withCredentials is true --- .../backend/native/NativeHTTPRequest.hx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lime/_internal/backend/native/NativeHTTPRequest.hx b/src/lime/_internal/backend/native/NativeHTTPRequest.hx index be40c2094..733fbc14e 100644 --- a/src/lime/_internal/backend/native/NativeHTTPRequest.hx +++ b/src/lime/_internal/backend/native/NativeHTTPRequest.hx @@ -40,6 +40,7 @@ class NativeHTTPRequest #if (cpp || neko || hl) private static var multiAddHandle:Deque; #end + private static var cookieList:Array; private var bytes:Bytes; private var bytesLoaded:Int; @@ -235,11 +236,17 @@ class NativeHTTPRequest curl.setOption(HEADERFUNCTION, curl_onHeader); } - // TODO: Add support for cookies: https://curl.haxx.se/docs/http-cookies.html - if (parent.withCredentials) { - // TODO: Send cookies with request + // an empty string means store cookies in memory + // cookies are stored only for the current session + curl.setOption(COOKIEFILE, ""); + if (cookieList != null) { + for(cookie in cookieList) { + // pass in each stored cookie individually + curl.setOption(COOKIELIST, cookie); + } + } } curl.setOption(SSL_VERIFYPEER, false); @@ -518,6 +525,9 @@ class NativeHTTPRequest var curl = message.curl; var status = curl.getInfo(RESPONSE_CODE); + // returns an array of cookie values + cookieList = curl.getInfo(COOKIELIST); + multi.removeHandle(curl); curl.cleanup();