Example #1
0
        public async ValueTask <HttpResponseLog> Handle(HttpResponse response, CancellationToken cancellationToken = default)
        {
            if (response == null)
            {
                throw new NullReferenceException();
            }

            var logMessage = _logMessageFactory.Create(response);

            var context = _httpContextAccessor.HttpContext;

            var bodyWrapper = context.Features.Get <HttpResponseBodyWrapper>();

            var reader = new HttpMessageLogBodyReader(_options.Response.IgnoreContentTypes);

            var body = await reader.ReadAsync(bodyWrapper.Body, response.ContentType, response.ContentLength);

            logMessage.SetBody(body);

            return(logMessage);
        }
        public async ValueTask <HttpRequestLog> Handle(HttpRequest request, CancellationToken cancellationToken = default)
        {
            if (request == null)
            {
                throw new NullReferenceException(nameof(request));
            }

            var logMessage = _logMessageFactory.Create(request);

            if (request.HasFormContentType)
            {
                await _formContentHandler.Handle(request, logMessage, cancellationToken);
            }
            else
            {
                var reader = new HttpMessageLogBodyReader(_options.Request.IgnoreContentTypes);

                var body = await reader.ReadAsync(request.Body, request.ContentType, request.ContentLength, cancellationToken);

                logMessage.SetBody(body);
            }

            return(logMessage);
        }
Example #3
0
 private ValueTask <HttpRequestLog> CreateLogMessage(CancellationToken cancellationToken)
 {
     return(_logMessageFactory.Create <HttpRequestLog>(cancellationToken));
 }