예제 #1
0
        /// <inheritdoc/>
        public bool IsValidRequest(HttpContext context)
        {
            if (_formatUtilities.GetExtensionFromUri(context.Request.GetDisplayUrl()) == null)
            {
                return(false);
            }

            if (!context.Request.Query.ContainsKey(ResizeWebProcessor.Width) &&
                !context.Request.Query.ContainsKey(ResizeWebProcessor.Height))
            {
                return(false);
            }

            if (context.Request.Query.TryGetValue(ResizeWebProcessor.Width, out var widthString))
            {
                var width = CommandParser.Instance.ParseValue <int>(widthString);

                if (Array.BinarySearch <int>(_supportedSizes, width) < 0)
                {
                    return(false);
                }
            }

            if (context.Request.Query.TryGetValue(ResizeWebProcessor.Height, out var heightString))
            {
                var height = CommandParser.Instance.ParseValue <int>(heightString);

                if (Array.BinarySearch <int>(_supportedSizes, height) < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
        public void GetExtensionShouldMatchDefaultExtensions(string expected, string ext)
        {
            string uri = $"http://www.example.org/some/path/to/image.{ext}?width=300";

            Assert.Equal(expected, formatUtilities.GetExtensionFromUri(uri));
        }
예제 #3
0
 /// <inheritdoc/>
 public bool IsValidRequest(HttpContext context) => _formatUtilities.GetExtensionFromUri(context.Request.GetDisplayUrl()) != null;