-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.http.Client: api does not assert methods are called in the right order #15096
Comments
The API expects you to call the |
|
I ran in to a similar issue today, and also would love to see a |
After a bit of poking around, I think that the intended usage was probably something like the following, which appears to do the right thing. I can submit a const std = @import("std");
const http = std.http;
pub fn main() !void {
var alloc = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer alloc.deinit();
var allocator = alloc.allocator();
const uri = try std.Uri.parse("http://localhost:8080/my/url");
var client = http.Client{ .allocator = allocator };
defer client.deinit();
var req = try client.request(uri, .{ .method = .POST }, .{});
defer req.deinit();
// after this call, the response headers are populated and can be used
try req.waitForCompleteHead();
try req.finish();
var buf = try allocator.alloc(u8, req.response.headers.content_length.?);
defer allocator.free(buf);
_ = try req.read(buf);
std.debug.print("got response: {s}\n", .{buf});
std.debug.print("status: {d}\n", .{req.response.headers.status});
} |
ah i was unaware of |
Sounds good to me. |
I'll admit |
Can we get an issue title that correctly reflects whether or not this is a bug? |
Zig Version
0.11.0-dev.2297+28d6dd75a
Steps to Reproduce and Observed Behavior
Expected Behavior
The text was updated successfully, but these errors were encountered: