using System; using FrostFS.SDK.Client.Mappers.GRPC; using FrostFS.SDK.Proto.Interfaces; using FrostFS.Session; namespace FrostFS.SDK.Client; public static class RequestConstructor { public static void AddMetaHeader(this IRequest request, string[] xHeaders, SessionToken? sessionToken = null) { if (request is null) throw new ArgumentNullException(nameof(request)); if (request.MetaHeader is not null) return; var metaHeader = MetaHeader.Default(); metaHeader.Ttl = 2; request.MetaHeader = metaHeader.ToMessage(); if (sessionToken != null) request.MetaHeader.SessionToken = sessionToken; if (xHeaders != null && xHeaders.Length > 0) { if (xHeaders.Length % 2 != 0) throw new ArgumentException("xHeaders with odd length"); for (var i = 0; i < xHeaders.Length; i += 2) { request.MetaHeader.XHeaders.Add(new XHeader { Key = xHeaders[i], Value = xHeaders[i + 1] }); } } } }