public virtual HttpAsyncTaskHandler ProcessRequestRaw(IHttpRequest request) { MemoryStream resultStream = null; if (request.PathInfo.Contains("/components/fileorganizer/fileorganizer.js")) { resultStream = HtmlHelper.OrganizerScript; } else if (request.PathInfo.Contains("/components/fileorganizer/fileorganizer.template.html")) { resultStream = HtmlHelper.OrganizerTemplate; } if (resultStream != null) { var handler = new CustomActionHandler((httpReq, httpRes) => { httpRes.ContentType = "text/html"; lock (resultStream) { resultStream.Seek(0, SeekOrigin.Begin); resultStream.WriteTo(httpRes.OutputStream); httpRes.EndRequest(); } httpRes.End(); }); return(handler); } return(null); }
public void EventManagerShouldAddHandleTest() { var eventManager = EventManagerDispatcher <EventManagerTestsEvent> .GetEventManager(); var handler = new CustomActionHandler <EventManagerTestsEvent>(); eventManager.AddHandler(handler); Assert.Contains(handler, eventManager.GetEventHandlers().ToArray()); }
public void Register(IAppHost appHost) { if (appHost.HasMultiplePlugins <CorsFeature>()) { throw new NotSupportedException("CorsFeature has already been registered"); } if (!string.IsNullOrEmpty(allowedOrigins) && allowOriginWhitelist == null) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowOrigin, allowedOrigins); } if (!string.IsNullOrEmpty(allowedMethods)) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowMethods, allowedMethods); } if (!string.IsNullOrEmpty(allowedHeaders)) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowHeaders, allowedHeaders); } if (allowCredentials) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowCredentials, "true"); } Action <IRequest, IResponse> allowOriginFilter = null; if (allowOriginWhitelist != null) { allowOriginFilter = (httpReq, httpRes) => { var origin = httpReq.Headers.Get("Origin"); if (allowOriginWhitelist.Contains(origin)) { httpRes.AddHeader(HttpHeaders.AllowOrigin, origin); } }; appHost.PreRequestFilters.Add(allowOriginFilter); } if (AutoHandleOptionsRequests) { //Handles Request and closes Response after emitting global HTTP Headers var emitGlobalHeadersHandler = new CustomActionHandler( (httpReq, httpRes) => { if (allowOriginFilter != null) { allowOriginFilter(httpReq, httpRes); } httpRes.EndRequest(); }); appHost.RawHttpHandlers.Add(httpReq => httpReq.HttpMethod == HttpMethods.Options ? emitGlobalHeadersHandler : null); } }
public override void Configure(Container container) { //containers HttpServiceContainer.Build(container); SearchContainer.Build(container); // mappings AllergyMapper.Build(); GoalsMapper.Build(); AllergyMedSearchMapper.Build(); MedSuppMapper.Build(); PatientNoteMapper.Build(); PatientSystemMapper.Build(); PatientContactMapper.Build(); ContactTypeLookUpsMappers.Build(); ContactMapper.Build(); Plugins.Add(new RequestLogsFeature() { RequiredRoles = new string[] {} }); // request filtering for setting global vals. RequestFilters.Add((req, res, requestDto) => { HostContext.Instance.Items.Add("Contract", ((IAppDomainRequest)requestDto).ContractNumber); HostContext.Instance.Items.Add("Version", ((IAppDomainRequest)requestDto).Version); }); RequestFilters.Add((req, res, requestDto) => { var obj = req.ResponseContentType; }); var emitGlobalHeadersHandler = new CustomActionHandler((httpReq, httpRes) => httpRes.EndRequest()); SetConfig(new EndpointHostConfig { RawHttpHandlers = { (httpReq) => httpReq.HttpMethod == HttpMethods.Options ? emitGlobalHeadersHandler : null }, GlobalResponseHeaders = { //{"Access-Control-Allow-Origin", "*"}, { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }, { "Access-Control-Allow-Headers", "Content-Type" }, }, AllowJsonpRequests = true }); // initialize datetime format JsConfig.DateHandler = JsonDateHandler.ISO8601; }
public override void Configure(Funq.Container container) { JsConfig.EmitCamelCaseNames = true; JsConfig.DateHandler = DateHandler.ISO8601; Plugins.Add(new CorsFeature(allowedOrigins: "*", allowedMethods: "GET, POST, PUT, DELETE, OPTIONS", allowedHeaders: "Content-Type, authToken, accept, authorization", allowCredentials: false)); var emitGlobalHeadersHandler = new CustomActionHandler((httpReq, httpRes) => httpRes.EndRequest()); RawHttpHandlers.Add(httpReq => httpReq.HttpMethod == HttpMethods.Options ? emitGlobalHeadersHandler : null); PreRequestFilters.Add((req, res) => req.UseBufferedStream = true); }
public void Initialize( WasmBehaviour wasm, MixedRealityInputAction grabAction, MixedRealityInputAction useAction) { this.wasm = wasm; grabHandler = gameObject.AddComponent<CustomActionHandler>(); grabHandler.InputAction = grabAction; grabHandler.SetFocusRequired(true); grabHandler.OnInputActionStarted += GrabHandler_OnInputActionStarted; useHandler = gameObject.AddComponent<CustomActionHandler>(); useHandler.InputAction = useAction; // useHandler.SetFocusRequired(false); useHandler.OnInputActionStarted += UseHandler_OnInputActionStarted; }
public override void Configure(Funq.Container container) { //register any dependencies your services use, e.g: //container.Register<ICacheClient>(new MemoryCacheClient()); Plugins.Add(new RequestLogsFeature() { RequiredRoles = new string[] { } }); var emitGlobalHeadersHandler = new CustomActionHandler((httpReq, httpRes) => httpRes.EndRequest()); SetConfig(new EndpointHostConfig { RawHttpHandlers = { (httpReq) => httpReq.HttpMethod == HttpMethods.Options ? emitGlobalHeadersHandler : null }, GlobalResponseHeaders = { //{"Access-Control-Allow-Origin", "*"}, { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }, { "Access-Control-Allow-Headers", "Content-Type" }, }, AllowJsonpRequests = true }); }
public virtual HttpAsyncTaskHandler ProcessRequestRaw(IHttpRequest request) { MemoryStream resultStream = null; if (request.PathInfo.Contains("/components/metadataviewer/metadataviewer.js")) { resultStream = HtmlHelper.ViewerScript; } else if (request.PathInfo.Contains("/components/metadataviewer/metadataviewer.template.html")) { resultStream = HtmlHelper.ViewerTemplate; } else if (request.PathInfo.Contains("/bower_components/emby-webcomponents/itemcontextmenu.js")) { resultStream = HtmlHelper.ModifiedContextMenu; } if (resultStream != null) { var handler = new CustomActionHandler((httpReq, httpRes) => { httpRes.ContentType = "text/html"; lock (resultStream) { resultStream.Seek(0, SeekOrigin.Begin); resultStream.WriteTo(httpRes.OutputStream); httpRes.EndRequest(); } httpRes.End(); }); return handler; } return null; }
public override void Configure(Container container) { ServiceStack.Text.JsConfig.IncludeNullValues = true; ServiceStack.Text.JsConfig.IncludeTypeInfo = true; if (System.PlatformExtension.IsMono()) { RCFProto.SetNativeDllPath(@"/var/mono-www/bin/libRCFProto_NET_impl.so"); } else { RCFProto.SetNativeDllPath(@"C:/Users/Brenden/Documents/visual studio 2013/Projects/SwgEMU-API/SWGEmu-API/bin/RCFProto_NET_impl.dll"); } RCFProto.Init(); container.Register <RcfProtoChannel>(AccquireChannel).ReusedWithin(ReuseScope.Request); container.RegisterAutoWiredAs <InventoryItemTransformModel, IInventoryItemTransformModel>(); container.RegisterAutoWiredAs <StructureTransformModel, IStructureTransformModel>(); container.Register <swgemurpcserver.rpc.SWGEmuAccountService.Stub>(c => swgemurpcserver.rpc.SWGEmuAccountService.CreateStub(c.Resolve <DeltaVSoft.RCFProto.RcfProtoChannel>())).ReusedWithin(ReuseScope.Request); container.Register <swgemurpcserver.rpc.SWGEmuCharacterDetailsService.Stub>(c => swgemurpcserver.rpc.SWGEmuCharacterDetailsService.Stub.CreateStub(c.Resolve <DeltaVSoft.RCFProto.RcfProtoChannel>())).ReusedWithin(ReuseScope.Request); container.Register <swgemurpcserver.rpc.SWGEmuStructureItemDetailsService.Stub>(c => swgemurpcserver.rpc.SWGEmuStructureItemDetailsService.CreateStub(c.Resolve <RcfProtoChannel>())).ReusedWithin(ReuseScope.Request); container.RegisterAutoWiredAs <Model.AccountModel, Model.IAccountModel>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWiredAs <Model.CharacterModel, Model.ICharacterModel>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWiredAs <Model.StructureModel, IStructureModel>().ReusedWithin(ReuseScope.Request); container.Register <Model.IStringDetailsModel>(c => { string path = SWGEmuAPI.Properties.Settings.Default.DetailsFilePath; System.IO.DirectoryInfo pathInfo = new System.IO.DirectoryInfo(path); //throw new Exception(ServiceStack.Text.JsonSerializer.SerializeToString<List<string>>(realpaths)); if (!pathInfo.Exists) { //throw new System.IO.DirectoryNotFoundException("Direcotry for string details not found: " + path); } return(new Model.StringDetailsModel(new FileSystemVirtualDirectory(VirtualPathProvider, null, pathInfo))); }).ReusedWithin(ReuseScope.Hierarchy); SetConfig(new EndpointHostConfig { DebugMode = true //Show StackTraces for easier debugging (default auto inferred by Debug/Release builds) }); //enable cors requests and enable the options method. Plugins.Add(new CorsFeature(allowedHeaders: "Content-Type, Authorization, Accept")); var emitGlobalHeadersHandler = new CustomActionHandler((httpReq, httpRes) => httpRes.EndRequest()); this.Config.RawHttpHandlers.Add(httpReq => httpReq.HttpMethod == HttpMethods.Options ? emitGlobalHeadersHandler : null); //cahcing container.Register <IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379")); container.Register <ICacheClient>(c => (ICacheClient)c.Resolve <IRedisClientsManager>().GetCacheClient()).ReusedWithin(Funq.ReuseScope.None); container.Register <IRedisClient>(c => c.Resolve <IRedisClientsManager>().GetClient()).ReusedWithin(Funq.ReuseScope.Request); Plugins.Add(new ServiceStack.ServiceInterface.Admin.RequestLogsFeature()); Plugins.Add(new RazorFormat()); Plugins.Add(new SessionFeature()); Plugins.Add(new ValidationFeature()); //OAuth2 classes container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(Properties.Settings.Default.ConnectionString, ServiceStack.OrmLite.MySql.MySqlDialectProvider.Instance)); container.RegisterAutoWiredAs <OAuth2.Server.Model.ClientModel, OAuth2.Server.Model.IClientModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.ResourceOwnerModel, OAuth2.Server.Model.IResourceOwnerModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.TokenDBModel, OAuth2.Server.Model.IDBTokenModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.TokenCacheModel, OAuth2.Server.Model.ICacheTokenModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.CacheDBTokenModel, OAuth2.Server.Model.ITokenModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.ApprovalModel, OAuth2.Server.Model.IApprovalModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.ScopeModel, OAuth2.Server.Model.IScopeModel>(); container.RegisterAutoWiredAs <OAuth2.Server.Model.AuthorizationCodeModel, OAuth2.Server.Model.IAuthorizationCodeModel>(); container.RegisterAutoWired <OAuth2.Server.Model.ClientGrantModel>(); container.RegisterAutoWired <OAuth2.Server.Model.CodeGrantModel>(); container.RegisterAutoWired <OAuth2.Server.Model.PasswordGrantModel>(); container.RegisterAutoWired <OAuth2.Server.Model.RefreshTokenGrantModel>(); container.RegisterAutoWired <OAuth2.Server.Model.TokenGrantModel>(); //add filter to inject client details from basic auth RequestFilters.Add(AddClientDetails); }
public void Register(IAppHost appHost) { if (appHost.HasMultiplePlugins <CorsFeature>()) { throw new NotSupportedException("CorsFeature has already been registered"); } if (!string.IsNullOrEmpty(allowedOrigins) && allowOriginWhitelist == null) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowOrigin, allowedOrigins); } if (!string.IsNullOrEmpty(allowedMethods)) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowMethods, allowedMethods); } if (!string.IsNullOrEmpty(allowedHeaders)) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowHeaders, allowedHeaders); } if (allowCredentials) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AllowCredentials, "true"); } if (exposeHeaders != null) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.ExposeHeaders, exposeHeaders); } if (maxAge != null) { appHost.Config.GlobalResponseHeaders.Add(HttpHeaders.AccessControlMaxAge, maxAge.Value.ToString()); } if (allowOriginWhitelist != null) { void allowOriginFilter(IRequest httpReq, IResponse httpRes) { var origin = httpReq.Headers.Get(HttpHeaders.Origin); if (allowOriginWhitelist.Contains(origin)) { httpRes.AddHeader(HttpHeaders.AllowOrigin, origin); } } appHost.PreRequestFilters.Add(allowOriginFilter); } if (AutoHandleOptionsRequests) { //Handles Request and closes Response after emitting global HTTP Headers var emitGlobalHeadersHandler = new CustomActionHandler( (httpReq, httpRes) => { httpRes.EndRequest(); //PreRequestFilters already written in CustomActionHandler }); appHost.RawHttpHandlers.Add(httpReq => httpReq.HttpMethod == HttpMethods.Options ? emitGlobalHeadersHandler : null); } appHost.GetPlugin <MetadataFeature>() ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/corsfeature", "CORS Feature"); }