private IOptionsMonitor <HttpLoggingOptions> CreateOptionsAccessor()
        {
            var options         = new HttpLoggingOptions();
            var optionsAccessor = Mock.Of <IOptionsMonitor <HttpLoggingOptions> >(o => o.CurrentValue == options);

            return(optionsAccessor);
        }
        public void CanClearMediaTypes()
        {
            var options = new HttpLoggingOptions();

            options.MediaTypeOptions.Clear();
            Assert.Empty(options.MediaTypeOptions.MediaTypeStates);
        }
        public void HeadersAreCaseInsensitive()
        {
            var options = new HttpLoggingOptions();

            options.RequestHeaders.Clear();
            options.RequestHeaders.Add("Test");
            options.RequestHeaders.Add("test");

            Assert.Single(options.RequestHeaders);
        }
        public void CanAddMediaTypesWithCharset()
        {
            var options = new HttpLoggingOptions();

            options.MediaTypeOptions.AddText("test/*; charset=ascii");

            var defaultMediaTypes = options.MediaTypeOptions.MediaTypeStates;

            Assert.Equal(6, defaultMediaTypes.Count);

            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.Encoding.WebName.Equals("us-ascii"));
        }
        public void CanAddMediaTypesString()
        {
            var options = new HttpLoggingOptions();

            options.MediaTypeOptions.AddText("test/*");

            var defaultMediaTypes = options.MediaTypeOptions.MediaTypeStates;

            Assert.Equal(6, defaultMediaTypes.Count);

            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.MediaType.Equals("test/*"));
        }
        public void DefaultsMediaTypes()
        {
            var options           = new HttpLoggingOptions();
            var defaultMediaTypes = options.MediaTypeOptions.MediaTypeStates;

            Assert.Equal(5, defaultMediaTypes.Count);

            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.MediaType.Equals("application/json"));
            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.MediaType.Equals("application/*+json"));
            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.MediaType.Equals("application/xml"));
            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.MediaType.Equals("application/*+xml"));
            Assert.Contains(defaultMediaTypes, w => w.MediaTypeHeaderValue.MediaType.Equals("text/*"));
        }
 internal ResponseBufferingStream(IHttpResponseBodyFeature innerBodyFeature,
                                  int limit,
                                  ILogger logger,
                                  HttpContext context,
                                  List <MediaTypeState> encodings,
                                  HttpLoggingOptions options)
     : base(innerBodyFeature.Stream, logger)
 {
     _innerBodyFeature = innerBodyFeature;
     _innerStream      = innerBodyFeature.Stream;
     _limit            = limit;
     _context          = context;
     _encodings        = encodings;
     _options          = options;
 }
        public static void LogResponseHeaders(HttpResponse response, HttpLoggingOptions options, ILogger logger)
        {
            var list = new List <KeyValuePair <string, object?> >(
                response.Headers.Count + DefaultResponseFieldsMinusHeaders);

            if (options.LoggingFields.HasFlag(HttpLoggingFields.ResponseStatusCode))
            {
                list.Add(new KeyValuePair <string, object?>(nameof(response.StatusCode), response.StatusCode));
            }

            if (options.LoggingFields.HasFlag(HttpLoggingFields.ResponseHeaders))
            {
                FilterHeaders(list, response.Headers, options._internalResponseHeaders);
            }

            var httpResponseLog = new HttpResponseLog(list);

            logger.ResponseLog(httpResponseLog);
        }