public static void Delete(NameValueConfigurationElement header, HttpProtocolSection section)
        {
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            if (header == null)
            {
                return;
            }

            // Need to pull the element out of the collection we are removing it from
            header = section.CustomHeaders.FirstOrDefault(h => h.Name.Equals(header.Name, StringComparison.OrdinalIgnoreCase));

            if (header != null)
            {
                try {
                    section.CustomHeaders.Remove(header);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }
        public static NameValueConfigurationElement Create(dynamic model, HttpProtocolSection section)
        {
            if (section == null)
            {
                throw new ArgumentException("section");
            }
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            string name  = DynamicHelper.Value(model.name);
            string value = DynamicHelper.Value(model.value);

            if (String.IsNullOrEmpty(name))
            {
                throw new ApiArgumentException("name");
            }
            if (value == null)
            {
                // We don't check for empty because there is nothing wrong with an empty string header value

                throw new ApiArgumentException("value");
            }

            var elem = section.CustomHeaders.CreateElement();

            elem.Name  = name;
            elem.Value = value;

            return(elem);
        }
Exemplo n.º 3
0
        public static void UpdateFeatureSettings(dynamic model, HttpProtocolSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            try {
                DynamicHelper.If <bool>((object)model.allow_keep_alive, v => section.AllowKeepAlive = v);

                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
                }
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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));
        }
        public static void Update(NameValueConfigurationElement header, dynamic model, HttpProtocolSection section)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            try {
                string name = DynamicHelper.Value(model.name);
                if (!string.IsNullOrEmpty(name))
                {
                    if (section.RedirectHeaders.Any(h => h.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
                    {
                        throw new AlreadyExistsException("header.name");
                    }

                    header.Name = name;
                }

                header.Value = DynamicHelper.Value(model.value) ?? header.Value;
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }