示例#1
0
        /// <summary>
        ///     Use the <see cref="GanymedeRequestResource" /> object to set the necessary attribute values.
        /// </summary>
        /// <returns></returns>
        public HeaderStage UseGanymedeEndpointOptions()
        {
            if (PipelineContext.Resource.ResourceHeaders.Count <= 0)
            {
                return(this);
            }

            foreach (GanymedeRequestHeader headerOptions in PipelineContext.Resource.ResourceHeaders)
            {
                IHeaderBuilderCommand headerCommand = CommandTypeRegistry.Instance.TryGetCommandType(headerOptions.Name.Trim().ToUpperInvariant());
                headerCommand?.Execute(_headerBuilder, headerOptions.KeyOrQuality, headerOptions.Value);
            }

            return(this);
        }
        public static void SetDefaultRequestHeaders(this HttpClient httpClient, IEnumerable <GanymedeRequestHeader> headerOptions)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }

            IEnumerable <GanymedeRequestHeader> options = headerOptions as GanymedeRequestHeader[] ?? headerOptions.ToArray();

            if (!options.Any())
            {
                return;
            }

            var headerBuilder = new HttpClientHeaderCommandBuilder(httpClient);

            foreach (GanymedeRequestHeader header in options)
            {
                IHeaderBuilderCommand headerCommand = CommandTypeRegistry.Instance.TryGetCommandType(header.Name.Trim().ToUpperInvariant());
                headerCommand?.Execute(headerBuilder, header.KeyOrQuality, header.Value);
            }
        }