| ... | @@ -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 { |
| 54 | | 54 | |
| 55 | try res.headers.append("content-type", "text/plain"); | 55 | try res.headers.append("content-type", "text/plain"); |
| 56 | | 56 | |
| 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 }; |
| 67 | | 67 | |
| 68 | try res.start(); | 68 | try res.send(); |
| 69 | | 69 | |
| 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 | } |
| 94 | | 94 | |
| 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; |
| 101 | | 101 | |
| 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"); |
| 112 | | 112 | |
| 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"); |
| 122 | | 122 | |
| 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); |
| 135 | | 135 | |
| 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"); |
| 145 | | 145 | |
| 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 { |
| 154 | | 154 | |
| 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 | } |
| 164 | | 164 | |
| ... | @@ -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); |
| 245 | | 245 | |
| 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(); |
| 249 | | 249 | |
| 250 | try req.start(.{}); | 250 | try req.send(.{}); |
| 251 | try req.wait(); | 251 | try req.wait(); |
| 252 | | 252 | |
| 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); |
| 270 | | 270 | |
| 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(); |
| 274 | | 274 | |
| 275 | try req.start(.{}); | 275 | try req.send(.{}); |
| 276 | try req.wait(); | 276 | try req.wait(); |
| 277 | | 277 | |
| 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); |
| 294 | | 294 | |
| 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(); |
| 298 | | 298 | |
| 299 | try req.start(.{}); | 299 | try req.send(.{}); |
| 300 | try req.wait(); | 300 | try req.wait(); |
| 301 | | 301 | |
| 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); |
| 320 | | 320 | |
| 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(); |
| 324 | | 324 | |
| 325 | try req.start(.{}); | 325 | try req.send(.{}); |
| 326 | try req.wait(); | 326 | try req.wait(); |
| 327 | | 327 | |
| 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); |
| 345 | | 345 | |
| 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(); |
| 349 | | 349 | |
| 350 | try req.start(.{}); | 350 | try req.send(.{}); |
| 351 | try req.wait(); | 351 | try req.wait(); |
| 352 | | 352 | |
| 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); |
| 371 | | 371 | |
| 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(); |
| 375 | | 375 | |
| 376 | try req.start(.{}); | 376 | try req.send(.{}); |
| 377 | try req.wait(); | 377 | try req.wait(); |
| 378 | | 378 | |
| 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); |
| 398 | | 398 | |
| 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(); |
| 402 | | 402 | |
| 403 | req.transfer_encoding = .{ .content_length = 14 }; | 403 | req.transfer_encoding = .{ .content_length = 14 }; |
| 404 | | 404 | |
| 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); |
| 430 | | 430 | |
| 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(); |
| 434 | | 434 | |
| 435 | try req.start(.{}); | 435 | try req.send(.{}); |
| 436 | try req.wait(); | 436 | try req.wait(); |
| 437 | | 437 | |
| 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); |
| 457 | | 457 | |
| 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(); |
| 461 | | 461 | |
| 462 | req.transfer_encoding = .chunked; | 462 | req.transfer_encoding = .chunked; |
| 463 | | 463 | |
| 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); |
| 487 | | 487 | |
| 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(); |
| 491 | | 491 | |
| 492 | try req.start(.{}); | 492 | try req.send(.{}); |
| 493 | try req.wait(); | 493 | try req.wait(); |
| 494 | | 494 | |
| 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); |
| 511 | | 511 | |
| 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(); |
| 515 | | 515 | |
| 516 | try req.start(.{}); | 516 | try req.send(.{}); |
| 517 | try req.wait(); | 517 | try req.wait(); |
| 518 | | 518 | |
| 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); |
| 535 | | 535 | |
| 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(); |
| 539 | | 539 | |
| 540 | try req.start(.{}); | 540 | try req.send(.{}); |
| 541 | try req.wait(); | 541 | try req.wait(); |
| 542 | | 542 | |
| 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); |
| 559 | | 559 | |
| 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(); |
| 563 | | 563 | |
| 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); |
| 581 | | 581 | |
| 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(); |
| 585 | | 585 | |
| 586 | try req.start(.{}); | 586 | try req.send(.{}); |
| 587 | const result = req.wait(); | 587 | const result = req.wait(); |
| 588 | | 588 | |
| 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); |
| 629 | | 629 | |
| 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(); |
| 633 | | 633 | |
| 634 | req.transfer_encoding = .chunked; | 634 | req.transfer_encoding = .chunked; |
| 635 | | 635 | |
| 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); |
| 639 | | 639 | |
| ... | @@ -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); |
| 663 | | 663 | |
| 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(); |
| 667 | | 667 | |
| 668 | req.transfer_encoding = .chunked; | 668 | req.transfer_encoding = .chunked; |
| 669 | | 669 | |
| 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); |
| 683 | | 683 | |
| 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; |