Skip to content

Commit 1a23d31

Browse files
bradcypertjiacai2050Copilot
authored
Add support for selecting HTTP version (#38)
Hey, thanks for the helpful library! I am working on [httpspec](https://github.com/bradcypert/httpspec) and I needed to be able to set the HTTP version on the curl library. I couldnt find an easy way to do that without modifying the library, so I went ahead and did that (and here's a patch to support it!). --------- Co-authored-by: Jiacai Liu <dev@liujiacai.net> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent df369a2 commit 1a23d31

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/Easy.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ timeout_ms: usize,
2020
user_agent: [:0]const u8,
2121
ca_bundle: ?ResizableBuffer,
2222

23+
pub const HttpVersion = enum(c_long) {
24+
none = c.CURL_HTTP_VERSION_NONE,
25+
http1_0 = c.CURL_HTTP_VERSION_1_0,
26+
http1_1 = c.CURL_HTTP_VERSION_1_1,
27+
http2 = c.CURL_HTTP_VERSION_2_0,
28+
http2_tls = c.CURL_HTTP_VERSION_2TLS,
29+
http2_prior_knowledge = c.CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE,
30+
http3 = c.CURL_HTTP_VERSION_3,
31+
http3_only = c.CURL_HTTP_VERSION_3ONLY,
32+
};
33+
2334
pub const Method = enum {
2435
GET,
2536
POST,
@@ -319,6 +330,14 @@ pub fn setUpload(self: Self, up: *Upload) !void {
319330
try checkCode(c.curl_easy_setopt(self.handle, c.CURLOPT_READDATA, up));
320331
}
321332

333+
pub fn setHttpVersion(self: Self, version: HttpVersion) !void {
334+
try checkCode(c.curl_easy_setopt(
335+
self.handle,
336+
c.CURLOPT_HTTP_VERSION,
337+
@intFromEnum(version),
338+
));
339+
}
340+
322341
pub fn setFollowLocation(self: Self, enable: bool) !void {
323342
const param: c_long = @intCast(@intFromBool(enable));
324343
try checkCode(c.curl_easy_setopt(self.handle, c.CURLOPT_FOLLOWLOCATION, param));

0 commit comments

Comments
 (0)