private void ConfigureHttpResponseHeaders() { Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{ Defines.PATH}/{{id?}}", new { controller = "HttpResponseHeaders" }); Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", respHeader => new { href = HttpResponseHeadersHelper.GetLocation(respHeader.id) }); // Web Server Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => { var id = GetHttpResponseHeadersId(null, null); return(new { href = HttpResponseHeadersHelper.GetLocation(id.Uuid) }); }); // Sites Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => { var siteId = new SiteId((string)site.id); Site s = SiteHelper.GetSite(siteId.Id); var id = GetHttpResponseHeadersId(s, "/"); return(new { href = HttpResponseHeadersHelper.GetLocation(id.Uuid) }); }); // Applications Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => { var appId = new ApplicationId((string)app.id); Site s = SiteHelper.GetSite(appId.SiteId); var id = GetHttpResponseHeadersId(s, appId.Path); return(new { href = HttpResponseHeadersHelper.GetLocation(id.Uuid) }); }); }
public object Patch(string id, dynamic model) { CustomHeaderId headerId = new CustomHeaderId(id); Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value); if (headerId.SiteId != null && site == null) { return(NotFound()); } NameValueConfigurationElement header = CustomHeadersHelper.GetCustomHeaders(site, headerId.Path).FirstOrDefault(h => h.Name.Equals(headerId.Name, StringComparison.OrdinalIgnoreCase)); if (header == null) { return(NotFound()); } var configScope = ManagementUnit.ResolveConfigScope(model); var section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, configScope); CustomHeadersHelper.Update(header, model, section); ManagementUnit.Current.Commit(); dynamic ch = CustomHeadersHelper.ToJsonModel(header, site, headerId.Path); if (ch.id != id) { return(LocationChanged(CustomHeadersHelper.GetLocation(ch.id), ch)); } return(ch); }
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)); }
public object Get() { Site site = ApplicationHelper.ResolveSite(); string path = ApplicationHelper.ResolvePath(); if (path == null) { return(NotFound()); } dynamic d = HttpResponseHeadersHelper.ToJsonModel(site, path); return(LocationChanged(HttpResponseHeadersHelper.GetLocation(d.id), d)); }
internal static object ToJsonModel(NameValueConfigurationElement header, Site site, string path) { if (header == null) { return(null); } RedirectHeaderId id = new RedirectHeaderId(site?.Id, path, header.Name); var obj = new { name = header.Name, value = header.Value, id = id.Uuid, http_response_headers = HttpResponseHeadersHelper.ToJsonModelRef(site, path), }; return(Core.Environment.Hal.Apply(Defines.RedirectHeadersResource.Guid, obj)); }
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(); }
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)); }
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 void Delete(string id) { var headerId = new CustomHeaderId(id); Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value); if (headerId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } NameValueConfigurationElement header = CustomHeadersHelper.GetCustomHeaders(site, headerId.Path).FirstOrDefault(h => h.Name.Equals(headerId.Name, StringComparison.OrdinalIgnoreCase)); if (header != null) { var section = HttpResponseHeadersHelper.GetSection(site, headerId.Path, ManagementUnit.ResolveConfigScope()); CustomHeadersHelper.Delete(header, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public static List <NameValueConfigurationElement> GetRedirectHeaders(Site site, string path) { return(HttpResponseHeadersHelper.GetSection(site, path).RedirectHeaders.ToList()); }
private HttpResponseHeadersId GetHttpResponseHeadersId(Site s, string path) { return(new HttpResponseHeadersId(s?.Id, path, HttpResponseHeadersHelper.IsSectionLocal(s, path))); }