1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 07:04:08 +00:00

0.15.1-fix cookies example

This commit is contained in:
renerocksai 2025-08-28 22:27:51 +02:00
parent 7672a5e099
commit a45baf78ea
No known key found for this signature in database
2 changed files with 6 additions and 12 deletions

View file

@ -17,22 +17,16 @@ pub const std_options: std.Options = .{
// We send ourselves a request with a cookie
fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
const uri = try std.Uri.parse(url);
var http_client: std.http.Client = .{ .allocator = a };
defer http_client.deinit();
var server_header_buffer: [2048]u8 = undefined;
var req = try http_client.open(.GET, uri, .{
.server_header_buffer = &server_header_buffer,
_ = try http_client.fetch(.{
.location = .{ .url = url },
.method = .GET,
.extra_headers = &.{
.{ .name = "cookie", .value = "ZIG_ZAP=awesome" },
},
});
defer req.deinit();
try req.send();
try req.wait();
}
fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
@ -71,7 +65,7 @@ pub fn main() !void {
std.debug.print("\n", .{});
// // iterate over all cookies
const cookies = r.cookiesToOwnedList(alloc) catch unreachable;
var cookies = r.cookiesToOwnedList(alloc) catch unreachable;
defer cookies.deinit();
for (cookies.items) |kv| {
std.log.info("cookie `{s}` is {any}", .{ kv.key, kv.value });

View file

@ -795,7 +795,7 @@ pub fn cookiesToOwnedStrList(self: *const Request, a: Allocator) anyerror!HttpPa
if (howmany != self.getCookiesCount()) {
return error.HttpIterParams;
}
return .{ .items = try params.toOwnedSlice(), .allocator = a };
return .{ .items = try params.toOwnedSlice(a), .allocator = a };
}
/// Same as parametersToOwnedList() but for cookies
@ -806,7 +806,7 @@ pub fn cookiesToOwnedList(self: *const Request, a: Allocator) !HttpParamKVList {
if (howmany != self.getCookiesCount()) {
return error.HttpIterParams;
}
return .{ .items = try params.toOwnedSlice(), .allocator = a };
return .{ .items = try params.toOwnedSlice(a), .allocator = a };
}
/// Returns the query / body parameters as key/value pairs, as strings.