From b3df9d4bf91e4df6a643ab23c8ec44f239cd14b6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 5 May 2025 17:25:42 -0700 Subject: [PATCH] std.http.Client: sendBody flush by default; fix flushing flushing must also flush TLS client if it exists --- lib/std/http/Client.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 2658628bf9..2ff7ca4e73 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -820,7 +820,7 @@ pub const Request = struct { /// Sends and flushes a complete request as only HTTP head, no body. pub fn sendBodiless(r: *Request) std.io.Writer.Error!void { try sendBodilessUnflushed(r); - try r.connection.?.writer.flush(); + try r.connection.?.flush(); } /// Sends but does not flush a complete request as only HTTP head, no body. @@ -830,9 +830,22 @@ pub const Request = struct { try sendHead(r); } + /// Transfers the HTTP head over the connection and flushes. + /// + /// See also: + /// * `sendBodyUnflushed` + pub fn sendBody(r: *Request) std.io.Writer.Error!http.BodyWriter { + const result = try sendBodyUnflushed(r); + try r.connection.?.flush(); + return result; + } + /// Transfers the HTTP head over the connection, which is not flushed until /// `BodyWriter.flush` or `BodyWriter.end` is called. - pub fn sendBody(r: *Request) std.io.Writer.Error!http.BodyWriter { + /// + /// See also: + /// * `sendBody` + pub fn sendBodyUnflushed(r: *Request) std.io.Writer.Error!http.BodyWriter { assert(r.method.requestHasBody()); try sendHead(r); return .{