Beispiel #1
0
        public override async ValueTask ProcessAsync(HttpMessage message)
        {
            // Some tests will check if the Request Content is being read (to
            // verify their Progress handling) so we'll just copy it to a
            // MemoryStream asynchronously
            if (message.Request.Content != null &&
                message.Request.Content.TryComputeLength(out long length))
            {
                // Set a Content-Length header if TryComputeLength succeeds.
                message.Request.Headers.SetValue("Content-Length", length.ToString());

                if (length > 0)
                {
                    using (MemoryStream stream = new MemoryStream((int)length))
                    {
                        await message.Request.Content.WriteToAsync(stream, message.CancellationToken).ConfigureAwait(false);
                    }
                }
            }

            var requestEntry = RecordTransport.CreateEntry(message.Request, null);

            if (_skipRequestBodyFilter(requestEntry))
            {
                requestEntry.Request.Body = null;
            }

            message.Response = GetResponse(_session.Lookup(requestEntry, _matcher, _sanitizer));

            // Copy the ClientRequestId like the HTTP transport.
            message.Response.ClientRequestId = message.Request.ClientRequestId;
        }
        public override void Process(HttpMessage message)
        {
            // Some tests will check if the Request Content is being read (to
            // verify their Progress handling) so we'll just copy it to a
            // MemoryStream
            if (message.Request.Content != null &&
                message.Request.Content.TryComputeLength(out long length) &&
                length > 0)
            {
                using (MemoryStream stream = new MemoryStream((int)length))
                {
                    message.Request.Content.WriteTo(stream, message.CancellationToken);
                }
            }

            var requestEntry = RecordTransport.CreateEntry(message.Request, null);

            if (_skipRequestBodyFilter(requestEntry))
            {
                requestEntry.Request.Body = null;
            }

            message.Response = GetResponse(_session.Lookup(requestEntry, _matcher, _sanitizer));

            // Copy the ClientRequestId like the HTTP transport.
            message.Response.ClientRequestId = message.Request.ClientRequestId;
        }
Beispiel #3
0
        public RecordEntry Lookup(Request request, RecordMatcher matcher, RecordedTestSanitizer sanitizer)
        {
            var requestEntry = RecordTransport.CreateEntry(request, null);

            sanitizer.Sanitize(requestEntry);

            lock (Entries)
            {
                RecordEntry entry = matcher.FindMatch(requestEntry, Entries);
                Entries.Remove(entry);
                return(entry);
            }
        }