aboutsummaryrefslogtreecommitdiff
path: root/src/Package/Fetch/git.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-02-11 17:17:09 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-02-23 02:37:10 -0700
commit90bd4f226e2ba03634d31c73df06bf0a90fa0231 (patch)
tree0a5cc52fa31ac0e0d9f8f40bce9534c67c4bd89c /src/Package/Fetch/git.zig
parentf1cf300c8fa9842ec9c812310bdc9f3aeeb75359 (diff)
downloadzig-90bd4f226e2ba03634d31c73df06bf0a90fa0231.tar.gz
zig-90bd4f226e2ba03634d31c73df06bf0a90fa0231.zip
std.http: remove the ability to heap-allocate headers
The buffer for HTTP headers is now always provided via a static buffer. As a consequence, OutOfMemory is no longer a member of the read() error set, and the API and implementation of Client and Server are simplified. error.HttpHeadersExceededSizeLimit is renamed to error.HttpHeadersOversize.
Diffstat (limited to 'src/Package/Fetch/git.zig')
-rw-r--r--src/Package/Fetch/git.zig15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Package/Fetch/git.zig b/src/Package/Fetch/git.zig
index ee8f1ba543..b6c47eabc7 100644
--- a/src/Package/Fetch/git.zig
+++ b/src/Package/Fetch/git.zig
@@ -494,8 +494,9 @@ pub const Session = struct {
session: *Session,
allocator: Allocator,
redirect_uri: *[]u8,
+ http_headers_buffer: []u8,
) !void {
- var capability_iterator = try session.getCapabilities(allocator, redirect_uri);
+ var capability_iterator = try session.getCapabilities(allocator, redirect_uri, http_headers_buffer);
defer capability_iterator.deinit();
while (try capability_iterator.next()) |capability| {
if (mem.eql(u8, capability.key, "agent")) {
@@ -521,6 +522,7 @@ pub const Session = struct {
session: Session,
allocator: Allocator,
redirect_uri: *[]u8,
+ http_headers_buffer: []u8,
) !CapabilityIterator {
var info_refs_uri = session.uri;
info_refs_uri.path = try std.fs.path.resolvePosix(allocator, &.{ "/", session.uri.path, "info/refs" });
@@ -534,6 +536,7 @@ pub const Session = struct {
var request = try session.transport.open(.GET, info_refs_uri, headers, .{
.max_redirects = 3,
+ .server_header_buffer = http_headers_buffer,
});
errdefer request.deinit();
try request.send(.{});
@@ -620,6 +623,7 @@ pub const Session = struct {
include_symrefs: bool = false,
/// Whether to include the peeled object ID for returned tag refs.
include_peeled: bool = false,
+ server_header_buffer: []u8,
};
/// Returns an iterator over refs known to the server.
@@ -658,6 +662,7 @@ pub const Session = struct {
var request = try session.transport.open(.POST, upload_pack_uri, headers, .{
.handle_redirects = false,
+ .server_header_buffer = options.server_header_buffer,
});
errdefer request.deinit();
request.transfer_encoding = .{ .content_length = body.items.len };
@@ -721,7 +726,12 @@ pub const Session = struct {
/// Fetches the given refs from the server. A shallow fetch (depth 1) is
/// performed if the server supports it.
- pub fn fetch(session: Session, allocator: Allocator, wants: []const []const u8) !FetchStream {
+ pub fn fetch(
+ session: Session,
+ allocator: Allocator,
+ wants: []const []const u8,
+ http_headers_buffer: []u8,
+ ) !FetchStream {
var upload_pack_uri = session.uri;
upload_pack_uri.path = try std.fs.path.resolvePosix(allocator, &.{ "/", session.uri.path, "git-upload-pack" });
defer allocator.free(upload_pack_uri.path);
@@ -758,6 +768,7 @@ pub const Session = struct {
var request = try session.transport.open(.POST, upload_pack_uri, headers, .{
.handle_redirects = false,
+ .server_header_buffer = http_headers_buffer,
});
errdefer request.deinit();
request.transfer_encoding = .{ .content_length = body.items.len };