/// <inheritdoc cref="IOwinRequestMapper.MapAsync"/>
        public async Task <RequestMessage> MapAsync(IRequest request, IWireMockMiddlewareOptions options)
        {
            (UrlDetails urldetails, string clientIP) = ParseRequest(request);

            string method = request.Method;

            Dictionary <string, string[]> headers = null;
            IEnumerable <string>          contentEncodingHeader = null;

            if (request.Headers.Any())
            {
                headers = new Dictionary <string, string[]>();
                foreach (var header in request.Headers)
                {
                    headers.Add(header.Key, header.Value);

                    if (string.Equals(header.Key, HttpKnownHeaderNames.ContentEncoding, StringComparison.OrdinalIgnoreCase))
                    {
                        contentEncodingHeader = header.Value;
                    }
                }
            }

            IDictionary <string, string> cookies = null;

            if (request.Cookies.Any())
            {
                cookies = new Dictionary <string, string>();
                foreach (var cookie in request.Cookies)
                {
                    cookies.Add(cookie.Key, cookie.Value);
                }
            }

            BodyData body = null;

            if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
            {
                var bodyParserSettings = new BodyParserSettings
                {
                    Stream                   = request.Body,
                    ContentType              = request.ContentType,
                    DeserializeJson          = !options.DisableJsonBodyParsing.GetValueOrDefault(false),
                    ContentEncoding          = contentEncodingHeader?.FirstOrDefault(),
                    DecompressGZipAndDeflate = !options.DisableRequestBodyDecompressing.GetValueOrDefault(false)
                };

                body = await BodyParser.Parse(bodyParserSettings);
            }

            return(new RequestMessage(urldetails, method, clientIP, body, headers, cookies)
            {
                DateTime = DateTime.UtcNow
            });
        }
        /// <inheritdoc cref="IOwinRequestMapper.MapAsync"/>
        public async Task <RequestMessage> MapAsync(IRequest request, IWireMockMiddlewareOptions options)
        {
            (UrlDetails urldetails, string clientIP) = ParseRequest(request);

            string method = request.Method;

            Dictionary <string, string[]> headers = null;

            if (request.Headers.Any())
            {
                headers = new Dictionary <string, string[]>();
                foreach (var header in request.Headers)
                {
                    headers.Add(header.Key, header.Value);
                }
            }

            IDictionary <string, string> cookies = null;

            if (request.Cookies.Any())
            {
                cookies = new Dictionary <string, string>();
                foreach (var cookie in request.Cookies)
                {
                    cookies.Add(cookie.Key, cookie.Value);
                }
            }

            BodyData body = null;

            if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
            {
                body = await BodyParser.Parse(request.Body, request.ContentType, !options.DisableJsonBodyParsing.GetValueOrDefault(false));
            }

            return(new RequestMessage(urldetails, method, clientIP, body, headers, cookies)
            {
                DateTime = DateTime.UtcNow
            });
        }
Beispiel #3
0
        /// <inheritdoc cref="IOwinRequestMapper.MapAsync"/>
        public async Task <RequestMessage> MapAsync(IRequest request)
        {
            (UrlDetails urldetails, string clientIP) = ParseRequest(request);

            string method = request.Method;

            Dictionary <string, string[]> headers = null;

            if (request.Headers.Any())
            {
                headers = new Dictionary <string, string[]>();
                foreach (var header in request.Headers)
                {
                    headers.Add(header.Key, header.Value);
                }
            }

            IDictionary <string, string> cookies = null;

            if (request.Cookies.Any())
            {
                cookies = new Dictionary <string, string>();
                foreach (var cookie in request.Cookies)
                {
                    cookies.Add(cookie.Key, cookie.Value);
                }
            }

            BodyData body = null;

            if (request.Body != null && BodyParser.ShouldParseBody(method))
            {
                body = await BodyParser.Parse(request.Body, request.ContentType);
            }

            return(new RequestMessage(urldetails, method, clientIP, body, headers, cookies)
            {
                DateTime = DateTime.UtcNow
            });
        }
Beispiel #4
0
 public void BodyParser_ShouldParseBody_DefaultIsTrueForUnknownMethods(string method)
 {
     Check.That(BodyParser.ShouldParseBody(method, false)).IsTrue();
 }
Beispiel #5
0
 public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsTrue_ExpectedResultShouldBeTrue(string method)
 {
     Check.That(BodyParser.ShouldParseBody(method, true)).IsTrue();
 }
Beispiel #6
0
 public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsFalse_ExpectedResultForKnownMethods(string method, bool resultShouldBe)
 {
     Check.That(BodyParser.ShouldParseBody(method, false)).Equals(resultShouldBe);
 }
Beispiel #7
0
 public void BodyParser_ShouldParseBody_ExpectedResultForKnownMethods(string method, bool resultShouldBe)
 {
     Check.That(BodyParser.ShouldParseBody(method)).Equals(resultShouldBe);
 }