mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
0.15.1-fix cookies example
This commit is contained in:
parent
7672a5e099
commit
a45baf78ea
2 changed files with 6 additions and 12 deletions
|
@ -17,22 +17,16 @@ pub const std_options: std.Options = .{
|
||||||
|
|
||||||
// We send ourselves a request with a cookie
|
// We send ourselves a request with a cookie
|
||||||
fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
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 };
|
var http_client: std.http.Client = .{ .allocator = a };
|
||||||
defer http_client.deinit();
|
defer http_client.deinit();
|
||||||
|
|
||||||
var server_header_buffer: [2048]u8 = undefined;
|
_ = try http_client.fetch(.{
|
||||||
var req = try http_client.open(.GET, uri, .{
|
.location = .{ .url = url },
|
||||||
.server_header_buffer = &server_header_buffer,
|
.method = .GET,
|
||||||
.extra_headers = &.{
|
.extra_headers = &.{
|
||||||
.{ .name = "cookie", .value = "ZIG_ZAP=awesome" },
|
.{ .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 {
|
fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
||||||
|
@ -71,7 +65,7 @@ pub fn main() !void {
|
||||||
std.debug.print("\n", .{});
|
std.debug.print("\n", .{});
|
||||||
|
|
||||||
// // iterate over all cookies
|
// // iterate over all cookies
|
||||||
const cookies = r.cookiesToOwnedList(alloc) catch unreachable;
|
var cookies = r.cookiesToOwnedList(alloc) catch unreachable;
|
||||||
defer cookies.deinit();
|
defer cookies.deinit();
|
||||||
for (cookies.items) |kv| {
|
for (cookies.items) |kv| {
|
||||||
std.log.info("cookie `{s}` is {any}", .{ kv.key, kv.value });
|
std.log.info("cookie `{s}` is {any}", .{ kv.key, kv.value });
|
||||||
|
|
|
@ -795,7 +795,7 @@ pub fn cookiesToOwnedStrList(self: *const Request, a: Allocator) anyerror!HttpPa
|
||||||
if (howmany != self.getCookiesCount()) {
|
if (howmany != self.getCookiesCount()) {
|
||||||
return error.HttpIterParams;
|
return error.HttpIterParams;
|
||||||
}
|
}
|
||||||
return .{ .items = try params.toOwnedSlice(), .allocator = a };
|
return .{ .items = try params.toOwnedSlice(a), .allocator = a };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as parametersToOwnedList() but for cookies
|
/// Same as parametersToOwnedList() but for cookies
|
||||||
|
@ -806,7 +806,7 @@ pub fn cookiesToOwnedList(self: *const Request, a: Allocator) !HttpParamKVList {
|
||||||
if (howmany != self.getCookiesCount()) {
|
if (howmany != self.getCookiesCount()) {
|
||||||
return error.HttpIterParams;
|
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.
|
/// Returns the query / body parameters as key/value pairs, as strings.
|
||||||
|
|
Loading…
Add table
Reference in a new issue