atproto pds in zig pds.zat.dev
pds atproto
24

Configure Feed

Select the types of activity you want to include in your feed.

reuse proxy upstream transport

zzstoatzz (Jun 3, 2026, 4:15 PM -0500) dca0c525 e588554c

+14 -3
+14 -3
src/atproto/proxy.zig
··· 8 8 const zat = @import("zat"); 9 9 10 10 const http = std.http; 11 + const proxy_transport_allocator = std.heap.smp_allocator; 12 + 13 + threadlocal var proxy_transport_ready = false; 14 + threadlocal var proxy_transport_state: zat.HttpTransport = undefined; 11 15 12 16 pub fn xrpcProxy(request: *http_api.Request) !void { 13 17 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); ··· 91 95 const service_token = try auth.createServiceJwtWithKeypair(allocator, account, service.did, method, null, &keypair); 92 96 const authorization = try std.fmt.allocPrint(allocator, "Bearer {s}", .{service_token}); 93 97 94 - var transport = zat.HttpTransport.init(store.currentIo(), allocator); 95 - defer transport.deinit(); 96 98 log.debug("xrpc proxy fetch method={s} upstream={s} extra_headers={d}\n", .{ method, upstream_url, extra_count }); 97 - const result = transport.fetch(.{ 99 + const result = proxyTransport().fetch(.{ 98 100 .url = upstream_url, 99 101 .method = http_api.toStdMethod(request.method), 100 102 .payload = payload, ··· 106 108 log.err("xrpc proxy fetch failed method={s} upstream={s} err={s}\n", .{ method, upstream_url, @errorName(err) }); 107 109 return http_api.xrpcError(request, .bad_gateway, "UpstreamFailure", "Failed to reach proxied service"); 108 110 }; 111 + defer proxy_transport_allocator.free(result.body); 109 112 log.debug("xrpc proxy upstream method={s} status={d} body_len={d}\n", .{ method, @intFromEnum(result.status), result.body.len }); 110 113 if (result.body.len == 0) return http_api.empty(request, result.status); 111 114 return http_api.json(request, result.status, result.body); 115 + } 116 + 117 + fn proxyTransport() *zat.HttpTransport { 118 + if (!proxy_transport_ready) { 119 + proxy_transport_state = zat.HttpTransport.init(store.currentIo(), proxy_transport_allocator); 120 + proxy_transport_ready = true; 121 + } 122 + return &proxy_transport_state; 112 123 } 113 124 114 125 pub fn shouldProxy(request: *const http_api.Request) bool {