public void Register(IAppHost appHost) { appHost.CatchAllHandlers.Add(ProcessRequest); appHost.ConfigurePlugin <MetadataFeature>( feature => feature.AddDebugLink($"?{Keywords.Debug}={Keywords.RequestInfo}", "Request Info")); }
public void BeforePluginsLoaded(IAppHost appHost) { appHost.Config.EmbeddedResourceSources.Add(typeof(OpenApiFeature).Assembly); if (!DisableSwaggerUI) { appHost.ConfigurePlugin <MetadataFeature>( feature => feature.AddPluginLink("swagger-ui/", "Swagger UI")); } }
public void Register(IAppHost appHost) { if (!string.IsNullOrEmpty(AtRestPath)) { appHost.RegisterService <RequestLogsService>(AtRestPath); } var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.LimitToServiceRequests = LimitToServiceRequests; requestLogger.SkipLogging = SkipLogging; requestLogger.RequiredRoles = RequiredRoles; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; requestLogger.RequestLogFilter = RequestLogFilter; requestLogger.IgnoreFilter = IgnoreFilter; requestLogger.CurrentDateFn = CurrentDateFn; appHost.Register(requestLogger); if (EnableRequestBodyTracking) { appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => { #if NETCORE // https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/6 if (httpReq.ContentType.MatchesContentType(MimeTypes.MultiPartFormData)) { return; } #endif httpReq.UseBufferedStream = EnableRequestBodyTracking; }); } appHost.ConfigurePlugin <MetadataFeature>( feature => feature.AddDebugLink(AtRestPath, "Request Logs")); appHost.GetPlugin <MetadataFeature>()?.ExportTypes.Add(typeof(RequestLogEntry)); appHost.AddToAppMetadata(meta => { meta.Plugins.RequestLogs = new RequestLogsInfo { RequiredRoles = RequiredRoles, ServiceRoutes = new Dictionary <string, string[]> { { nameof(RequestLogsService), new[] { AtRestPath } }, }, RequestLogger = requestLogger.GetType().Name, }; }); }
public void Register(IAppHost appHost) { appHost.RawHttpHandlers.Add(req => req.PathInfo == RoutePath ? (string.IsNullOrEmpty(req.QueryString["id"]) || string.IsNullOrEmpty(req.QueryString["format"]) ? new SharpPageHandler(HtmlTemplates.GetSvgTemplatePath()) { ValidateFn = ValidateFn, Context = SharpPageHandler.NewContext(appHost), } : (IHttpHandler) new SvgFormatHandler { Id = req.QueryString["id"], Format = req.QueryString["format"], Fill = req.QueryString["fill"], }) : req.PathInfo.StartsWith(RoutePath) ? new SvgFormatHandler(req.PathInfo.Substring(RoutePath.Length + 1)) { Fill = req.QueryString["fill"] } : null); var btnSvgCssFile = appHost.VirtualFileSources.GetFile("/css/buttons-svg.css"); if (btnSvgCssFile != null) { var btnSvgCss = btnSvgCssFile.ReadAllText(); foreach (var name in new[] { "svg-auth", "svg-icons" }) { if (Svg.CssFiles.ContainsKey(name) && !Svg.AppendToCssFiles.ContainsKey(name)) { Svg.AppendToCssFiles[name] = btnSvgCss; } } } appHost.ConfigurePlugin <MetadataFeature>( feature => feature.AddDebugLink(RoutePath, "SVG Images")); }
public void Register(IAppHost appHost) { if (ResourceFilterPattern != null) { OpenApiService.resourceFilterRegex = new Regex(ResourceFilterPattern, RegexOptions.Compiled); } if (SecurityDefinitions == null && OperationSecurity == null) { var useBasicAuth = appHost.GetPlugin <AuthFeature>()?.AuthProviders ?.Any(x => x.Provider == AuthenticateService.BasicProvider) == true; if (!useBasicAuth) { UseBearerSecurity = true; } else { UseBasicSecurity = true; } } OpenApiService.UseCamelCaseSchemaPropertyNames = UseCamelCaseSchemaPropertyNames; OpenApiService.UseLowercaseUnderscoreSchemaPropertyNames = UseLowercaseUnderscoreSchemaPropertyNames; OpenApiService.DisableAutoDtoInBodyParam = DisableAutoDtoInBodyParam; OpenApiService.ApiDeclarationFilter = ApiDeclarationFilter; OpenApiService.OperationFilter = OperationFilter; OpenApiService.SchemaFilter = SchemaFilter; OpenApiService.SchemaPropertyFilter = SchemaPropertyFilter; OpenApiService.AnyRouteVerbs = AnyRouteVerbs.ToArray(); OpenApiService.InlineSchemaTypesInNamespaces = InlineSchemaTypesInNamespaces.ToArray(); OpenApiService.SecurityDefinitions = SecurityDefinitions; OpenApiService.OperationSecurity = OperationSecurity; appHost.RegisterService(typeof(OpenApiService), "/openapi"); if (!DisableSwaggerUI) { var swaggerUrl = "swagger-ui/"; appHost.ConfigurePlugin <MetadataFeature>( feature => feature.AddPluginLink(swaggerUrl, "Swagger UI")); appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => { IVirtualFile indexFile; IVirtualFile patchFile = null; IVirtualFile patchPreLoadFile = null; pathInfo = pathInfo.TrimStart('/'); switch (pathInfo) { case "swagger-ui/": case "swagger-ui/default.html": indexFile = appHost.VirtualFileSources.GetFile("/swagger-ui/index.html"); patchFile = appHost.VirtualFileSources.GetFile("/swagger-ui/patch.js"); patchPreLoadFile = appHost.VirtualFileSources.GetFile("/swagger-ui/patch-preload.js"); break; default: indexFile = null; break; } if (indexFile != null) { var html = indexFile.ReadAllText(); var injectJs = patchFile?.ReadAllText(); var injectPreloadJs = patchPreLoadFile?.ReadAllText(); return(new CustomResponseHandler((req, res) => { res.ContentType = MimeTypes.HtmlUtf8; //use alt HTML ContentType so it's not overridden when Feature.Html is removed var resourcesUrl = req.ResolveAbsoluteUrl("~/openapi"); html = html.Replace("http://petstore.swagger.io/v2/swagger.json", resourcesUrl) .Replace("ApiDocs", HostContext.ServiceName) .Replace("<span class=\"logo__title\">swagger</span>", $"<span class=\"logo__title\">{HostContext.ServiceName}</span>") .Replace("http://swagger.io", LogoHref ?? "./"); if (LogoUrl != null) { html = html.Replace("images/logo_small.png", LogoUrl); } if (injectPreloadJs != null) { html = html.Replace("window.swaggerUi.load();", injectPreloadJs + "\n\n window.swaggerUi.load();"); } if (injectJs != null) { html = html.Replace("</body>", "<script type='text/javascript'>" + injectJs + "</script></body>"); } return html; })); } return(pathInfo.StartsWith("/swagger-ui/") ? new StaticFileHandler() : null); }); } }