import 'dart:io'; import 'package:http/http.dart' as http; class AuthedClientInner extends http.BaseClient { final String _secret; final http.Client _inner; AuthedClientInner(this._secret, this._inner); @override Future send(http.BaseRequest request) { request.headers['X-ZT1-Auth'] = _secret; return _inner.send(request); } // @override // Future post(Uri url, // {Map? headers, Object? body, Encoding? encoding}) { // Map hd = headers ?? {}; // hd['content-type'] = 'application/json'; // return super.post(url, headers: hd, body: body, encoding: encoding); // } } class AuthedClient { late Future client; Future loadSecret() async { final results = await Process.run( 'su', ['-c', 'cat', '/data/adb/zerotier/home/authtoken.secret']); return AuthedClientInner(results.stdout.toString().trim(), http.Client()); } AuthedClient() { client = loadSecret(); } }