authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-16 00:56:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-23 02:37:11-07:00
log99a5de9dbb0a3a30f09056558f715f7607b1a20a
treeeedca0be26422424b81c38d8c2c8b1ae48275f59
parentb6ca89fa7c0c4c766229586f1977babfb20d782a

git fetching: fix redirect handling

I mistakenly thought this was dead code in an earlier commit in this branch. This commit restores the proper behavior.

2 files changed, 9 insertions(+), 7 deletions(-)

lib/std/http/Client.zig+5
......@@ -639,6 +639,11 @@ pub const Request = struct {
639639 _ => rb.* = @enumFromInt(@intFromEnum(rb.*) - 1),
640640 }
641641 }
642
643 pub fn remaining(rb: RedirectBehavior) u16 {
644 assert(rb != .unhandled);
645 return @intFromEnum(rb);
646 }
642647 };
643648
644649 /// Frees all resources associated with the request.
src/Package/Fetch/git.zig+4-7
......@@ -530,8 +530,9 @@ pub const Session = struct {
530530 info_refs_uri.query = "service=git-upload-pack";
531531 info_refs_uri.fragment = null;
532532
533 const max_redirects = 3;
533534 var request = try session.transport.open(.GET, info_refs_uri, .{
534 .redirect_behavior = @enumFromInt(3),
535 .redirect_behavior = @enumFromInt(max_redirects),
535536 .server_header_buffer = http_headers_buffer,
536537 .extra_headers = &.{
537538 .{ .name = "Git-Protocol", .value = "version=2" },
......@@ -543,12 +544,8 @@ pub const Session = struct {
543544
544545 try request.wait();
545546 if (request.response.status != .ok) return error.ProtocolError;
546 // Pretty sure this is dead code - in order for a redirect to occur, the status
547 // code would need to be in the 300s and then it would not be "OK" which is checked
548 // on the line above.
549 var runtime_false = false;
550 _ = &runtime_false;
551 if (runtime_false) {
547 const any_redirects_occurred = request.redirect_behavior.remaining() < max_redirects;
548 if (any_redirects_occurred) {
552549 if (!mem.endsWith(u8, request.uri.path, "/info/refs")) return error.UnparseableRedirect;
553550 var new_uri = request.uri;
554551 new_uri.path = new_uri.path[0 .. new_uri.path.len - "/info/refs".len];