Last active
March 11, 2023 18:04
-
-
Save musaprg/b73aa918816989db7c15b7b75d214ca4 to your computer and use it in GitHub Desktop.
Revisions
-
musaprg revised this gist
Mar 11, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,7 @@ pub fn main() anyerror!void { const uri = try Uri.parse("http://example.com"); debug.print("parsed schema: {s}\n", .{uri.scheme}); debug.print("parsed path: {s}\n", .{uri.path}); debug.print("parsed host: {s}\n", .{uri.host orelse ""}); var req = try client.request(uri, .{}, .{}); var buf_reader = std.io.bufferedReader(req.reader()); -
musaprg created this gist
Mar 5, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ const std = @import("std"); const heap = std.heap; const http = std.http; const Uri = std.Uri; const debug = std.debug; pub fn main() anyerror!void { var arena = heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); const allocator = arena.allocator(); var client: http.Client = .{.allocator = allocator}; defer client.deinit(); const uri = try Uri.parse("http://example.com"); debug.print("parsed schema: {s}\n", .{uri.scheme}); debug.print("parsed host: {s}\n", .{uri.host orelse ""}); var req = try client.request(uri, .{}, .{}); var buf_reader = std.io.bufferedReader(req.reader()); var in_stream = buf_reader.reader(); var buf: [1024]u8 = undefined; while (try in_stream.readUntilDelimiterOrEof(&buf, '\n')) |line| { debug.print("{s}\n", .{line}); } debug.print("Method: {s}\n", .{@tagName(req.headers.method)}); debug.print("Status code: {s}\n", .{@tagName(req.response.headers.status)}); debug.print("Version: {s}\n", .{@tagName(req.response.headers.version)}); }