Ejemplo n.º 1
0
        protected void RespondTo(Action <ResponseFormat> collectFormats)
        {
            MimeTypes registeredMimes = new MimeTypes();

            registeredMimes.RegisterBuiltinTypes();

            ResponseHandler handler = new ResponseHandler();

            handler.ControllerBridge = new ControllerBridge(this, _controllerAction);
            handler.AcceptedMimes    = AcceptType.Parse(Request.Headers["Accept"], registeredMimes);
            handler.Format           = new ResponseFormat();

            collectFormats(handler.Format);
            handler.Respond();
        }
Ejemplo n.º 2
0
        private MimeType[] GetAcceptedTypes(MimeTypes registeredMimes)
        {
            var mimeTypes   = new List <MimeType>();
            var originalUrl = Request.Uri.GetLeftPart(UriPartial.Authority) + Request.Url;
            var lastSegment = new Uri(originalUrl).Segments.Last();

            if (lastSegment.Contains(".") && (lastSegment.LastIndexOf(".") < lastSegment.Length - 1))
            {
                var extension = lastSegment.Substring(lastSegment.LastIndexOf(".") + 1);
                var mimeType  = registeredMimes.GetMimeTypeForExtension(extension);

                if (mimeType != null)
                {
                    mimeTypes.Add(mimeType);
                }
            }

            mimeTypes.AddRange(AcceptType.Parse(AcceptHeader, registeredMimes));

            return(mimeTypes.Distinct().ToArray());
        }
Ejemplo n.º 3
0
 private MimeType[] ParseHeader(string header)
 {
     return(AcceptType.Parse(header, TestMimes));
 }