private HttpRequestMessage AspNetRequest(IDictionary <string, string> request)
        {
            var headers       = new Headers.Of(request);
            var aspnetRequest =
                new HttpRequestMessage(
                    methods[new Method.Of(request).AsString()],
                    new Address.Of(request).Value()
                    );

            foreach (var head in headers)
            {
                aspnetRequest.Headers.TryAddWithoutValidation(head.Key(), head.Value());
            }
            var content = Content(request);

            if (!IsEmpty(content))
            {
                aspnetRequest.Content = content;
                foreach (var head in headers)
                {
                    IEnumerable <string> tryValues = new List <string>();
                    if (
                        !aspnetRequest.Content.Headers.TryGetValues(head.Key(), out tryValues) ||
                        !new Contains <string>(tryValues, head.Value()).Value()
                        )
                    {
                        aspnetRequest.Content.Headers.TryAddWithoutValidation(head.Key(), head.Value());
                    }
                }
            }
            return(aspnetRequest);
        }
Esempio n. 2
0
        /// <summary>
        /// Headers are numbered to allow multiple values for the same key.
        /// Those numbers may differ between template and request,
        /// so headers can not be compared as raw request parts.
        /// </summary>
        private bool HasTemplateHeaders(IDictionary <string, string> request)
        {
            var templateHeaders = new Headers.Of(this.template);
            var requestHeaders  = new Headers.Of(request);
            var applies         = true;

            foreach (var templateHeader in templateHeaders)
            {
                var matches =
                    new Yaapii.Atoms.Enumerable.Filtered <IKvp>(kvp =>
                                                                kvp.Key() == templateHeader.Key() && kvp.Value() == templateHeader.Value(),
                                                                requestHeaders
                                                                );
                if (new Yaapii.Atoms.Enumerable.LengthOf(matches).Value() == 0)
                {
                    applies = false;
                    break;
                }
            }
            return(applies);
        }