blob: 197cf9d695e1fb754a67ca3abdad0076079da2b3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
const Client = std.http.Client;
const Headers = std.http.Headers;
const Reader = Request.Reader;
const Request = Client.Request;
const Uri = std.Uri;
pub fn get(parent_allocator: Allocator, uri: Uri) ![]u8 {
var arena = ArenaAllocator.init(parent_allocator);
defer arena.deinit();
const allocator = arena.allocator();
var client = Client{
.allocator = allocator,
};
defer client.deinit();
var headers = Headers.init(allocator);
defer headers.deinit();
var request = try client.request(.GET, uri, headers, .{});
defer request.deinit();
try request.start();
try request.wait();
return request.reader().readAllAlloc(parent_allocator, std.math.maxInt(usize));
}
|