authorgravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-10-07 20:27:39-05:00
committergravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-10-21 20:52:59-05:00
log363d0ee5e13f4ac3a93d246121edfd00ef9fd97b
treecf0f1561e448ac231b15c21feabace4a41489582
parent544ed34d99f59a1b487341eaaa9610be44629924
signature Commit is signed but in an unrecognized format.

std.http: rename start->send and request->open to be more inline with operation


5 files changed, 72 insertions(+), 72 deletions(-)

lib/std/http/Client.zig+16-16
...@@ -598,15 +598,15 @@ pub const Request = struct {...@@ -598,15 +598,15 @@ pub const Request = struct {
598 };598 };
599 }599 }
600600
601 pub const StartError = Connection.WriteError || error{ InvalidContentLength, UnsupportedTransferEncoding };601 pub const SendError = Connection.WriteError || error{ InvalidContentLength, UnsupportedTransferEncoding };
602602
603 pub const StartOptions = struct {603 pub const SendOptions = struct {
604 /// Specifies that the uri should be used as is604 /// Specifies that the uri should be used as is. You guarantee that the uri is already escaped.
605 raw_uri: bool = false,605 raw_uri: bool = false,
606 };606 };
607607
608 /// Send the HTTP request headers to the server.608 /// Send the HTTP request headers to the server.
609 pub fn start(req: *Request, options: StartOptions) StartError!void {609 pub fn send(req: *Request, options: SendOptions) SendError!void {
610 if (!req.method.requestHasBody() and req.transfer_encoding != .none) return error.UnsupportedTransferEncoding;610 if (!req.method.requestHasBody() and req.transfer_encoding != .none) return error.UnsupportedTransferEncoding;
611611
612 const w = req.connection.?.writer();612 const w = req.connection.?.writer();
...@@ -733,14 +733,14 @@ pub const Request = struct {...@@ -733,14 +733,14 @@ pub const Request = struct {
733 return index;733 return index;
734 }734 }
735735
736 pub const WaitError = RequestError || StartError || TransferReadError || proto.HeadersParser.CheckCompleteHeadError || Response.ParseError || Uri.ParseError || error{ TooManyHttpRedirects, RedirectRequiresResend, HttpRedirectMissingLocation, CompressionInitializationFailed, CompressionNotSupported };736 pub const WaitError = RequestError || SendError || TransferReadError || proto.HeadersParser.CheckCompleteHeadError || Response.ParseError || Uri.ParseError || error{ TooManyHttpRedirects, RedirectRequiresResend, HttpRedirectMissingLocation, CompressionInitializationFailed, CompressionNotSupported };
737737
738 /// Waits for a response from the server and parses any headers that are sent.738 /// Waits for a response from the server and parses any headers that are sent.
739 /// This function will block until the final response is received.739 /// This function will block until the final response is received.
740 ///740 ///
741 /// If `handle_redirects` is true and the request has no payload, then this function will automatically follow741 /// If `handle_redirects` is true and the request has no payload, then this function will automatically follow
742 /// redirects. If a request payload is present, then this function will error with error.RedirectRequiresResend.742 /// redirects. If a request payload is present, then this function will error with error.RedirectRequiresResend.
743 /// 743 ///
744 /// Must be called after `start` and, if any data was written to the request body, then also after `finish`.744 /// Must be called after `start` and, if any data was written to the request body, then also after `finish`.
745 pub fn wait(req: *Request) WaitError!void {745 pub fn wait(req: *Request) WaitError!void {
746 while (true) { // handle redirects746 while (true) { // handle redirects
...@@ -845,7 +845,7 @@ pub const Request = struct {...@@ -845,7 +845,7 @@ pub const Request = struct {
845845
846 try req.redirect(resolved_url);846 try req.redirect(resolved_url);
847847
848 try req.start(.{});848 try req.send(.{});
849 } else {849 } else {
850 req.response.skip = false;850 req.response.skip = false;
851 if (!req.response.parser.done) {851 if (!req.response.parser.done) {
...@@ -1223,7 +1223,7 @@ pub fn connectTunnel(...@@ -1223,7 +1223,7 @@ pub fn connectTunnel(
1223 // we can use a small buffer here because a CONNECT response should be very small1223 // we can use a small buffer here because a CONNECT response should be very small
1224 var buffer: [8096]u8 = undefined;1224 var buffer: [8096]u8 = undefined;
12251225
1226 var req = client.request(.CONNECT, uri, proxy.headers, .{1226 var req = client.open(.CONNECT, uri, proxy.headers, .{
1227 .handle_redirects = false,1227 .handle_redirects = false,
1228 .connection = conn,1228 .connection = conn,
1229 .header_strategy = .{ .static = buffer[0..] },1229 .header_strategy = .{ .static = buffer[0..] },
...@@ -1233,7 +1233,7 @@ pub fn connectTunnel(...@@ -1233,7 +1233,7 @@ pub fn connectTunnel(
1233 };1233 };
1234 defer req.deinit();1234 defer req.deinit();
12351235
1236 req.start(.{ .raw_uri = true }) catch |err| break :tunnel err;1236 req.send(.{ .raw_uri = true }) catch |err| break :tunnel err;
1237 req.wait() catch |err| break :tunnel err;1237 req.wait() catch |err| break :tunnel err;
12381238
1239 if (req.response.status.class() == .server_error) {1239 if (req.response.status.class() == .server_error) {
...@@ -1266,9 +1266,9 @@ const ConnectErrorPartial = ConnectTcpError || error{ UnsupportedUrlScheme, Conn...@@ -1266,9 +1266,9 @@ const ConnectErrorPartial = ConnectTcpError || error{ UnsupportedUrlScheme, Conn
1266pub const ConnectError = ConnectErrorPartial || RequestError;1266pub const ConnectError = ConnectErrorPartial || RequestError;
12671267
1268/// Connect to `host:port` using the specified protocol. This will reuse a connection if one is already open.1268/// Connect to `host:port` using the specified protocol. This will reuse a connection if one is already open.
1269/// 1269///
1270/// If a proxy is configured for the client, then the proxy will be used to connect to the host.1270/// If a proxy is configured for the client, then the proxy will be used to connect to the host.
1271/// 1271///
1272/// This function is threadsafe.1272/// This function is threadsafe.
1273pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connection.Protocol) ConnectError!*Connection {1273pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connection.Protocol) ConnectError!*Connection {
1274 // pointer required so that `supports_connect` can be updated if a CONNECT fails1274 // pointer required so that `supports_connect` can be updated if a CONNECT fails
...@@ -1304,7 +1304,7 @@ pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connectio...@@ -1304,7 +1304,7 @@ pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connectio
1304 return client.connectTcp(host, port, protocol);1304 return client.connectTcp(host, port, protocol);
1305}1305}
13061306
1307pub const RequestError = ConnectTcpError || ConnectErrorPartial || Request.StartError || std.fmt.ParseIntError || Connection.WriteError || error{1307pub const RequestError = ConnectTcpError || ConnectErrorPartial || Request.SendError || std.fmt.ParseIntError || Connection.WriteError || error{
1308 UnsupportedUrlScheme,1308 UnsupportedUrlScheme,
1309 UriMissingHost,1309 UriMissingHost,
13101310
...@@ -1350,7 +1350,7 @@ pub const protocol_map = std.ComptimeStringMap(Connection.Protocol, .{...@@ -1350,7 +1350,7 @@ pub const protocol_map = std.ComptimeStringMap(Connection.Protocol, .{
1350///1350///
1351/// The caller is responsible for calling `deinit()` on the `Request`.1351/// The caller is responsible for calling `deinit()` on the `Request`.
1352/// This function is threadsafe.1352/// This function is threadsafe.
1353pub fn request(client: *Client, method: http.Method, uri: Uri, headers: http.Headers, options: RequestOptions) RequestError!Request {1353pub fn open(client: *Client, method: http.Method, uri: Uri, headers: http.Headers, options: RequestOptions) RequestError!Request {
1354 const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUrlScheme;1354 const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUrlScheme;
13551355
1356 const port: u16 = uri.port orelse switch (protocol) {1356 const port: u16 = uri.port orelse switch (protocol) {
...@@ -1446,7 +1446,7 @@ pub const FetchResult = struct {...@@ -1446,7 +1446,7 @@ pub const FetchResult = struct {
1446};1446};
14471447
1448/// Perform a one-shot HTTP request with the provided options.1448/// Perform a one-shot HTTP request with the provided options.
1449/// 1449///
1450/// This function is threadsafe.1450/// This function is threadsafe.
1451pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !FetchResult {1451pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !FetchResult {
1452 const has_transfer_encoding = options.headers.contains("transfer-encoding");1452 const has_transfer_encoding = options.headers.contains("transfer-encoding");
...@@ -1459,7 +1459,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc...@@ -1459,7 +1459,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc
1459 .uri => |u| u,1459 .uri => |u| u,
1460 };1460 };
14611461
1462 var req = try request(client, options.method, uri, options.headers, .{1462 var req = try open(client, options.method, uri, options.headers, .{
1463 .header_strategy = options.header_strategy,1463 .header_strategy = options.header_strategy,
1464 .handle_redirects = options.payload == .none,1464 .handle_redirects = options.payload == .none,
1465 });1465 });
...@@ -1476,7 +1476,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc...@@ -1476,7 +1476,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc
1476 .none => {},1476 .none => {},
1477 }1477 }
14781478
1479 try req.start(.{ .raw_uri = options.raw_uri });1479 try req.send(.{ .raw_uri = options.raw_uri });
14801480
1481 switch (options.payload) {1481 switch (options.payload) {
1482 .string => |str| try req.writeAll(str),1482 .string => |str| try req.writeAll(str),
lib/std/http/Server.zig+3-3
...@@ -392,10 +392,10 @@ pub const Response = struct {...@@ -392,10 +392,10 @@ pub const Response = struct {
392 }392 }
393 }393 }
394394
395 pub const StartError = Connection.WriteError || error{ UnsupportedTransferEncoding, InvalidContentLength };395 pub const SendError = Connection.WriteError || error{ UnsupportedTransferEncoding, InvalidContentLength };
396396
397 /// Send the HTTP response headers to the client.397 /// Send the HTTP response headers to the client.
398 pub fn start(res: *Response) StartError!void {398 pub fn send(res: *Response) SendError!void {
399 switch (res.state) {399 switch (res.state) {
400 .waited => res.state = .responded,400 .waited => res.state = .responded,
401 .first, .start, .responded, .finished => unreachable,401 .first, .start, .responded, .finished => unreachable,
...@@ -771,7 +771,7 @@ test "HTTP server handles a chunked transfer coding request" {...@@ -771,7 +771,7 @@ test "HTTP server handles a chunked transfer coding request" {
771 res.transfer_encoding = .{ .content_length = server_body.len };771 res.transfer_encoding = .{ .content_length = server_body.len };
772 try res.headers.append("content-type", "text/plain");772 try res.headers.append("content-type", "text/plain");
773 try res.headers.append("connection", "close");773 try res.headers.append("connection", "close");
774 try res.do();774 try res.send();
775775
776 var buf: [128]u8 = undefined;776 var buf: [128]u8 = undefined;
777 const n = try res.readAll(&buf);777 const n = try res.readAll(&buf);
src/Package/Fetch.zig+2-2
...@@ -826,7 +826,7 @@ fn initResource(f: *Fetch, uri: std.Uri) RunError!Resource {...@@ -826,7 +826,7 @@ fn initResource(f: *Fetch, uri: std.Uri) RunError!Resource {
826 var h = std.http.Headers{ .allocator = gpa };826 var h = std.http.Headers{ .allocator = gpa };
827 defer h.deinit();827 defer h.deinit();
828828
829 var req = http_client.request(.GET, uri, h, .{}) catch |err| {829 var req = http_client.open(.GET, uri, h, .{}) catch |err| {
830 return f.fail(f.location_tok, try eb.printString(830 return f.fail(f.location_tok, try eb.printString(
831 "unable to connect to server: {s}",831 "unable to connect to server: {s}",
832 .{@errorName(err)},832 .{@errorName(err)},
...@@ -834,7 +834,7 @@ fn initResource(f: *Fetch, uri: std.Uri) RunError!Resource {...@@ -834,7 +834,7 @@ fn initResource(f: *Fetch, uri: std.Uri) RunError!Resource {
834 };834 };
835 errdefer req.deinit(); // releases more than memory835 errdefer req.deinit(); // releases more than memory
836836
837 req.start(.{}) catch |err| {837 req.send(.{}) catch |err| {
838 return f.fail(f.location_tok, try eb.printString(838 return f.fail(f.location_tok, try eb.printString(
839 "HTTP request failed: {s}",839 "HTTP request failed: {s}",
840 .{@errorName(err)},840 .{@errorName(err)},
src/Package/Fetch/git.zig+6-6
...@@ -518,11 +518,11 @@ pub const Session = struct {...@@ -518,11 +518,11 @@ pub const Session = struct {
518 defer headers.deinit();518 defer headers.deinit();
519 try headers.append("Git-Protocol", "version=2");519 try headers.append("Git-Protocol", "version=2");
520520
521 var request = try session.transport.request(.GET, info_refs_uri, headers, .{521 var request = try session.transport.open(.GET, info_refs_uri, headers, .{
522 .max_redirects = 3,522 .max_redirects = 3,
523 });523 });
524 errdefer request.deinit();524 errdefer request.deinit();
525 try request.start(.{});525 try request.send(.{});
526 try request.finish();526 try request.finish();
527527
528 try request.wait();528 try request.wait();
...@@ -641,12 +641,12 @@ pub const Session = struct {...@@ -641,12 +641,12 @@ pub const Session = struct {
641 }641 }
642 try Packet.write(.flush, body_writer);642 try Packet.write(.flush, body_writer);
643643
644 var request = try session.transport.request(.POST, upload_pack_uri, headers, .{644 var request = try session.transport.open(.POST, upload_pack_uri, headers, .{
645 .handle_redirects = false,645 .handle_redirects = false,
646 });646 });
647 errdefer request.deinit();647 errdefer request.deinit();
648 request.transfer_encoding = .{ .content_length = body.items.len };648 request.transfer_encoding = .{ .content_length = body.items.len };
649 try request.start(.{});649 try request.send(.{});
650 try request.writeAll(body.items);650 try request.writeAll(body.items);
651 try request.finish();651 try request.finish();
652652
...@@ -740,12 +740,12 @@ pub const Session = struct {...@@ -740,12 +740,12 @@ pub const Session = struct {
740 try Packet.write(.{ .data = "done\n" }, body_writer);740 try Packet.write(.{ .data = "done\n" }, body_writer);
741 try Packet.write(.flush, body_writer);741 try Packet.write(.flush, body_writer);
742742
743 var request = try session.transport.request(.POST, upload_pack_uri, headers, .{743 var request = try session.transport.open(.POST, upload_pack_uri, headers, .{
744 .handle_redirects = false,744 .handle_redirects = false,
745 });745 });
746 errdefer request.deinit();746 errdefer request.deinit();
747 request.transfer_encoding = .{ .content_length = body.items.len };747 request.transfer_encoding = .{ .content_length = body.items.len };
748 try request.start(.{});748 try request.send(.{});
749 try request.writeAll(body.items);749 try request.writeAll(body.items);
750 try request.finish();750 try request.finish();
751751
test/standalone/http.zig+45-45
...@@ -29,11 +29,11 @@ fn handleRequest(res: *Server.Response) !void {...@@ -29,11 +29,11 @@ fn handleRequest(res: *Server.Response) !void {
29 if (res.request.headers.contains("expect")) {29 if (res.request.headers.contains("expect")) {
30 if (mem.eql(u8, res.request.headers.getFirstValue("expect").?, "100-continue")) {30 if (mem.eql(u8, res.request.headers.getFirstValue("expect").?, "100-continue")) {
31 res.status = .@"continue";31 res.status = .@"continue";
32 try res.start();32 try res.send();
33 res.status = .ok;33 res.status = .ok;
34 } else {34 } else {
35 res.status = .expectation_failed;35 res.status = .expectation_failed;
36 try res.start();36 try res.send();
37 return;37 return;
38 }38 }
39 }39 }
...@@ -54,7 +54,7 @@ fn handleRequest(res: *Server.Response) !void {...@@ -54,7 +54,7 @@ fn handleRequest(res: *Server.Response) !void {
5454
55 try res.headers.append("content-type", "text/plain");55 try res.headers.append("content-type", "text/plain");
5656
57 try res.start();57 try res.send();
58 if (res.request.method != .HEAD) {58 if (res.request.method != .HEAD) {
59 try res.writeAll("Hello, ");59 try res.writeAll("Hello, ");
60 try res.writeAll("World!\n");60 try res.writeAll("World!\n");
...@@ -65,7 +65,7 @@ fn handleRequest(res: *Server.Response) !void {...@@ -65,7 +65,7 @@ fn handleRequest(res: *Server.Response) !void {
65 } else if (mem.startsWith(u8, res.request.target, "/large")) {65 } else if (mem.startsWith(u8, res.request.target, "/large")) {
66 res.transfer_encoding = .{ .content_length = 14 * 1024 + 14 * 10 };66 res.transfer_encoding = .{ .content_length = 14 * 1024 + 14 * 10 };
6767
68 try res.start();68 try res.send();
6969
70 var i: u32 = 0;70 var i: u32 = 0;
71 while (i < 5) : (i += 1) {71 while (i < 5) : (i += 1) {
...@@ -92,14 +92,14 @@ fn handleRequest(res: *Server.Response) !void {...@@ -92,14 +92,14 @@ fn handleRequest(res: *Server.Response) !void {
92 try testing.expectEqualStrings("14", res.request.headers.getFirstValue("content-length").?);92 try testing.expectEqualStrings("14", res.request.headers.getFirstValue("content-length").?);
93 }93 }
9494
95 try res.start();95 try res.send();
96 try res.writeAll("Hello, ");96 try res.writeAll("Hello, ");
97 try res.writeAll("World!\n");97 try res.writeAll("World!\n");
98 try res.finish();98 try res.finish();
99 } else if (mem.eql(u8, res.request.target, "/trailer")) {99 } else if (mem.eql(u8, res.request.target, "/trailer")) {
100 res.transfer_encoding = .chunked;100 res.transfer_encoding = .chunked;
101101
102 try res.start();102 try res.send();
103 try res.writeAll("Hello, ");103 try res.writeAll("Hello, ");
104 try res.writeAll("World!\n");104 try res.writeAll("World!\n");
105 // try res.finish();105 // try res.finish();
...@@ -110,7 +110,7 @@ fn handleRequest(res: *Server.Response) !void {...@@ -110,7 +110,7 @@ fn handleRequest(res: *Server.Response) !void {
110 res.status = .found;110 res.status = .found;
111 try res.headers.append("location", "../../get");111 try res.headers.append("location", "../../get");
112112
113 try res.start();113 try res.send();
114 try res.writeAll("Hello, ");114 try res.writeAll("Hello, ");
115 try res.writeAll("Redirected!\n");115 try res.writeAll("Redirected!\n");
116 try res.finish();116 try res.finish();
...@@ -120,7 +120,7 @@ fn handleRequest(res: *Server.Response) !void {...@@ -120,7 +120,7 @@ fn handleRequest(res: *Server.Response) !void {
120 res.status = .found;120 res.status = .found;
121 try res.headers.append("location", "/redirect/1");121 try res.headers.append("location", "/redirect/1");
122122
123 try res.start();123 try res.send();
124 try res.writeAll("Hello, ");124 try res.writeAll("Hello, ");
125 try res.writeAll("Redirected!\n");125 try res.writeAll("Redirected!\n");
126 try res.finish();126 try res.finish();
...@@ -133,7 +133,7 @@ fn handleRequest(res: *Server.Response) !void {...@@ -133,7 +133,7 @@ fn handleRequest(res: *Server.Response) !void {
133 res.status = .found;133 res.status = .found;
134 try res.headers.append("location", location);134 try res.headers.append("location", location);
135135
136 try res.start();136 try res.send();
137 try res.writeAll("Hello, ");137 try res.writeAll("Hello, ");
138 try res.writeAll("Redirected!\n");138 try res.writeAll("Redirected!\n");
139 try res.finish();139 try res.finish();
...@@ -143,7 +143,7 @@ fn handleRequest(res: *Server.Response) !void {...@@ -143,7 +143,7 @@ fn handleRequest(res: *Server.Response) !void {
143 res.status = .found;143 res.status = .found;
144 try res.headers.append("location", "/redirect/3");144 try res.headers.append("location", "/redirect/3");
145145
146 try res.start();146 try res.send();
147 try res.writeAll("Hello, ");147 try res.writeAll("Hello, ");
148 try res.writeAll("Redirected!\n");148 try res.writeAll("Redirected!\n");
149 try res.finish();149 try res.finish();
...@@ -154,11 +154,11 @@ fn handleRequest(res: *Server.Response) !void {...@@ -154,11 +154,11 @@ fn handleRequest(res: *Server.Response) !void {
154154
155 res.status = .found;155 res.status = .found;
156 try res.headers.append("location", location);156 try res.headers.append("location", location);
157 try res.start();157 try res.send();
158 try res.finish();158 try res.finish();
159 } else {159 } else {
160 res.status = .not_found;160 res.status = .not_found;
161 try res.start();161 try res.send();
162 }162 }
163}163}
164164
...@@ -244,10 +244,10 @@ pub fn main() !void {...@@ -244,10 +244,10 @@ pub fn main() !void {
244 const uri = try std.Uri.parse(location);244 const uri = try std.Uri.parse(location);
245245
246 log.info("{s}", .{location});246 log.info("{s}", .{location});
247 var req = try client.request(.GET, uri, h, .{});247 var req = try client.open(.GET, uri, h, .{});
248 defer req.deinit();248 defer req.deinit();
249249
250 try req.start(.{});250 try req.send(.{});
251 try req.wait();251 try req.wait();
252252
253 const body = try req.reader().readAllAlloc(calloc, 8192);253 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -269,10 +269,10 @@ pub fn main() !void {...@@ -269,10 +269,10 @@ pub fn main() !void {
269 const uri = try std.Uri.parse(location);269 const uri = try std.Uri.parse(location);
270270
271 log.info("{s}", .{location});271 log.info("{s}", .{location});
272 var req = try client.request(.GET, uri, h, .{});272 var req = try client.open(.GET, uri, h, .{});
273 defer req.deinit();273 defer req.deinit();
274274
275 try req.start(.{});275 try req.send(.{});
276 try req.wait();276 try req.wait();
277277
278 const body = try req.reader().readAllAlloc(calloc, 8192 * 1024);278 const body = try req.reader().readAllAlloc(calloc, 8192 * 1024);
...@@ -293,10 +293,10 @@ pub fn main() !void {...@@ -293,10 +293,10 @@ pub fn main() !void {
293 const uri = try std.Uri.parse(location);293 const uri = try std.Uri.parse(location);
294294
295 log.info("{s}", .{location});295 log.info("{s}", .{location});
296 var req = try client.request(.HEAD, uri, h, .{});296 var req = try client.open(.HEAD, uri, h, .{});
297 defer req.deinit();297 defer req.deinit();
298298
299 try req.start(.{});299 try req.send(.{});
300 try req.wait();300 try req.wait();
301301
302 const body = try req.reader().readAllAlloc(calloc, 8192);302 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -319,10 +319,10 @@ pub fn main() !void {...@@ -319,10 +319,10 @@ pub fn main() !void {
319 const uri = try std.Uri.parse(location);319 const uri = try std.Uri.parse(location);
320320
321 log.info("{s}", .{location});321 log.info("{s}", .{location});
322 var req = try client.request(.GET, uri, h, .{});322 var req = try client.open(.GET, uri, h, .{});
323 defer req.deinit();323 defer req.deinit();
324324
325 try req.start(.{});325 try req.send(.{});
326 try req.wait();326 try req.wait();
327327
328 const body = try req.reader().readAllAlloc(calloc, 8192);328 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -344,10 +344,10 @@ pub fn main() !void {...@@ -344,10 +344,10 @@ pub fn main() !void {
344 const uri = try std.Uri.parse(location);344 const uri = try std.Uri.parse(location);
345345
346 log.info("{s}", .{location});346 log.info("{s}", .{location});
347 var req = try client.request(.HEAD, uri, h, .{});347 var req = try client.open(.HEAD, uri, h, .{});
348 defer req.deinit();348 defer req.deinit();
349349
350 try req.start(.{});350 try req.send(.{});
351 try req.wait();351 try req.wait();
352352
353 const body = try req.reader().readAllAlloc(calloc, 8192);353 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -370,10 +370,10 @@ pub fn main() !void {...@@ -370,10 +370,10 @@ pub fn main() !void {
370 const uri = try std.Uri.parse(location);370 const uri = try std.Uri.parse(location);
371371
372 log.info("{s}", .{location});372 log.info("{s}", .{location});
373 var req = try client.request(.GET, uri, h, .{});373 var req = try client.open(.GET, uri, h, .{});
374 defer req.deinit();374 defer req.deinit();
375375
376 try req.start(.{});376 try req.send(.{});
377 try req.wait();377 try req.wait();
378378
379 const body = try req.reader().readAllAlloc(calloc, 8192);379 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -397,12 +397,12 @@ pub fn main() !void {...@@ -397,12 +397,12 @@ pub fn main() !void {
397 const uri = try std.Uri.parse(location);397 const uri = try std.Uri.parse(location);
398398
399 log.info("{s}", .{location});399 log.info("{s}", .{location});
400 var req = try client.request(.POST, uri, h, .{});400 var req = try client.open(.POST, uri, h, .{});
401 defer req.deinit();401 defer req.deinit();
402402
403 req.transfer_encoding = .{ .content_length = 14 };403 req.transfer_encoding = .{ .content_length = 14 };
404404
405 try req.start(.{});405 try req.send(.{});
406 try req.writeAll("Hello, ");406 try req.writeAll("Hello, ");
407 try req.writeAll("World!\n");407 try req.writeAll("World!\n");
408 try req.finish();408 try req.finish();
...@@ -429,10 +429,10 @@ pub fn main() !void {...@@ -429,10 +429,10 @@ pub fn main() !void {
429 const uri = try std.Uri.parse(location);429 const uri = try std.Uri.parse(location);
430430
431 log.info("{s}", .{location});431 log.info("{s}", .{location});
432 var req = try client.request(.GET, uri, h, .{});432 var req = try client.open(.GET, uri, h, .{});
433 defer req.deinit();433 defer req.deinit();
434434
435 try req.start(.{});435 try req.send(.{});
436 try req.wait();436 try req.wait();
437437
438 const body = try req.reader().readAllAlloc(calloc, 8192);438 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -456,12 +456,12 @@ pub fn main() !void {...@@ -456,12 +456,12 @@ pub fn main() !void {
456 const uri = try std.Uri.parse(location);456 const uri = try std.Uri.parse(location);
457457
458 log.info("{s}", .{location});458 log.info("{s}", .{location});
459 var req = try client.request(.POST, uri, h, .{});459 var req = try client.open(.POST, uri, h, .{});
460 defer req.deinit();460 defer req.deinit();
461461
462 req.transfer_encoding = .chunked;462 req.transfer_encoding = .chunked;
463463
464 try req.start(.{});464 try req.send(.{});
465 try req.writeAll("Hello, ");465 try req.writeAll("Hello, ");
466 try req.writeAll("World!\n");466 try req.writeAll("World!\n");
467 try req.finish();467 try req.finish();
...@@ -486,10 +486,10 @@ pub fn main() !void {...@@ -486,10 +486,10 @@ pub fn main() !void {
486 const uri = try std.Uri.parse(location);486 const uri = try std.Uri.parse(location);
487487
488 log.info("{s}", .{location});488 log.info("{s}", .{location});
489 var req = try client.request(.GET, uri, h, .{});489 var req = try client.open(.GET, uri, h, .{});
490 defer req.deinit();490 defer req.deinit();
491491
492 try req.start(.{});492 try req.send(.{});
493 try req.wait();493 try req.wait();
494494
495 const body = try req.reader().readAllAlloc(calloc, 8192);495 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -510,10 +510,10 @@ pub fn main() !void {...@@ -510,10 +510,10 @@ pub fn main() !void {
510 const uri = try std.Uri.parse(location);510 const uri = try std.Uri.parse(location);
511511
512 log.info("{s}", .{location});512 log.info("{s}", .{location});
513 var req = try client.request(.GET, uri, h, .{});513 var req = try client.open(.GET, uri, h, .{});
514 defer req.deinit();514 defer req.deinit();
515515
516 try req.start(.{});516 try req.send(.{});
517 try req.wait();517 try req.wait();
518518
519 const body = try req.reader().readAllAlloc(calloc, 8192);519 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -534,10 +534,10 @@ pub fn main() !void {...@@ -534,10 +534,10 @@ pub fn main() !void {
534 const uri = try std.Uri.parse(location);534 const uri = try std.Uri.parse(location);
535535
536 log.info("{s}", .{location});536 log.info("{s}", .{location});
537 var req = try client.request(.GET, uri, h, .{});537 var req = try client.open(.GET, uri, h, .{});
538 defer req.deinit();538 defer req.deinit();
539539
540 try req.start(.{});540 try req.send(.{});
541 try req.wait();541 try req.wait();
542542
543 const body = try req.reader().readAllAlloc(calloc, 8192);543 const body = try req.reader().readAllAlloc(calloc, 8192);
...@@ -558,10 +558,10 @@ pub fn main() !void {...@@ -558,10 +558,10 @@ pub fn main() !void {
558 const uri = try std.Uri.parse(location);558 const uri = try std.Uri.parse(location);
559559
560 log.info("{s}", .{location});560 log.info("{s}", .{location});
561 var req = try client.request(.GET, uri, h, .{});561 var req = try client.open(.GET, uri, h, .{});
562 defer req.deinit();562 defer req.deinit();
563563
564 try req.start(.{});564 try req.send(.{});
565 req.wait() catch |err| switch (err) {565 req.wait() catch |err| switch (err) {
566 error.TooManyHttpRedirects => {},566 error.TooManyHttpRedirects => {},
567 else => return err,567 else => return err,
...@@ -580,10 +580,10 @@ pub fn main() !void {...@@ -580,10 +580,10 @@ pub fn main() !void {
580 const uri = try std.Uri.parse(location);580 const uri = try std.Uri.parse(location);
581581
582 log.info("{s}", .{location});582 log.info("{s}", .{location});
583 var req = try client.request(.GET, uri, h, .{});583 var req = try client.open(.GET, uri, h, .{});
584 defer req.deinit();584 defer req.deinit();
585585
586 try req.start(.{});586 try req.send(.{});
587 const result = req.wait();587 const result = req.wait();
588588
589 // a proxy without an upstream is likely to return a 5xx status.589 // a proxy without an upstream is likely to return a 5xx status.
...@@ -628,12 +628,12 @@ pub fn main() !void {...@@ -628,12 +628,12 @@ pub fn main() !void {
628 const uri = try std.Uri.parse(location);628 const uri = try std.Uri.parse(location);
629629
630 log.info("{s}", .{location});630 log.info("{s}", .{location});
631 var req = try client.request(.POST, uri, h, .{});631 var req = try client.open(.POST, uri, h, .{});
632 defer req.deinit();632 defer req.deinit();
633633
634 req.transfer_encoding = .chunked;634 req.transfer_encoding = .chunked;
635635
636 try req.start(.{});636 try req.send(.{});
637 try req.wait();637 try req.wait();
638 try testing.expectEqual(http.Status.@"continue", req.response.status);638 try testing.expectEqual(http.Status.@"continue", req.response.status);
639639
...@@ -662,12 +662,12 @@ pub fn main() !void {...@@ -662,12 +662,12 @@ pub fn main() !void {
662 const uri = try std.Uri.parse(location);662 const uri = try std.Uri.parse(location);
663663
664 log.info("{s}", .{location});664 log.info("{s}", .{location});
665 var req = try client.request(.POST, uri, h, .{});665 var req = try client.open(.POST, uri, h, .{});
666 defer req.deinit();666 defer req.deinit();
667667
668 req.transfer_encoding = .chunked;668 req.transfer_encoding = .chunked;
669669
670 try req.start(.{});670 try req.send(.{});
671 try req.wait();671 try req.wait();
672 try testing.expectEqual(http.Status.expectation_failed, req.response.status);672 try testing.expectEqual(http.Status.expectation_failed, req.response.status);
673 }673 }
...@@ -682,7 +682,7 @@ pub fn main() !void {...@@ -682,7 +682,7 @@ pub fn main() !void {
682 defer calloc.free(requests);682 defer calloc.free(requests);
683683
684 for (0..total_connections) |i| {684 for (0..total_connections) |i| {
685 var req = try client.request(.GET, uri, .{ .allocator = calloc }, .{});685 var req = try client.open(.GET, uri, .{ .allocator = calloc }, .{});
686 req.response.parser.done = true;686 req.response.parser.done = true;
687 req.connection.?.closing = false;687 req.connection.?.closing = false;
688 requests[i] = req;688 requests[i] = req;