コード例 #1
0
ファイル: StartRMState.cs プロジェクト: mbmccormick/Ximura
        /// <summary>
        /// This is the initialize state. This method does nothing.
        /// </summary>
        /// <param name="context">The current context.</param>
        public override void Initialize(ResourceManagerContext context)
        {
            string subCommand = "";

            if (context.Data.DestinationAddress.SubCommand is string)
                subCommand =(string)context.Data.DestinationAddress.SubCommand;

            switch (subCommand)
            {
                case "ETagFlush":
                    context.CheckChangeState("ETagCacheFlush");
                    break;
                default:
                    context.CheckChangeState("OutputSelector");
                    break;
            }
        }
コード例 #2
0
 /// <summary>
 /// This method selects the appropriate output style.
 /// </summary>
 /// <param name="context">The current context.</param>
 public override void OutputSelect(ResourceManagerContext context)
 {
     string id = context.Request.Settings.OutputColl[0].OutputType;
     switch (id)
     {
         case "file":
             context.CheckChangeState("RS_OutputFile");
             break;
         case "resource":
             context.CheckChangeState("RS_OutputResource");
             break;
         case "cds":
             context.CheckChangeState("RS_OutputCDS");
             break;
         //case "app":
         //    context.CheckChangeState("RS_OutputAPP");
         //    break;
         default:
             throw new InvalidOutputCCException(@"Output format """ + id + @""" not recognised.");
     }
 }
コード例 #3
0
        /// <summary>
        /// This method determines whether the entity has not been modified, and if so
        /// simply instructs the calling party that that is the case.
        /// </summary>
        /// <param name="context">The current context.</param>
        /// <returns>Returns false if the output logic should not be processed.</returns>
        public override bool RequestValidate(ResourceManagerContext context)
        {
            //Check whether the request has an ETag.
            string ETag = context.Request.Data.RequestIfNoneMatch;
            context.CheckChangeState("OutputSelector");

            if (ETag == null || ETag == "")
                return true;

            try
            {
                Guid vid = new Guid(ETag.Trim(new char[] { '"' }));
                Guid? cid;
                DateTime? expiry;
                Type contentType;


                if (!context.ContextSettings.ETagValidate(vid, out cid, out expiry, out contentType))
                    return true;


                if (expiry.HasValue && expiry.Value > DateTime.Now)
                {
                    context.Request.Data.ResponseHeaderAdd("Expires", CH.ConvertToRFC1123DateString(expiry.Value));
                    //set the cache control to public as we want these resources to be as cached as possible.
                    context.Request.Data.ResponseHeaderAdd("Cache-control", "public");
                }
                else if (!RevalidateAndUpdateETag(context, vid, cid.Value, contentType)) //OK, check the CDS to see if the content has changed.
                {
                    context.Request.Data.ResponseHeaderAdd("X-debug", "cachehit revalidate fail");

                    return true;
                }
                else
                    context.Request.Data.ResponseHeaderAdd("Cache-control", "must-revalidate");

                context.Request.Data.ResponseHeaderAdd("ETag", ETag);
        
                context.Response.Status = CH.HTTPCodes.NotModified_304;
                context.Response.Substatus = "Not Modified";
                return false;
            }
            catch (Exception ex)
            {
                context.Request.Data.ResponseHeaderAdd("X-debug", "cachehit exception");
                return true;
            }
        }