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

            return(optionsAccessor);
        }
Пример #2
0
        public void CanClearMediaTypes()
        {
            var options = new HttpLoggingOptions();

            options.MediaTypeOptions.Clear();
            Assert.Empty(options.MediaTypeOptions.MediaTypeStates);
        }
Пример #3
0
        public void HeadersAreCaseInsensitive()
        {
            var options = new HttpLoggingOptions();

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

            Assert.Single(options.RequestHeaders);
        }
Пример #4
0
        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"));
        }
Пример #5
0
        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/*"));
        }
Пример #6
0
        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/*"));
        }
Пример #7
0
 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;
 }
Пример #8
0
        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);
        }