public void WhenPatchApplied_ThenSetUserAgentHeaderSuceeds() { RestrictedHeaderConfigPatch.SetHeaderRestriction("User-Agent", false); var websocket = new ClientWebSocket(); websocket.Options.SetRequestHeader("User-Agent", "test"); RestrictedHeaderConfigPatch.SetHeaderRestriction("User-Agent", true); }
protected override int HandleFirstInvocation(string[] args) { var options = CommandLineOptions.ParseOrExit(args); IsLoggingEnabled = options.IsLoggingEnabled; #if DEBUG Google.Solutions.IapDesktop.Application.TraceSources.IapDesktop.Switch.Level = SourceLevels.Verbose; #endif // Use TLS 1.2 if possible. System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; // Lift limit on concurrent HTTP connections to same endpoint, // relevant for GCS downloads. ServicePointManager.DefaultConnectionLimit = 16; // Allow custom User-Agent headers. try { RestrictedHeaderConfigPatch.SetHeaderRestriction("User-Agent", false); } catch (InvalidOperationException) { Google.Solutions.IapDesktop.Application.TraceSources.IapDesktop.TraceWarning( "Failed to un-restrict User-Agent headers"); } System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); // // Set up layers. Services in a layer can lookup services in a lower layer, // but not in a higher layer. // var persistenceLayer = new ServiceRegistry(); var adapterLayer = new ServiceRegistry(persistenceLayer); var integrationLayer = new ServiceRegistry(adapterLayer); var windowAndWorkflowLayer = new ServiceRegistry(integrationLayer); var hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default); // // Persistence layer. // persistenceLayer.AddTransient <IAppProtocolRegistry, AppProtocolRegistry>(); persistenceLayer.AddSingleton(new ApplicationSettingsRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\Application"))); persistenceLayer.AddSingleton(new ToolWindowStateRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\ToolWindows"))); persistenceLayer.AddSingleton(new AuthSettingsRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\Auth"), GoogleAuthAdapter.StoreUserId)); var mainForm = new MainForm(persistenceLayer, windowAndWorkflowLayer) { StartupUrl = options.StartupUrl }; // // Adapter layer. // adapterLayer.AddSingleton <IAuthorizationAdapter>(mainForm); adapterLayer.AddSingleton <IJobHost>(mainForm); adapterLayer.AddTransient <IResourceManagerAdapter, ResourceManagerAdapter>(); adapterLayer.AddTransient <IComputeEngineAdapter, ComputeEngineAdapter>(); adapterLayer.AddTransient <GithubAdapter>(); adapterLayer.AddTransient <EmailAdapter>(); adapterLayer.AddTransient <IHttpProxyAdapter, HttpProxyAdapter>(); try { // Activate proxy settings based on app settings. adapterLayer.GetService <IHttpProxyAdapter>().ActivateSettings( adapterLayer.GetService <ApplicationSettingsRepository>().GetSettings()); } catch (Exception) { // Settings invalid -> ignore. } // // Integration layer. // var eventService = new EventService(mainForm); integrationLayer.AddSingleton <IJobService, JobService>(); integrationLayer.AddSingleton <IEventService>(eventService); integrationLayer.AddSingleton <IGlobalConnectionBroker, GlobalConnectionBroker>(); integrationLayer.AddSingleton <IProjectRepository>(new ProjectRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\Inventory"), eventService)); // // Window & workflow layer. // windowAndWorkflowLayer.AddSingleton <IMainForm>(mainForm); windowAndWorkflowLayer.AddTransient <CloudConsoleService>(); windowAndWorkflowLayer.AddTransient <HelpService>(); windowAndWorkflowLayer.AddTransient <IProjectPickerDialog, ProjectPickerDialog>(); windowAndWorkflowLayer.AddTransient <AboutWindow>(); windowAndWorkflowLayer.AddTransient <IExceptionDialog, ExceptionDialog>(); windowAndWorkflowLayer.AddTransient <IConfirmationDialog, ConfirmationDialog>(); windowAndWorkflowLayer.AddTransient <ITaskDialog, TaskDialog>(); windowAndWorkflowLayer.AddTransient <IUpdateService, UpdateService>(); windowAndWorkflowLayer.AddSingleton <IProjectExplorer, ProjectExplorerWindow>(); windowAndWorkflowLayer.AddTransient <OptionsDialog>(); #if DEBUG windowAndWorkflowLayer.AddSingleton <DebugJobServiceWindow>(); windowAndWorkflowLayer.AddSingleton <DebugDockingWindow>(); windowAndWorkflowLayer.AddSingleton <DebugProjectExplorerTrackingWindow>(); #endif // // Extension layer. // var extensionLayer = new ServiceRegistry(windowAndWorkflowLayer); foreach (var extension in LoadExtensionAssemblies()) { extensionLayer.AddExtensionAssembly(extension); } // Run app. this.initializedMainForm = mainForm; this.mainFormInitialized.Set(); System.Windows.Forms.Application.Run(mainForm); // Ensure logs are flushed. IsLoggingEnabled = false; return(0); }
protected override int HandleFirstInvocation(string[] args) { var startupUrl = ParseCommandLine(args); IsLoggingEnabled = false; #if DEBUG Google.Solutions.IapDesktop.Application.TraceSources.IapDesktop.Switch.Level = SourceLevels.Verbose; #endif // Use TLS 1.2 if possible. System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; // Allow custom User-Agent headers. try { RestrictedHeaderConfigPatch.SetHeaderRestriction("User-Agent", false); } catch (InvalidOperationException) { Google.Solutions.IapDesktop.Application.TraceSources.IapDesktop.TraceWarning( "Failed to un-restrict User-Agent headers"); } System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); // // Set up layers. Services in a layer can lookup services in a lower layer, // but not in a higher layer. // var persistenceLayer = new ServiceRegistry(); var adapterLayer = new ServiceRegistry(persistenceLayer); var integrationLayer = new ServiceRegistry(adapterLayer); var windowAndWorkflowLayer = new ServiceRegistry(integrationLayer); var hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default); // // Persistence layer. // persistenceLayer.AddTransient <AppProtocolRegistry>(); persistenceLayer.AddSingleton(new ApplicationSettingsRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\Application"))); persistenceLayer.AddSingleton(new AuthSettingsRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\Auth"), GoogleAuthAdapter.StoreUserId)); persistenceLayer.AddSingleton(new ConnectionSettingsRepository( hkcu.CreateSubKey($@"{BaseRegistryKeyPath}\Inventory"))); var mainForm = new MainForm(persistenceLayer, windowAndWorkflowLayer) { StartupUrl = startupUrl }; // // Adapter layer. // adapterLayer.AddSingleton <IAuthorizationAdapter>(mainForm); adapterLayer.AddSingleton <IJobHost>(mainForm); adapterLayer.AddTransient <IResourceManagerAdapter, ResourceManagerAdapter>(); adapterLayer.AddTransient <IComputeEngineAdapter, ComputeEngineAdapter>(); adapterLayer.AddTransient <GithubAdapter>(); // // Integration layer. // integrationLayer.AddSingleton <IJobService, JobService>(); integrationLayer.AddSingleton <IEventService>(new EventService(mainForm)); integrationLayer.AddTransient <ProjectInventoryService>(); integrationLayer.AddTransient <ITunnelService, TunnelService>(); integrationLayer.AddSingleton <ITunnelBrokerService, TunnelBrokerService>(); // // Window & workflow layer. // windowAndWorkflowLayer.AddSingleton <IMainForm>(mainForm); windowAndWorkflowLayer.AddTransient <CloudConsoleService>(); windowAndWorkflowLayer.AddTransient <IProjectPickerDialog, ProjectPickerDialog>(); windowAndWorkflowLayer.AddTransient <AboutWindow>(); windowAndWorkflowLayer.AddTransient <IExceptionDialog, ExceptionDialog>(); windowAndWorkflowLayer.AddTransient <IConfirmationDialog, ConfirmationDialog>(); windowAndWorkflowLayer.AddTransient <ITaskDialog, TaskDialog>(); windowAndWorkflowLayer.AddTransient <IUpdateService, UpdateService>(); windowAndWorkflowLayer.AddSingleton <IRemoteDesktopService, RemoteDesktopService>(); windowAndWorkflowLayer.AddSingleton <ISettingsEditor, SettingsEditorWindow>(); windowAndWorkflowLayer.AddSingleton <IProjectExplorer, ProjectExplorerWindow>(); windowAndWorkflowLayer.AddSingleton <ITunnelsViewer, TunnelsWindow>(); windowAndWorkflowLayer.AddTransient <ICredentialsService, CredentialsService>(); windowAndWorkflowLayer.AddTransient <RemoteDesktopConnectionService>(); #if DEBUG windowAndWorkflowLayer.AddSingleton <DebugJobServiceWindow>(); windowAndWorkflowLayer.AddSingleton <DebugProjectExplorerTrackingWindow>(); windowAndWorkflowLayer.AddSingleton <HtmlPageGenerator>(); #endif // // Extension layer. // var extensionLayer = new ServiceRegistry(windowAndWorkflowLayer); foreach (var extension in LoadExtensionAssemblies()) { extensionLayer.AddExtensionAssembly(extension); } // Run app. this.initializedMainForm = mainForm; this.mainFormInitialized.Set(); System.Windows.Forms.Application.Run(mainForm); // Ensure logs are flushed. IsLoggingEnabled = false; return(0); }