async Task <Stream> ExecuteRequest(IConvertToHttpContent request, string apiPath, CancellationToken cancelToken = default, KeyValuePair <string, string> remoteUrlHeader = default)
        {
            using var formContent = new MultipartFormDataContent($"{Constants.Http.MultipartData.BoundaryPrefix}{DateTime.Now.Ticks}");

            foreach (var item in request.ToHttpContent())
            {
                formContent.Add(item);
            }

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, apiPath)
            {
                Content = formContent
            };

            if (remoteUrlHeader.Key.IsSet())
            {
                var name = $"{Constants.Gotenberg.CustomRemoteHeaders.RemoteUrlKeyPrefix}{remoteUrlHeader.Key.Trim()}";
                requestMessage.Headers.Add(name, remoteUrlHeader.Value);
            }

            var response = await this._innerClient
                           .SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, cancelToken)
                           .ConfigureAwait(false);

            cancelToken.ThrowIfCancellationRequested();

            return(await response.Content.ReadAsStreamAsync().ConfigureAwait(false));
        }
Exemple #2
0
 public static IEnumerable <HttpContent> IfNullEmptyContent(this IConvertToHttpContent converter)
 {
     return(converter?.ToHttpContent() ?? Enumerable.Empty <HttpContent>());
 }