Example #1
0
 public void select_first_when_one_does_match()
 {
     var currentMimeType = new CurrentMimeType("application/x-www-form-urlencoded; charset=UTF-8", "text/html, application/json, */*");
     currentMimeType
         .SelectFirstMatching(new[] { "text/json", "application/json" })
         .ShouldEqual("application/json");
 }
Example #2
0
 public void InterpretQuerystring(CurrentMimeType mimeType, IHttpRequest request)
 {
     var corrected = QuerystringParameters.FirstValue(x => x.Determine(request.QueryString));
     if (corrected.IsNotEmpty())
     {
         mimeType.AcceptTypes = new MimeTypeList(corrected);
     }
 }
        public object Bind(Type type, IBindingContext context)
        {
            var contentType = context.Data.ValueAs<string>("Content-Type");
            var acceptType = context.Data.ValueAs<string>("Accept");
            var currentMimeType = new CurrentMimeType(contentType, acceptType);

            return currentMimeType;
        }
Example #4
0
        public void InterpretQuerystring(CurrentMimeType mimeType, IHttpRequest request)
        {
            var corrected = QuerystringParameters.FirstValue(x => x.Determine(request.QueryString));

            if (corrected.IsNotEmpty())
            {
                mimeType.AcceptTypes = new MimeTypeList(corrected);
            }
        }
        public void no_correction_with_no_querystring()
        {
            var request = OwinHttpRequest.ForTesting();
            var mimeType = new CurrentMimeType("text/json", theOriginalMimetype);

            new ConnegSettings().InterpretQuerystring(mimeType, request);

            mimeType.AcceptTypes.Single().ShouldEqual(theOriginalMimetype);
        }
Example #6
0
        public object Bind(Type type, IBindingContext context)
        {
            var contentType     = context.Data.ValueAs <string>("Content-Type");
            var acceptType      = context.Data.ValueAs <string>("Accept");
            var currentMimeType = new CurrentMimeType(contentType, acceptType);


            return(currentMimeType);
        }
Example #7
0
        public void get_the_description_if_the_reader_is_null()
        {
            var mimeType = new CurrentMimeType("text/json", null);

            var choice = new ReaderChoice(mimeType, null);

            var description = Description.For(choice);

            description.Title.ShouldEqual("Unable to select a reader for content-type 'text/json'");
        }
Example #8
0
        public void get_the_description_if_the_reader_is_not_null()
        {
            var mimeType = new CurrentMimeType("text/json", null);

            var choice = new ReaderChoice(mimeType, new ClassWithTitle());

            var description = Description.For(choice);

            description.Title.ShouldEqual("Selected reader 'Some title' for content-type 'text/json'");
        }
        public void correct_to_xml()
        {
            var request = OwinHttpRequest.ForTesting();
            request.QueryString["Format"] = "XML";

            var mimeType = new CurrentMimeType("text/json", theOriginalMimetype);

            new ConnegSettings().InterpretQuerystring(mimeType, request);

            mimeType.AcceptTypes.Single().ShouldEqual(MimeType.Xml.Value);
        }
        public object Bind(Type type, IBindingContext context)
        {
            var request = context.Service<ICurrentHttpRequest>();

            var contentType = request.GetHeader(HttpRequestHeader.ContentType).FirstOrDefault() ??
                              MimeType.HttpFormMimetype;

            var acceptType = ReadAcceptType(request.GetHeader(HttpRequestHeader.Accept));

            var currentMimeType = new CurrentMimeType(contentType, acceptType);

            return currentMimeType;
        }
        public object Bind(Type type, IBindingContext context)
        {
            var mimetypeContext = context.Service<MimetypeContext>();


            var contentType = mimetypeContext.ContentType;
            var acceptType = mimetypeContext.Accepts;
            
            

            var currentMimeType = new CurrentMimeType(contentType, acceptType);
            mimetypeContext.Correct(currentMimeType);

            return currentMimeType;
        }
        public object Bind(Type type, IBindingContext context)
        {
            var request = context.Service <ICurrentHttpRequest>();

            var contentType = request.GetHeader(HttpRequestHeader.ContentType).FirstOrDefault() ??
                              MimeType.HttpFormMimetype;

            var acceptType = ReadAcceptType(request.GetHeader(HttpRequestHeader.Accept));



            var currentMimeType = new CurrentMimeType(contentType, acceptType);


            return(currentMimeType);
        }
Example #13
0
        public object Bind(Type type, IBindingContext context)
        {
            var mimetypeContext = context.Service <MimetypeContext>();


            var contentType = mimetypeContext.ContentType;
            var acceptType  = mimetypeContext.Accepts;



            var currentMimeType = new CurrentMimeType(contentType, acceptType);

            mimetypeContext.Correct(currentMimeType);

            return(currentMimeType);
        }
        public object Bind(Type type, IBindingContext context)
        {
            var contentType = context.ValueAs<string>("Content-Type");
            var acceptType = context.ValueAs<string>("Accept");
            var currentMimeType = new CurrentMimeType(contentType, acceptType);

            // Life just doesn't get to be simple.  What if a jquery plugin, just pulling an example out of
            // very thick air, posts json, but with an incorrect mimetype?
            if (currentMimeType.ContentType == MimeType.HttpFormMimetype && context.IsAjaxRequest())
            {
                var streamingData = context.Service<IStreamingData>();
                if (streamingData.CouldBeJson())
                {
                    currentMimeType.ContentType = MimeType.Json.Value;
                }
            }

            return currentMimeType;
        }
Example #15
0
        public object Bind(Type type, IBindingContext context)
        {
            var contentType     = context.ValueAs <string>("Content-Type");
            var acceptType      = context.ValueAs <string>("Accept");
            var currentMimeType = new CurrentMimeType(contentType, acceptType);

            // Life just doesn't get to be simple.  What if a jquery plugin, just pulling an example out of
            // very thick air, posts json, but with an incorrect mimetype?
            if (currentMimeType.ContentType == MimeType.HttpFormMimetype && context.IsAjaxRequest())
            {
                var streamingData = context.Service <IStreamingData>();
                if (streamingData.CouldBeJson())
                {
                    currentMimeType.ContentType = MimeType.Json.Value;
                }
            }


            return(currentMimeType);
        }
Example #16
0
            public void Correct(CurrentMimeType currentMimeType)
            {
                _settings.InterpretQuerystring(currentMimeType, _request);

                _settings.Corrections.Each(x => x.Correct(currentMimeType, _request, _currentChain.OriginatingChain));
            }
            public void Correct(CurrentMimeType currentMimeType)
            {
                _settings.InterpretQuerystring(currentMimeType, _request);

                _settings.Corrections.Each(x => x.Correct(currentMimeType, _request, _currentChain.OriginatingChain));
            }
        public void use_a_custom_querystring_parameter()
        {
            var request = OwinHttpRequest.ForTesting();
            request.QueryString["Format"] = "Text";

            var settings = new ConnegSettings();
            settings.QuerystringParameters.Add(new ConnegQuerystring("Format", "Text", MimeType.Text));

            var mimeType = new CurrentMimeType("text/json", theOriginalMimetype);

            settings.InterpretQuerystring(mimeType, request);

            mimeType.AcceptTypes.Single().ShouldEqual(MimeType.Text.Value);
        }
 public void is_smart_enough_to_pull_out_charset()
 {
     var currentMimeType = new CurrentMimeType("application/x-www-form-urlencoded; charset=UTF-8", null);
     currentMimeType.ContentType.ShouldEqual("application/x-www-form-urlencoded");
     currentMimeType.Charset.ShouldEqual("UTF-8");
 }
 public void feeding_in_null_for_contentType_defaults_to_HttpFormMimeType()
 {
     var currentMimeType = new CurrentMimeType(null, null);
     currentMimeType.ContentType.ShouldEqual(MimeType.HttpFormMimetype);
 }
 public void accepts_html_negative()
 {
     var currentMimeType = new CurrentMimeType("application/x-www-form-urlencoded; charset=UTF-8", null);
     currentMimeType.AcceptsHtml().ShouldBeFalse();
 }
Example #22
0
 public NoMatchingWriter(CurrentMimeType mimeType)
 {
     _mimeType = mimeType;
 }
 public void Correct(CurrentMimeType mimeType, IHttpRequest request, BehaviorChain chain)
 {
     mimeType.AcceptTypes = new MimeTypeList(MimeType.Json);
 }
        public void select_first_with_a_wild_card()
        {
            var currentMimeType = new CurrentMimeType("application/x-www-form-urlencoded; charset=UTF-8", "text/html, */*");
            currentMimeType
                .SelectFirstMatching(new[]{"text/json", "application/json"})
                .ShouldBe("text/json");

            currentMimeType
                .SelectFirstMatching(new[] { "application/json", "text/json" })
                .ShouldBe("application/json");
        }