@@ -203,6 +203,13 @@ pub const Connection = struct {
203203 try self .secretHeaders (& header_list );
204204 try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_HTTPHEADER , header_list .headers ));
205205
206+ // Add cookies.
207+ // Clear cookies from Curl's engine.
208+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_COOKIELIST , "ALL" ));
209+ if (header_list .cookies ) | cookies | {
210+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_COOKIE , cookies ));
211+ }
212+
206213 try errorCheck (c .curl_easy_perform (easy ));
207214 var http_code : c_long = undefined ;
208215 try errorCheck (c .curl_easy_getinfo (easy , c .CURLINFO_RESPONSE_CODE , & http_code ));
@@ -215,11 +222,12 @@ pub const Connection = struct {
215222
216223pub const Headers = struct {
217224 headers : * c.curl_slist ,
225+ cookies : ? [* c ]const u8 ,
218226
219227 pub fn init () ! Headers {
220228 const header_list = c .curl_slist_append (null , "User-Agent: Lightpanda/1.0" );
221229 if (header_list == null ) return error .OutOfMemory ;
222- return .{ .headers = header_list };
230+ return .{ .headers = header_list , . cookies = null };
223231 }
224232
225233 pub fn deinit (self : * const Headers ) void {
@@ -244,6 +252,10 @@ pub const Headers = struct {
244252 list .putAssumeCapacity (header .name , header .value );
245253 current = node .* .next ;
246254 }
255+ // special case for cookies
256+ if (self .cookies ) | v | {
257+ list .putAssumeCapacity ("Cookie" , std .mem .span (@as ([* :0 ]const u8 , @ptrCast (v ))));
258+ }
247259 return list ;
248260 }
249261
@@ -263,6 +275,10 @@ pub const Headers = struct {
263275 num += 1 ;
264276 current = node .* .next ;
265277 }
278+ // special case for cookies
279+ if (self .cookies != null ) {
280+ num += 1 ;
281+ }
266282 return num ;
267283 }
268284};
0 commit comments