@@ -204,6 +204,13 @@ pub const Connection = struct {
204204 try self .secretHeaders (& header_list );
205205 try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_HTTPHEADER , header_list .headers ));
206206
207+ // Add cookies.
208+ // Clear cookies from Curl's engine.
209+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_COOKIELIST , "ALL" ));
210+ if (header_list .cookies ) | cookies | {
211+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_COOKIE , cookies ));
212+ }
213+
207214 try errorCheck (c .curl_easy_perform (easy ));
208215 var http_code : c_long = undefined ;
209216 try errorCheck (c .curl_easy_getinfo (easy , c .CURLINFO_RESPONSE_CODE , & http_code ));
@@ -216,11 +223,12 @@ pub const Connection = struct {
216223
217224pub const Headers = struct {
218225 headers : * c.curl_slist ,
226+ cookies : ? [* c ]const u8 ,
219227
220228 pub fn init () ! Headers {
221229 const header_list = c .curl_slist_append (null , "User-Agent: Lightpanda/1.0" );
222230 if (header_list == null ) return error .OutOfMemory ;
223- return .{ .headers = header_list };
231+ return .{ .headers = header_list , . cookies = null };
224232 }
225233
226234 pub fn deinit (self : * const Headers ) void {
@@ -245,6 +253,10 @@ pub const Headers = struct {
245253 list .putAssumeCapacity (header .name , header .value );
246254 current = node .* .next ;
247255 }
256+ // special case for cookies
257+ if (self .cookies ) | v | {
258+ list .putAssumeCapacity ("Cookie" , std .mem .span (@as ([* :0 ]const u8 , @ptrCast (v ))));
259+ }
248260 return list ;
249261 }
250262
@@ -264,6 +276,10 @@ pub const Headers = struct {
264276 num += 1 ;
265277 current = node .* .next ;
266278 }
279+ // special case for cookies
280+ if (self .cookies != null ) {
281+ num += 1 ;
282+ }
267283 return num ;
268284 }
269285};
0 commit comments