Esempio n. 1
0
        public object Get(string id)
        {
            HttpResponseHeadersId headerId = new HttpResponseHeadersId(id);

            Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value);

            if (headerId.SiteId != null && site == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            return(HttpResponseHeadersHelper.ToJsonModel(site, headerId.Path));
        }
Esempio n. 2
0
        public static object ToJsonModelRef(Site site, string path)
        {
            var section = GetSection(site, path);

            HttpResponseHeadersId id = new HttpResponseHeadersId(site?.Id, path, section.IsLocallyStored);

            var obj = new {
                id    = id.Uuid,
                scope = site == null ? string.Empty : site.Name + path
            };

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj, false));
        }
Esempio n. 3
0
        internal static object ToJsonModel(Site site, string path)
        {
            HttpProtocolSection section = GetSection(site, path);

            HttpResponseHeadersId id = new HttpResponseHeadersId(site?.Id, path, section.IsLocallyStored);

            var obj = new {
                id               = id.Uuid,
                scope            = site == null ? string.Empty : site.Name + path,
                metadata         = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective),
                allow_keep_alive = section.AllowKeepAlive,
                website          = SiteHelper.ToJsonModelRef(site)
            };

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj));
        }
Esempio n. 4
0
        public void Delete(string id)
        {
            HttpResponseHeadersId headerId = new HttpResponseHeadersId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (headerId.SiteId != null) ? SiteHelper.GetSite(headerId.SiteId.Value) : null;

            if (site == null)
            {
                return;
            }

            HttpProtocolSection section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, ManagementUnit.ResolveConfigScope());

            section.RevertToParent();

            ManagementUnit.Current.Commit();
        }
Esempio n. 5
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.http_response_headers == null)
            {
                throw new ApiArgumentException("http_response_headers");
            }
            if (!(model.http_response_headers is JObject))
            {
                throw new ApiArgumentException("http_response_headers");
            }

            string uuid = DynamicHelper.Value(model.http_response_headers.id);

            if (uuid == null)
            {
                throw new ApiArgumentException("http_response_headers.id");
            }

            HttpResponseHeadersId id = new HttpResponseHeadersId(uuid);

            Site site = id.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value);

            string configPath           = ManagementUnit.ResolveConfigScope(model);
            HttpProtocolSection section = HttpResponseHeadersHelper.GetSection(site, id.Path, configPath);

            NameValueConfigurationElement header = CustomHeadersHelper.Create(model, section);

            CustomHeadersHelper.Add(header, section);

            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic ch = CustomHeadersHelper.ToJsonModel(header, site, id.Path);

            return(Created(CustomHeadersHelper.GetLocation(ch.id), ch));
        }
Esempio n. 6
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            HttpResponseHeadersId headerId = new HttpResponseHeadersId(id);

            Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value);

            if (headerId.SiteId != null && site == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            // Check for config_scope
            string configScope          = ManagementUnit.ResolveConfigScope(model);;
            HttpProtocolSection section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, configScope);

            HttpResponseHeadersHelper.UpdateFeatureSettings(model, section);

            ManagementUnit.Current.Commit();

            return(HttpResponseHeadersHelper.ToJsonModel(site, headerId.Path));
        }
Esempio n. 7
0
        public object Get()
        {
            string uuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(uuid))
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            HttpResponseHeadersId id = new HttpResponseHeadersId(uuid);

            Site site = id.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value);

            List <NameValueConfigurationElement> headers = CustomHeadersHelper.GetCustomHeaders(site, id.Path);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(headers.Count());

            return(new {
                custom_headers = headers.Select(h => CustomHeadersHelper.ToJsonModelRef(h, site, id.Path))
            });
        }