Skip to content

Commit 304c26e

Browse files
committed
chore: use headers in an example to test
1 parent fe5b6e6 commit 304c26e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

examples/basic.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ export fn http_get() i32 {
123123
var req = http.HttpRequest.init("GET", "https://jsonplaceholder.typicode.com/todos/1");
124124
defer req.deinit(allocator);
125125

126-
// set headers on the request object
127-
req.setHeader(allocator, "some-name", "some-value") catch unreachable;
128-
req.setHeader(allocator, "another", "again") catch unreachable;
126+
// // set headers on the request object
127+
// req.setHeader(allocator, "some-name", "some-value") catch unreachable;
128+
// req.setHeader(allocator, "another", "again") catch unreachable;
129129

130130
// make the request and get the response back
131131
const res = plugin.request(req, null) catch unreachable;
@@ -135,11 +135,15 @@ export fn http_get() i32 {
135135
plugin.setError("request failed");
136136
return @as(i32, res.status);
137137
}
138+
var headers = res.headers(plugin.allocator) catch {
139+
plugin.setError("failed to get headers from response!");
140+
return -1;
141+
};
142+
defer headers.deinit();
138143

139-
const headers = res.headers(allocator) catch unreachable;
140144
const content_type = headers.get("content-type");
141145
if (content_type) |t| {
142-
plugin.log(.Debug, t);
146+
plugin.log(.Debug, t.value); // something like 'application/json; charset=utf-8'
143147
}
144148

145149
// get the bytes for the res body

0 commit comments

Comments
 (0)