mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
New HTTP client (#1231)
* wip * It mostly works! * Support `bun install` * Support `bun create` * Support chunked transfer encoding * Handle Keep Alive when redirecting to a different domain Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -251,7 +251,7 @@ pub const CreateCommand = struct {
|
||||
@setCold(true);
|
||||
|
||||
Global.configureAllocator(.{ .long_running = false });
|
||||
try NetworkThread.init();
|
||||
try HTTP.HTTPThread.init();
|
||||
|
||||
var create_options = try CreateOptions.parse(ctx, false);
|
||||
const positionals = create_options.positionals;
|
||||
@@ -1849,7 +1849,16 @@ pub const Example = struct {
|
||||
|
||||
// ensure very stable memory address
|
||||
var async_http: *HTTP.AsyncHTTP = ctx.allocator.create(HTTP.AsyncHTTP) catch unreachable;
|
||||
async_http.* = try HTTP.AsyncHTTP.init(ctx.allocator, .GET, api_url, header_entries, headers_buf, mutable, &request_body, 60 * std.time.ns_per_min);
|
||||
async_http.* = HTTP.AsyncHTTP.initSync(
|
||||
ctx.allocator,
|
||||
.GET,
|
||||
api_url,
|
||||
header_entries,
|
||||
headers_buf,
|
||||
mutable,
|
||||
&request_body,
|
||||
60 * std.time.ns_per_min,
|
||||
);
|
||||
async_http.client.progress_node = progress;
|
||||
const response = try async_http.sendSync(true);
|
||||
|
||||
@@ -1912,7 +1921,7 @@ pub const Example = struct {
|
||||
|
||||
// ensure very stable memory address
|
||||
var async_http: *HTTP.AsyncHTTP = ctx.allocator.create(HTTP.AsyncHTTP) catch unreachable;
|
||||
async_http.* = try HTTP.AsyncHTTP.init(ctx.allocator, .GET, url, .{}, "", mutable, &request_body, 60 * std.time.ns_per_min);
|
||||
async_http.* = HTTP.AsyncHTTP.initSync(ctx.allocator, .GET, url, .{}, "", mutable, &request_body, 60 * std.time.ns_per_min);
|
||||
async_http.client.progress_node = progress;
|
||||
var response = try async_http.sendSync(true);
|
||||
|
||||
@@ -1984,7 +1993,7 @@ pub const Example = struct {
|
||||
mutable.reset();
|
||||
|
||||
// ensure very stable memory address
|
||||
async_http.* = try HTTP.AsyncHTTP.init(ctx.allocator, .GET, URL.parse(tarball_url), .{}, "", mutable, &request_body, 60 * std.time.ns_per_min);
|
||||
async_http.* = HTTP.AsyncHTTP.initSync(ctx.allocator, .GET, URL.parse(tarball_url), .{}, "", mutable, &request_body, 60 * std.time.ns_per_min);
|
||||
async_http.client.progress_node = progress;
|
||||
|
||||
refresher.maybeRefresh();
|
||||
@@ -2013,7 +2022,16 @@ pub const Example = struct {
|
||||
var mutable = try ctx.allocator.create(MutableString);
|
||||
mutable.* = try MutableString.init(ctx.allocator, 2048);
|
||||
|
||||
async_http.* = try HTTP.AsyncHTTP.init(ctx.allocator, .GET, url, .{}, "", mutable, &request_body, 60 * std.time.ns_per_min);
|
||||
async_http.* = HTTP.AsyncHTTP.initSync(
|
||||
ctx.allocator,
|
||||
.GET,
|
||||
url,
|
||||
.{},
|
||||
"",
|
||||
mutable,
|
||||
&request_body,
|
||||
60 * std.time.ns_per_min,
|
||||
);
|
||||
|
||||
if (Output.enable_ansi_colors) {
|
||||
async_http.client.progress_node = progress_node;
|
||||
|
||||
Reference in New Issue
Block a user