@@ -255,7 +255,8 @@ pub const Aligner = struct {
255
255
};
256
256
257
257
const NetworkTask = struct {
258
- http: AsyncHTTP = undefined,
258
+ unsafe_http_client: AsyncHTTP = undefined,
259
+ response: bun.http.HTTPClientResult = .{},
259
260
task_id: u64,
260
261
url_buf: []const u8 = &[_]u8{},
261
262
retried: u16 = 0,
@@ -282,10 +283,11 @@ const NetworkTask = struct {
282
283
};
283
284
pub const DedupeMap = std.HashMap(u64, DedupeMapEntry, IdentityContext(u64), 80);
284
285
285
- pub fn notify(this: *NetworkTask, async_http: *AsyncHTTP, _: anytype ) void {
286
+ pub fn notify(this: *NetworkTask, async_http: *AsyncHTTP, result: bun.http.HTTPClientResult ) void {
286
287
defer this.package_manager.wake();
287
288
async_http.real.?.* = async_http.*;
288
289
async_http.real.?.response_buffer = async_http.response_buffer;
290
+ this.response = result;
289
291
this.package_manager.async_network_task_queue.push(this);
290
292
}
291
293
@@ -454,13 +456,13 @@ const NetworkTask = struct {
454
456
this.allocator = allocator;
455
457
456
458
const url = URL.parse(this.url_buf);
457
- this.http = AsyncHTTP.init(allocator, .GET, url, header_builder.entries, header_builder.content.ptr.?[0..header_builder.content.len], &this.response_buffer, "", this.getCompletionCallback(), HTTP.FetchRedirect.follow, .{
459
+ this.unsafe_http_client = AsyncHTTP.init(allocator, .GET, url, header_builder.entries, header_builder.content.ptr.?[0..header_builder.content.len], &this.response_buffer, "", this.getCompletionCallback(), HTTP.FetchRedirect.follow, .{
458
460
.http_proxy = this.package_manager.httpProxy(url),
459
461
});
460
- this.http .client.flags.reject_unauthorized = this.package_manager.tlsRejectUnauthorized();
462
+ this.unsafe_http_client .client.flags.reject_unauthorized = this.package_manager.tlsRejectUnauthorized();
461
463
462
464
if (PackageManager.verbose_install) {
463
- this.http .client.verbose = .headers;
465
+ this.unsafe_http_client .client.verbose = .headers;
464
466
}
465
467
466
468
this.callback = .{
@@ -471,14 +473,14 @@ const NetworkTask = struct {
471
473
};
472
474
473
475
if (PackageManager.verbose_install) {
474
- this.http .verbose = .headers;
475
- this.http .client.verbose = .headers;
476
+ this.unsafe_http_client .verbose = .headers;
477
+ this.unsafe_http_client .client.verbose = .headers;
476
478
}
477
479
478
480
// Incase the ETag causes invalidation, we fallback to the last modified date.
479
481
if (last_modified.len != 0 and bun.getRuntimeFeatureFlag("BUN_FEATURE_FLAG_LAST_MODIFIED_PRETEND_304")) {
480
- this.http .client.flags.force_last_modified = true;
481
- this.http .client.if_modified_since = last_modified;
482
+ this.unsafe_http_client .client.flags.force_last_modified = true;
483
+ this.unsafe_http_client .client.if_modified_since = last_modified;
482
484
}
483
485
}
484
486
@@ -487,7 +489,7 @@ const NetworkTask = struct {
487
489
}
488
490
489
491
pub fn schedule(this: *NetworkTask, batch: *ThreadPool.Batch) void {
490
- this.http .schedule(this.allocator, batch);
492
+ this.unsafe_http_client .schedule(this.allocator, batch);
491
493
}
492
494
493
495
pub const ForTarballError = OOM || error{
@@ -547,12 +549,12 @@ const NetworkTask = struct {
547
549
548
550
const url = URL.parse(this.url_buf);
549
551
550
- this.http = AsyncHTTP.init(allocator, .GET, url, header_builder.entries, header_buf, &this.response_buffer, "", this.getCompletionCallback(), HTTP.FetchRedirect.follow, .{
552
+ this.unsafe_http_client = AsyncHTTP.init(allocator, .GET, url, header_builder.entries, header_buf, &this.response_buffer, "", this.getCompletionCallback(), HTTP.FetchRedirect.follow, .{
551
553
.http_proxy = this.package_manager.httpProxy(url),
552
554
});
553
- this.http .client.flags.reject_unauthorized = this.package_manager.tlsRejectUnauthorized();
555
+ this.unsafe_http_client .client.flags.reject_unauthorized = this.package_manager.tlsRejectUnauthorized();
554
556
if (PackageManager.verbose_install) {
555
- this.http .client.verbose = .headers;
557
+ this.unsafe_http_client .client.verbose = .headers;
556
558
}
557
559
}
558
560
};
@@ -736,7 +738,7 @@ pub const Task = struct {
736
738
const package_manifest = Npm.Registry.getPackageMetadata(
737
739
allocator,
738
740
manager.scopeForPackageName(manifest.name.slice()),
739
- manifest.network.http. response.? ,
741
+ ( manifest.network.response.metadata orelse @panic("Assertion failure: Expected metadata to be set")).response ,
740
742
body,
741
743
&this.log,
742
744
manifest.name.slice(),
@@ -6402,7 +6404,7 @@ pub const PackageManager = struct {
6402
6404
}
6403
6405
}
6404
6406
6405
- if (!has_network_error and task.http. response == null) {
6407
+ if (!has_network_error and task.response.metadata == null) {
6406
6408
has_network_error = true;
6407
6409
const min = manager.options.min_simultaneous_requests;
6408
6410
const max = AsyncHTTP.max_simultaneous_requests.load(.monotonic);
@@ -6412,8 +6414,8 @@ pub const PackageManager = struct {
6412
6414
}
6413
6415
6414
6416
// Handle retry-able errors.
6415
- if (task.http. response == null or task.http. response.? .status_code > 499) {
6416
- const err = task.http.err orelse error.HTTPError;
6417
+ if (task.response.metadata == null or task.response.metadata.?.response .status_code > 499) {
6418
+ const err = task.response.fail orelse error.HTTPError;
6417
6419
6418
6420
if (task.retried < manager.options.max_retry_count) {
6419
6421
task.retried += 1;
@@ -6433,9 +6435,9 @@ pub const PackageManager = struct {
6433
6435
}
6434
6436
}
6435
6437
6436
- const response = task.http. response orelse {
6438
+ const metadata = task.response.metadata orelse {
6437
6439
// Handle non-retry-able errors.
6438
- const err = task.http.err orelse error.HTTPError;
6440
+ const err = task.response.fail orelse error.HTTPError;
6439
6441
6440
6442
if (@TypeOf(callbacks.onPackageManifestError) != void) {
6441
6443
callbacks.onPackageManifestError(
@@ -6478,6 +6480,7 @@ pub const PackageManager = struct {
6478
6480
6479
6481
continue;
6480
6482
};
6483
+ const response = metadata.response;
6481
6484
6482
6485
if (response.status_code > 399) {
6483
6486
if (@TypeOf(callbacks.onPackageManifestError) != void) {
@@ -6507,15 +6510,15 @@ pub const PackageManager = struct {
6507
6510
logger.Loc.Empty,
6508
6511
manager.allocator,
6509
6512
"<r><red><b>GET<r><red> {s}<d> - {d}<r>",
6510
- .{ task.http.client. url.href , response.status_code },
6513
+ .{ metadata. url, response.status_code },
6511
6514
) catch bun.outOfMemory();
6512
6515
} else {
6513
6516
manager.log.addWarningFmt(
6514
6517
null,
6515
6518
logger.Loc.Empty,
6516
6519
manager.allocator,
6517
6520
"<r><yellow><b>GET<r><yellow> {s}<d> - {d}<r>",
6518
- .{ task.http.client. url.href , response.status_code },
6521
+ .{ metadata. url, response.status_code },
6519
6522
) catch bun.outOfMemory();
6520
6523
}
6521
6524
if (manager.subcommand != .remove) {
@@ -6534,7 +6537,7 @@ pub const PackageManager = struct {
6534
6537
6535
6538
if (comptime log_level.isVerbose()) {
6536
6539
Output.prettyError(" ", .{});
6537
- Output.printElapsed(@as(f64, @floatFromInt(task.http .elapsed)) / std.time.ns_per_ms);
6540
+ Output.printElapsed(@as(f64, @floatFromInt(task.unsafe_http_client .elapsed)) / std.time.ns_per_ms);
6538
6541
Output.prettyError("\n<d>Downloaded <r><green>{s}<r> versions\n", .{name.slice()});
6539
6542
Output.flush();
6540
6543
}
@@ -6582,7 +6585,7 @@ pub const PackageManager = struct {
6582
6585
manager.task_batch.push(ThreadPool.Batch.from(manager.enqueueParseNPMPackage(task.task_id, name, task)));
6583
6586
},
6584
6587
.extract => |*extract| {
6585
- if (!has_network_error and task.http. response == null) {
6588
+ if (!has_network_error and task.response.metadata == null) {
6586
6589
has_network_error = true;
6587
6590
const min = manager.options.min_simultaneous_requests;
6588
6591
const max = AsyncHTTP.max_simultaneous_requests.load(.monotonic);
@@ -6591,8 +6594,8 @@ pub const PackageManager = struct {
6591
6594
}
6592
6595
}
6593
6596
6594
- if (task.http. response == null or task.http. response.? .status_code > 499) {
6595
- const err = task.http.err orelse error.TarballFailedToDownload;
6597
+ if (task.response.metadata == null or task.response.metadata.?.response .status_code > 499) {
6598
+ const err = task.response.fail orelse error.TarballFailedToDownload;
6596
6599
6597
6600
if (task.retried < manager.options.max_retry_count) {
6598
6601
task.retried += 1;
@@ -6618,8 +6621,8 @@ pub const PackageManager = struct {
6618
6621
}
6619
6622
}
6620
6623
6621
- const response = task.http. response orelse {
6622
- const err = task.http.err orelse error.TarballFailedToDownload;
6624
+ const metadata = task.response.metadata orelse {
6625
+ const err = task.response.fail orelse error.TarballFailedToDownload;
6623
6626
6624
6627
if (@TypeOf(callbacks.onPackageDownloadError) != void) {
6625
6628
const package_id = manager.lockfile.buffers.resolutions.items[extract.dependency_id];
@@ -6674,6 +6677,8 @@ pub const PackageManager = struct {
6674
6677
continue;
6675
6678
};
6676
6679
6680
+ const response = metadata.response;
6681
+
6677
6682
if (response.status_code > 399) {
6678
6683
if (@TypeOf(callbacks.onPackageDownloadError) != void) {
6679
6684
const err = switch (response.status_code) {
@@ -6705,7 +6710,7 @@ pub const PackageManager = struct {
6705
6710
manager.allocator,
6706
6711
"<r><red><b>GET<r><red> {s}<d> - {d}<r>",
6707
6712
.{
6708
- task.http.client. url.href ,
6713
+ metadata. url,
6709
6714
response.status_code,
6710
6715
},
6711
6716
) catch bun.outOfMemory();
@@ -6716,7 +6721,7 @@ pub const PackageManager = struct {
6716
6721
manager.allocator,
6717
6722
"<r><yellow><b>GET<r><yellow> {s}<d> - {d}<r>",
6718
6723
.{
6719
- task.http.client. url.href ,
6724
+ metadata. url,
6720
6725
response.status_code,
6721
6726
},
6722
6727
) catch bun.outOfMemory();
@@ -6737,7 +6742,7 @@ pub const PackageManager = struct {
6737
6742
6738
6743
if (comptime log_level.isVerbose()) {
6739
6744
Output.prettyError(" ", .{});
6740
- Output.printElapsed(@as(f64, @floatCast(@as(f64, @floatFromInt(task.http .elapsed)) / std.time.ns_per_ms)));
6745
+ Output.printElapsed(@as(f64, @floatCast(@as(f64, @floatFromInt(task.unsafe_http_client .elapsed)) / std.time.ns_per_ms)));
6741
6746
Output.prettyError("<d> Downloaded <r><green>{s}<r> tarball\n", .{extract.name.slice()});
6742
6747
Output.flush();
6743
6748
}
0 commit comments