コード例 #1
0
        /// <summary>
        /// Inspects the <see cref="RequestBase"/> and fill the <see cref="HttpHeaderCollection"/> with applicable headers.
        /// </summary>
        /// <param name="request">The <see cref="RequestBase"/>.</param>
        /// <param name="collectedHttpHeaders">The <see cref="HttpHeaderCollection"/> to fill with headers.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="request"/>' and '<paramref name="collectedHttpHeaders"/>' cannot be null. </exception>
        public void CollectRequestHeaders(RequestBase request, HttpHeaderCollection collectedHttpHeaders)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (collectedHttpHeaders == null)
            {
                throw new ArgumentNullException(nameof(collectedHttpHeaders));
            }

            var members = request.GetType().GetMembers(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public).Where(property => property.HasAttributeExactly <MapHeaderAttribute>());

            foreach (var memberInfo in members)
            {
                var mapHeaderAttribute = memberInfo.GetAttribute <MapHeaderAttribute>();
                var memberValue        = memberInfo.GetValue(request);
                if (memberValue == null)
                {
                    continue;
                }

                // ReSharper disable once AssignNullToNotNullAttribute Attribute is defined cause of filter in LINQ expression.
                var headerName = GetHeaderName(memberInfo, mapHeaderAttribute);
                var httpHeader = new HttpHeader(headerName, (string)memberValue);
                collectedHttpHeaders.Add(httpHeader);
            }
        }
コード例 #2
0
        /// <summary>
        /// Inspects the <see cref="RequestBase"/> and creates a <see cref="HttpHeaderCollection"/> with applicable headers.
        /// </summary>
        /// <param name="request">The <see cref="RequestBase"/>.</param>
        /// <param name="collectedHttpHeaders"></param>
        /// <returns>A new instance of the <see cref="HttpHeaderCollection"/> class.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="request"/>' and '<paramref name="collectedHttpHeaders"/>' cannot be null. </exception>
        public void CollectRequestHeaders(RequestBase request, HttpHeaderCollection collectedHttpHeaders)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (collectedHttpHeaders == null)
            {
                throw new ArgumentNullException(nameof(collectedHttpHeaders));
            }

            foreach (var requestHeader in request.HttpHeaders)
            {
                collectedHttpHeaders.Add(requestHeader);
            }
        }
コード例 #3
0
        public static HttpHeaderCollection FromHttpResponseMessage([NotNull] HttpResponseMessage httpResponseMessage)
        {
            if (httpResponseMessage == null)
            {
                throw new ArgumentNullException(nameof(httpResponseMessage));
            }

            var result = new HttpHeaderCollection();

            foreach (var httpResponseHeader in httpResponseMessage.Headers)
            {
                var httpHeader = new HttpHeader(httpResponseHeader.Key, String.Join(" ", httpResponseHeader.Value));
                result.Add(httpHeader);
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Inspects the <see cref="RequestBase"/> and creates a <see cref="HttpHeaderCollection"/> with applicable headers.
        /// </summary>
        /// <param name="request">The <see cref="RequestBase"/>.</param>
        /// <param name="collectedHttpHeaders"></param>
        /// <returns>A new instance of the <see cref="HttpHeaderCollection"/> class.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="request"/>' and '<paramref name="collectedHttpHeaders"/>' cannot be null. </exception>
        public void CollectRequestHeaders(RequestBase request, HttpHeaderCollection collectedHttpHeaders)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (collectedHttpHeaders == null)
            {
                throw new ArgumentNullException(nameof(collectedHttpHeaders));
            }

            foreach (var requestHeader in request.GetType().GetAttributesExactly <FixedRequestHeaderAttribute>().Select(fixedRequestHeaderAttribute => fixedRequestHeaderAttribute.ToHttpHeader()))
            {
                collectedHttpHeaders.Add(requestHeader);
            }
        }