diff options
author | 2022-12-27 07:15:58 +0800 | |
---|---|---|
committer | 2022-12-26 15:15:58 -0800 | |
commit | c4ca4c70d194f63cc6598c8452656d97c3f7a5e6 (patch) | |
tree | 8b6aa6700d0e222050253129a022ec1c9770de39 /src | |
parent | d94b96d9f440d3aeef4402aec9f3788bca2972d0 (diff) | |
download | bun-c4ca4c70d194f63cc6598c8452656d97c3f7a5e6.tar.gz bun-c4ca4c70d194f63cc6598c8452656d97c3f7a5e6.tar.zst bun-c4ca4c70d194f63cc6598c8452656d97c3f7a5e6.zip |
[install] specify `auth-type` (#1667)
Diffstat (limited to 'src')
-rw-r--r-- | src/install/install.zig | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/src/install/install.zig b/src/install/install.zig index 5dfddf78a..2748a0af0 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -197,6 +197,30 @@ const NetworkTask = struct { const default_headers_buf: string = "Accept" ++ accept_header_value; + fn appendAuth(header_builder: *HeaderBuilder, scope: *const Npm.Registry.Scope) void { + if (scope.token.len > 0) { + header_builder.appendFmt("Authorization", "Bearer {s}", .{scope.token}); + } else if (scope.auth.len > 0) { + header_builder.appendFmt("Authorization", "Basic {s}", .{scope.auth}); + } else { + return; + } + header_builder.append("npm-auth-type", "legacy"); + } + + fn countAuth(header_builder: *HeaderBuilder, scope: *const Npm.Registry.Scope) void { + if (scope.token.len > 0) { + header_builder.count("Authorization", ""); + header_builder.content.cap += "Bearer ".len + scope.token.len; + } else if (scope.auth.len > 0) { + header_builder.count("Authorization", ""); + header_builder.content.cap += "Basic ".len + scope.auth.len; + } else { + return; + } + header_builder.count("npm-auth-type", "legacy"); + } + pub fn forManifest( this: *NetworkTask, name: string, @@ -268,13 +292,7 @@ const NetworkTask = struct { var header_builder = HeaderBuilder{}; - if (scope.token.len > 0) { - header_builder.count("Authorization", ""); - header_builder.content.cap += "Bearer ".len + scope.token.len; - } else if (scope.auth.len > 0) { - header_builder.count("Authorization", ""); - header_builder.content.cap += "Basic ".len + scope.auth.len; - } + countAuth(&header_builder, scope); if (etag.len != 0) { header_builder.count("If-None-Match", etag); @@ -289,11 +307,7 @@ const NetworkTask = struct { } try header_builder.allocate(allocator); - if (scope.token.len > 0) { - header_builder.appendFmt("Authorization", "Bearer {s}", .{scope.token}); - } else if (scope.auth.len > 0) { - header_builder.appendFmt("Authorization", "Basic {s}", .{scope.auth}); - } + appendAuth(&header_builder, scope); if (etag.len != 0) { header_builder.append("If-None-Match", etag); @@ -381,23 +395,13 @@ const NetworkTask = struct { var header_builder = HeaderBuilder{}; - if (scope.token.len > 0) { - header_builder.count("Authorization", ""); - header_builder.content.cap += "Bearer ".len + scope.token.len; - } else if (scope.auth.len > 0) { - header_builder.count("Authorization", ""); - header_builder.content.cap += "Basic ".len + scope.auth.len; - } + countAuth(&header_builder, scope); var header_buf: string = ""; if (header_builder.header_count > 0) { try header_builder.allocate(allocator); - if (scope.token.len > 0) { - header_builder.appendFmt("Authorization", "Bearer {s}", .{scope.token}); - } else if (scope.auth.len > 0) { - header_builder.appendFmt("Authorization", "Basic {s}", .{scope.auth}); - } + appendAuth(&header_builder, scope); header_buf = header_builder.content.ptr.?[0..header_builder.content.len]; } |