On redirect, ensure transfer owns the new url

This commit is contained in:
Karl Seguin
2026-06-03 12:05:09 +08:00
parent f61b110b1c
commit 97b1dae12a

View File

@@ -1790,6 +1790,7 @@ pub const Transfer = struct {
return writer.print("{s} {s}", .{ @tagName(req.method), req.url });
}
// `url` must have transfer-arena lifetime: it's stored as-is, not duped.
pub fn updateURL(self: *Transfer, url: [:0]const u8) !void {
self.req.url = url;
}
@@ -1829,7 +1830,9 @@ pub const Transfer = struct {
}
const base_url = try conn.getEffectiveUrl();
const resolved = try URL.resolve(arena, std.mem.span(base_url), location.value, .{});
// base_url and location.value are owned by curl. The returned value
// will be stored in transfer.req.url, hence the always_dupe.
const resolved = try URL.resolve(arena, std.mem.span(base_url), location.value, .{ .always_dupe = true });
// RFC 7231 §7.1.2: if the Location value has no fragment, the redirect
// inherits the fragment from the URI used to generate the request.