text:
using System;
using System.Collections.Generic;
using Rhino.Mocks;
using NUnit.Framework;
using VersionOne.VisualStudio.DataLayer;
using VersionOne.VisualStudio.DataLayer.Entities;
using VersionOne.VisualStudio.DataLayer.Logging;
using VersionOne.VisualStudio.VSPackage;
using VersionOne.VisualStudio.VSPackage.Controllers;
using VersionOne.VisualStudio.VSPackage.Controls;
using VersionOne.VisualStudio.VSPackage.Descriptors;
using VersionOne.VisualStudio.VSPackage.Events;
using VersionOne.VisualStudio.VSPackage.Settings;
using Aga.Controls.Tree;

namespace VersionOne.VisualStudio.Tests {
    [TestFixture]
    public class WorkitemTreeControllerTester : BaseTester {
        private WorkitemTreeController controller;
        private IDataLayer dataLayerMock;
        private IAssetCache assetCacheMock;
        private ISettings settingsMock;
        private IEventDispatcher eventDispatcherMock;
        private IWorkitemTreeView viewMock;
        private IWaitCursor waitCursorStub;
        private ILoggerFactory loggerFactoryMock;
        private IEffortTracking effortTrackingMock;
        private Configuration configuration;

        private readonly MockRepository mockRepository = new MockRepository();

        [SetUp]
        public void SetUp() {
            dataLayerMock = mockRepository.StrictMock<IDataLayer>();
            assetCacheMock = mockRepository.StrictMock<IAssetCache>();
            settingsMock = mockRepository.StrictMock<ISettings>();
            viewMock = mockRepository.StrictMock<IWorkitemTreeView>();
            waitCursorStub = mockRepository.Stub<IWaitCursor>();
            eventDispatcherMock = mockRepository.Stub<IEventDispatcher>();
            loggerFactoryMock = mockRepository.DynamicMock<ILoggerFactory>();
            effortTrackingMock = mockRepository.StrictMock<IEffortTracking>();
            loggerFactoryMock.Stub(x => x.GetLogger(null)).IgnoreArguments().Return(mockRepository.Stub<ILogger>());
            configuration = new Configuration();
            Container.Rebind<IDataLayer>().ToConstant(dataLayerMock);
            controller = new WorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
        }

        private void ExpectRegisterAndPrepareView() {
            Expect.Call(() => eventDispatcherMock.ModelChanged += null).IgnoreArguments();
            Expect.Call(viewMock.Controller).PropertyBehavior();
            Expect.Call(dataLayerMock.CreateAssetCache()).Return(assetCacheMock);
            Expect.Call(dataLayerMock.CurrentProject).Return(null);
            Expect.Call(viewMock.Title).IgnoreArguments().PropertyBehavior();
            Expect.Call(viewMock.Model).IgnoreArguments().PropertyBehavior();
            Expect.Call(viewMock.ReconfigureTreeColumns);
            Expect.Call(viewMock.CheckSettingsAreValid()).Return(true);
            Expect.Call(viewMock.ReconfigureTreeColumns);
            Expect.Call(viewMock.SetSelection);
            Expect.Call(viewMock.Refresh);
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(null);
            Expect.Call(viewMock.AddTaskCommandEnabled).IgnoreArguments().PropertyBehavior();
            Expect.Call(viewMock.AddTestCommandEnabled).IgnoreArguments().PropertyBehavior();
            Expect.Call(viewMock.AddDefectCommandEnabled).IgnoreArguments().PropertyBehavior();
        }

        [Test]
        public void RegisterAndPrepareView() {
            ExpectRegisterAndPrepareView();

            mockRepository.ReplayAll();

            controller.Register(viewMock);
            Assert.AreEqual(controller, viewMock.Controller);
            controller.PrepareView();

            mockRepository.VerifyAll();
        }

        [Test]
        public void HandleRefresh() {
            ExpectRegisterAndPrepareView();
            Expect.Call(assetCacheMock.Drop);
            Expect.Call(dataLayerMock.EffortTracking).Return(effortTrackingMock);
            Expect.Call(effortTrackingMock.Refresh);
            Expect.Call(dataLayerMock.UpdateListPropertyValues);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsRequested)));

            mockRepository.ReplayAll();

            controller.Register(viewMock);
            controller.PrepareView();
            controller.HandleRefreshCommand();

            mockRepository.VerifyAll();
        }

        [Test]
        public void CommitItem() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);
            var descriptor = new WorkitemDescriptor(workitemMock, new ColumnSetting[0], PropertyUpdateSource.WorkitemView, true);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(descriptor);
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.CommitChanges);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.ProjectView, EventContext.V1SettingsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.CommitItem();

            mockRepository.VerifyAll();
        }

        [Test]
        public void CommitItemValidationFailure() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);
            var descriptor = new WorkitemDescriptor(workitemMock, new ColumnSetting[0], PropertyUpdateSource.WorkitemView, true);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(descriptor);
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.CommitChanges).Throw(new ValidatorException(null));
            Expect.Call(() => viewMock.ShowErrorMessage(null)).IgnoreArguments();
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.CommitItem();

            mockRepository.VerifyAll();
        }

        [Test]
        public void RevertNonVirtualItem() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), false, assetCacheMock);
            var descriptor = new WorkitemDescriptor(workitemMock, new ColumnSetting[0], PropertyUpdateSource.WorkitemView, true);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(descriptor);
            Expect.Call(workitemMock.RevertChanges);
            Expect.Call(viewMock.Refresh);

            mockRepository.ReplayAll();

            controller.Register(viewMock);
            controller.PrepareView();
            controller.RevertItem();

            mockRepository.VerifyAll();
        }

        [Test]
        public void SignupItem() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), false, assetCacheMock);
            var descriptor = new WorkitemDescriptor(workitemMock, new ColumnSetting[0], PropertyUpdateSource.WorkitemView, true);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(descriptor);
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.Signup);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.SignupItem();

            mockRepository.VerifyAll();
        }

        [Test]
        public void QuickCloseItem() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), false, assetCacheMock);
            var descriptor = new WorkitemDescriptor(workitemMock, new ColumnSetting[0], PropertyUpdateSource.WorkitemView, true);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(descriptor);
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.QuickClose);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.QuickCloseItem();

            mockRepository.VerifyAll();
        }

        [Test]
        public void CloseItem() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.Close);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.CloseItem(workitemMock);

            mockRepository.VerifyAll();
        }

        [Test]
        public void CloseItemValidationFailure() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.Close).Throw(new ValidatorException(null));
            Expect.Call(() => viewMock.ShowValidationInformationDialog(null)).IgnoreArguments();
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.CloseItem(workitemMock);

            mockRepository.VerifyAll();
        }

        [Test]
        public void CloseItemWithGenericDataLayerException() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(workitemMock.Close).Throw(new DataLayerException(null));
            Expect.Call(() => viewMock.ShowErrorMessage(null)).IgnoreArguments();
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();

            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.CloseItem(workitemMock);

            mockRepository.VerifyAll();
        }

        [Test]
        public void ModelChangedEvent() {
            ExpectRegisterAndPrepareView();

            Expect.Call(() => eventDispatcherMock.ModelChanged += null).IgnoreArguments();
            var raiser = LastCall.GetEventRaiser();

            mockRepository.ReplayAll();

            controller.Register(viewMock);
            controller.PrepareView();

            raiser.Raise(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.ProjectSelected));

            mockRepository.VerifyAll();
        }

        [Test]
        public void AddDefect() {
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);

            ExpectRegisterAndPrepareView();
            Expect.Call(dataLayerMock.CreateWorkitem(Entity.DefectType, null, assetCacheMock)).Return(workitemMock);
            Expect.Call(() => assetCacheMock.Add(workitemMock));
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.ProjectView, EventContext.WorkitemsChanged)));
            Expect.Call(() => viewMock.SelectWorkitem(workitemMock));
            Expect.Call(viewMock.Refresh);

            mockRepository.ReplayAll();
            controller.Register(viewMock);
            controller.PrepareView();
            controller.AddDefect();
            mockRepository.VerifyAll();
        }

        [Test]
        public void AddTask() {
            var parentWorkitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), true, assetCacheMock);
            var workitemMock = mockRepository.PartialMock<TestWorkitem>(Guid.NewGuid().ToString(), false, assetCacheMock);
            var descriptor = new WorkitemDescriptor(parentWorkitemMock, new ColumnSetting[0], PropertyUpdateSource.WorkitemView, true);
            TreeNodeAdv node = new TreeNodeAdv(null);

            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.CurrentWorkitemDescriptor).Return(descriptor);
            Expect.Call(dataLayerMock.CreateWorkitem(Entity.TaskType, parentWorkitemMock, assetCacheMock)).Return(workitemMock);
            Expect.Call(viewMock.CurrentNode).Return(node);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));
            Expect.Call(() => viewMock.SelectWorkitem(workitemMock));
            Expect.Call(viewMock.Refresh);

            mockRepository.ReplayAll();
            controller.Register(viewMock);
            controller.PrepareView();
            controller.AddTask();
            mockRepository.VerifyAll();
        }

        [Test]
        public void HandleFilteringByOwner() {
            const bool onlyMyTasks = true;

            ExpectRegisterAndPrepareView();
            Expect.Call(settingsMock.ShowMyTasks).PropertyBehavior();
            Expect.Call(settingsMock.StoreSettings);
            Expect.Call(dataLayerMock.ShowAllTasks).PropertyBehavior();
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)));

            mockRepository.ReplayAll();
            controller.Register(viewMock);
            controller.PrepareView();
            controller.HandleFilteringByOwner(onlyMyTasks);
            mockRepository.VerifyAll();
        }

        [Test]
        public void HandleSaveCommand() {
            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(() => dataLayerMock.CommitChanges(assetCacheMock));
            Expect.Call(assetCacheMock.Drop);
            Expect.Call(() => eventDispatcherMock.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsRequested)));

            mockRepository.ReplayAll();
            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.HandleSaveCommand();

            mockRepository.VerifyAll();
        }

        [Test]
        public void HandleSaveCommandValidationException() {
            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(() => dataLayerMock.CommitChanges(assetCacheMock)).Throw(new ValidatorException(null));
            Expect.Call(assetCacheMock.Drop).Repeat.Never();
            Expect.Call(() => viewMock.ShowValidationInformationDialog(null)).IgnoreArguments();

            mockRepository.ReplayAll();
            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.HandleSaveCommand();

            mockRepository.VerifyAll();
        }

        [Test]
        public void HandleSaveCommandGenericDataLayerException() {
            ExpectRegisterAndPrepareView();
            Expect.Call(viewMock.GetWaitCursor()).Return(waitCursorStub);
            Expect.Call(() => dataLayerMock.CommitChanges(assetCacheMock)).Throw(new DataLayerException(null));
            Expect.Call(assetCacheMock.Drop).Repeat.Never();
            Expect.Call(() => viewMock.ShowErrorMessage(null)).IgnoreArguments();
            Expect.Call(viewMock.ResetPropertyView);

            mockRepository.ReplayAll();
            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            controller.HandleSaveCommand();

            mockRepository.VerifyAll();
        }

        [Test]
        public void GetWorkitems() {
            var workitems = new List<Workitem>();

            ExpectRegisterAndPrepareView();
            Expect.Call(() => dataLayerMock.GetWorkitems(assetCacheMock));
            Expect.Call(settingsMock.ShowMyTasks).Return(false);
            Expect.Call(assetCacheMock.GetWorkitems(true)).Return(workitems);

            mockRepository.ReplayAll();
            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            var returnedWorkitems = controller.GetWorkitems();
            Assert.AreEqual(workitems, returnedWorkitems);

            mockRepository.VerifyAll();
        }

        [Test]
        public void GetWorkitemsFailure() {
            ExpectRegisterAndPrepareView();
            Expect.Call(() => dataLayerMock.GetWorkitems(assetCacheMock)).Throw(new DataLayerException(null));
            Expect.Call(() => viewMock.ShowErrorMessage(null)).IgnoreArguments();

            mockRepository.ReplayAll();
            controller = new TestWorkitemTreeController(loggerFactoryMock, dataLayerMock, configuration, settingsMock, eventDispatcherMock);
            controller.Register(viewMock);
            controller.PrepareView();
            var returnedWorkitems = controller.GetWorkitems();
            Assert.IsNull(returnedWorkitems);

            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Use it instead of original controller anytime you need to test async methods.
        /// </summary>
        private class TestWorkitemTreeController : WorkitemTreeController {
            internal TestWorkitemTreeController(ILoggerFactory loggerFactory, IDataLayer dataLayer, Configuration configuration, ISettings settings, IEventDispatcher eventDispatcher)
                : base(loggerFactory, dataLayer, configuration, settings, eventDispatcher) { }

            protected override ITaskRunner GetTaskRunner(IWaitCursor waitCursor) {
                return new SynchronousTaskRunner(waitCursor);
            }
        }
    }
}


text:
#ifndef AVIONICS_COMMON_SEPTENTRIO_SBF_H_
#define AVIONICS_COMMON_SEPTENTRIO_SBF_H_

#include <stdbool.h>
#include <stdint.h>

#include "avionics/common/septentrio_types.h"

bool SeptentrioSbfDecode(const SeptentrioHeader *hdr, const uint8_t *data,
                         SeptentrioBlock *blk);

#endif  // AVIONICS_COMMON_SEPTENTRIO_SBF_H_

redpajama_set_name: RedPajamaGithub


text:
#pragma once

#include <string>
#include <hyperscale/ast/expr.hpp>

namespace hyperscale {
namespace ast {

    class DeclRefExpr: public Expr {
    protected:
        std::string m_ref;

    public:
        /// Construct an DeclRefExpr node.
        DeclRefExpr(parser::Token& token);

        DeclRefExpr(const DeclRefExpr&) = delete;

        DeclRefExpr& operator=(const DeclRefExpr&) = delete;

        virtual ~DeclRefExpr() = default;

        std::string getRef();

        void accept(Visitor& visitor) override;
    };

} // end of ast namespace
} // end of hyperscale namespace


text:
package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"time"

	gh "github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	"github.com/miekg/dns"
	"github.com/polyverse-security/play-with-polyverse/config"
	"github.com/polyverse-security/play-with-polyverse/handlers"
	"github.com/polyverse-security/play-with-polyverse/templates"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"github.com/urfave/negroni"
)

func main() {

	config.ParseFlags()
	handlers.Bootstrap()

	bypassCaptcha := len(os.Getenv("GOOGLE_RECAPTCHA_DISABLED")) > 0

	// Start the DNS server
	dns.HandleFunc(".", handlers.DnsRequest)
	udpDnsServer := &dns.Server{Addr: ":53", Net: "udp"}
	go func() {
		err := udpDnsServer.ListenAndServe()
		if err != nil {
			log.Fatal(err)
		}
	}()
	tcpDnsServer := &dns.Server{Addr: ":53", Net: "tcp"}
	go func() {
		err := tcpDnsServer.ListenAndServe()
		if err != nil {
			log.Fatal(err)
		}
	}()

	server := handlers.Broadcast.GetHandler()

	r := mux.NewRouter()
	corsRouter := mux.NewRouter()

	// Reverse proxy (needs to be the first route, to make sure it is the first thing we check)
	//proxyHandler := handlers.NewMultipleHostReverseProxy()
	//websocketProxyHandler := handlers.NewMultipleHostWebsocketReverseProxy()

	tcpHandler := handlers.NewTCPProxy()

	corsHandler := gh.CORS(gh.AllowCredentials(), gh.AllowedHeaders([]string{"x-requested-with", "content-type"}), gh.AllowedOrigins([]string{"*"}))

	// Specific routes
	r.Host(fmt.Sprintf("{subdomain:.*}pwd{node:%s}-{port:%s}.{tld:.*}", config.PWDHostnameRegex, config.PortRegex)).Handler(tcpHandler)
	r.Host(fmt.Sprintf("{subdomain:.*}pwd{node:%s}.{tld:.*}", config.PWDHostnameRegex)).Handler(tcpHandler)
	r.Host(fmt.Sprintf("pwd{alias:%s}-{session:%s}-{port:%s}.{tld:.*}", config.AliasnameRegex, config.AliasSessionRegex, config.PortRegex)).Handler(tcpHandler)
	r.Host(fmt.Sprintf("pwd{alias:%s}-{session:%s}.{tld:.*}", config.AliasnameRegex, config.AliasSessionRegex)).Handler(tcpHandler)
	r.HandleFunc("/ping", handlers.Ping).Methods("GET")
	corsRouter.HandleFunc("/instances/images", handlers.GetInstanceImages).Methods("GET")
	corsRouter.HandleFunc("/sessions/{sessionId}", handlers.GetSession).Methods("GET")
	corsRouter.HandleFunc("/sessions/{sessionId}/setup", handlers.SessionSetup).Methods("POST")
	corsRouter.HandleFunc("/sessions/{sessionId}/instances", handlers.NewInstance).Methods("POST")
	corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}/uploads", handlers.FileUpload).Methods("POST")
	corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}", handlers.DeleteInstance).Methods("DELETE")
	corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}/exec", handlers.Exec).Methods("POST")

	r.HandleFunc("/p/{sessionId}", handlers.Home).Methods("GET")
	r.PathPrefix("/assets").Handler(http.FileServer(http.Dir("./www")))
	r.HandleFunc("/robots.txt", func(rw http.ResponseWriter, r *http.Request) {
		http.ServeFile(rw, r, "www/robots.txt")
	})
	r.HandleFunc("/sdk.js", func(rw http.ResponseWriter, r *http.Request) {
		http.ServeFile(rw, r, "www/sdk.js")
	})

	corsRouter.Handle("/sessions/{sessionId}/ws/", server)
	r.Handle("/metrics", promhttp.Handler())

	// Generic routes
	r.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
		if bypassCaptcha {
			http.ServeFile(rw, r, "./www/bypass.html")
		} else {
			welcome, tmplErr := templates.GetWelcomeTemplate()
			if tmplErr != nil {
				log.Fatal(tmplErr)
			}
			rw.Write(welcome)
		}
	}).Methods("GET")

	corsRouter.HandleFunc("/", handlers.NewSession).Methods("POST")

	n := negroni.Classic()
	r.PathPrefix("/").Handler(negroni.New(negroni.Wrap(corsHandler(corsRouter))))
	n.UseHandler(r)

	httpServer := http.Server{
		Addr:              "0.0.0.0:" + config.PortNumber,
		Handler:           n,
		IdleTimeout:       30 * time.Second,
		ReadHeaderTimeout: 5 * time.Second,
	}

	go func() {
		log.Println("Listening on port " + config.PortNumber)
		log.Fatal(httpServer.ListenAndServe())
	}()

	go handlers.ListenSSHProxy("0.0.0.0:1022")

	// Now listen for TLS connections that need to be proxied
	handlers.StartTLSProxy(config.SSLPortNumber)
}


text:
A `BrowserView` can be used to embed additional web content into a
[`BrowserWindow`](browser-window.md). It is like a child window, except that it is positioned
relative to its owning window. It is meant to be an alternative to the
`webview` tag.

## Class: BrowserView

> Create and control views.

Process: [Main](../glossary.md#main-process)

This module cannot be used until the `ready` event of the `app`
module is emitted.

### Example

```javascript
// In the main process.
const { app, BrowserView, BrowserWindow } = require('electron')

app.whenReady().then(() => {
  const win = new BrowserWindow({ width: 800, height: 600 })

  const view = new BrowserView()
  win.setBrowserView(view)
  view.setBounds({ x: 0, y: 0, width: 300, height: 300 })
  view.webContents.loadURL('https://electronjs.org')
})
```

### `new BrowserView([options])` _Experimental_

* `options` Object (optional)
  * `webPreferences` Object (optional) - See [BrowserWindow](browser-window.md).

### Instance Properties

Objects created with `new BrowserView` have the following properties:

#### `view.webContents` _Experimental_

A [`WebContents`](web-contents.md) object owned by this view.

### Instance Methods

Objects created with `new BrowserView` have the following instance methods:

#### `view.setAutoResize(options)` _Experimental_

* `options` Object
  * `width` boolean (optional) - If `true`, the view's width will grow and shrink together
    with the window. `false` by default.
  * `height` boolean (optional) - If `true`, the view's height will grow and shrink
    together with the window. `false` by default.
  * `horizontal` boolean (optional) - If `true`, the view's x position and width will grow
    and shrink proportionally with the window. `false` by default.
  * `vertical` boolean (optional) - If `true`, the view's y position and height will grow
    and shrink proportionally with the window. `false` by default.

#### `view.setBounds(bounds)` _Experimental_

* `bounds` [Rectangle](structures/rectangle.md)

Resizes and moves the view to the supplied bounds relative to the window.

#### `view.getBounds()` _Experimental_

Returns [`Rectangle`](structures/rectangle.md)

The `bounds` of this BrowserView instance as `Object`.

#### `view.setBackgroundColor(color)` _Experimental_

* `color` string - Color in Hex, RGB, ARGB, HSL, HSLA or named CSS color format. The alpha channel is
  optional for the hex type.

Examples of valid `color` values:

* Hex
  * #fff (RGB)
  * #ffff (ARGB)
  * #ffffff (RRGGBB)
  * #ffffffff (AARRGGBB)
* RGB
  * rgb\(([\d]+),\s*([\d]+),\s*([\d]+)\)
    * e.g. rgb(255, 255, 255)
* RGBA
  * rgba\(([\d]+),\s*([\d]+),\s*([\d]+),\s*([\d.]+)\)
    * e.g. rgba(255, 255, 255, 1.0)
* HSL
  * hsl\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%\)
    * e.g. hsl(200, 20%, 50%)
* HSLA
  * hsla\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)
    * e.g. hsla(200, 20%, 50%, 0.5)
* Color name
  * Options are listed in [SkParseColor.cpp](https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/utils/SkParseColor.cpp;l=11-152;drc=eea4bf52cb0d55e2a39c828b017c80a5ee054148)
  * Similar to CSS Color Module Level 3 keywords, but case-sensitive.
    * e.g. `blueviolet` or `red`

**Note:** Hex format with alpha takes `AARRGGBB` or `ARGB`, _not_ `RRGGBBA` or `RGA`.


text:
class Admin::ResourceController < AdminController

  before_filter :check_if_user_can_perform_action_on_resource

  def index
  end

end


text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE preface PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
                 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">

<chapter id="fundamentals">
    <title>Fundamentals</title>

        <title>Request execution</title>
        <para> The most essential function of HttpClient is to execute HTTP methods. Execution of an
            HTTP method involves one or several HTTP request / HTTP response exchanges, usually
            handled internally by HttpClient. The user is expected to provide a request object to
            execute and HttpClient is expected to transmit the request to the target server return a
            corresponding response object, or throw an exception if execution was unsuccessful. </para>
        <para> Quite naturally, the main entry point of the HttpClient API is the HttpClient
            interface that defines the contract described above. </para>
        <para>Here is an example of request execution process in its simplest form:</para>
        <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/");
CloseableHttpResponse response = httpclient.execute(httpget);
try {
    <...>
} finally {
    response.close();
}
]]></programlisting>

            <title>HTTP request</title>
            <para>All HTTP requests have a request line consisting a method name, a request URI and
                an HTTP protocol version.</para>
            <para>HttpClient supports out of the box all HTTP methods defined in the HTTP/1.1
                specification: <literal>GET</literal>, <literal>HEAD</literal>,
                    <literal>POST</literal>, <literal>PUT</literal>, <literal>DELETE</literal>,
                    <literal>TRACE</literal> and <literal>OPTIONS</literal>. There is a specific
                class for each method type.: <classname>HttpGet</classname>,
                    <classname>HttpHead</classname>, <classname>HttpPost</classname>,
                    <classname>HttpPut</classname>, <classname>HttpDelete</classname>,
                    <classname>HttpTrace</classname>, and <classname>HttpOptions</classname>.</para>
            <para>The Request-URI is a Uniform Resource Identifier that identifies the resource upon
                which to apply the request. HTTP request URIs consist of a protocol scheme, host
                name, optional port, resource path, optional query, and optional fragment.</para>
            <programlisting><![CDATA[
HttpGet httpget = new HttpGet(
     "http://www.google.com/search?hl=en&q=httpclient&btnG=Google+Search&aq=f&oq=");
]]></programlisting>
            <para>HttpClient provides <classname>URIBuilder</classname> utility class to simplify
                creation and modification of request URIs.</para>
            <programlisting><![CDATA[
URI uri = new URIBuilder()
        .setScheme("http")
        .setHost("www.google.com")
        .setPath("/search")
        .setParameter("q", "httpclient")
        .setParameter("btnG", "Google Search")
        .setParameter("aq", "f")
        .setParameter("oq", "")
        .build();
HttpGet httpget = new HttpGet(uri);
System.out.println(httpget.getURI());
]]></programlisting>
            <para>stdout ></para>
            <programlisting><![CDATA[
http://www.google.com/search?q=httpclient&btnG=Google+Search&aq=f&oq=
]]></programlisting>

            <title>HTTP response</title>
            <para>HTTP response is a message sent by the server back to the client after having
                received and interpreted a request message. The first line of that message consists
                of the protocol version followed by a numeric status code and its associated textual
                phrase.</para>
            <programlisting><![CDATA[
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
HttpStatus.SC_OK, "OK");

System.out.println(response.getProtocolVersion());
System.out.println(response.getStatusLine().getStatusCode());
System.out.println(response.getStatusLine().getReasonPhrase());
System.out.println(response.getStatusLine().toString());
]]></programlisting>
            <para>stdout ></para>
            <programlisting><![CDATA[
HTTP/1.1
200
OK
HTTP/1.1 200 OK
]]></programlisting>

            <title>Working with message headers</title>
            <para>An HTTP message can contain a number of headers describing properties of the
                message such as the content length, content type and so on. HttpClient provides
                methods to retrieve, add, remove and enumerate headers.</para>
            <programlisting><![CDATA[
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
    HttpStatus.SC_OK, "OK");
response.addHeader("Set-Cookie",
    "c1=a; path=/; domain=localhost");
response.addHeader("Set-Cookie",
    "c2=b; path=\"/\", c3=c; domain=\"localhost\"");
Header h1 = response.getFirstHeader("Set-Cookie");
System.out.println(h1);
Header h2 = response.getLastHeader("Set-Cookie");
System.out.println(h2);
Header[] hs = response.getHeaders("Set-Cookie");
System.out.println(hs.length);
]]></programlisting>
            <para>stdout ></para>
            <programlisting><![CDATA[
Set-Cookie: c1=a; path=/; domain=localhost
Set-Cookie: c2=b; path="/", c3=c; domain="localhost"
2
]]></programlisting>
            <para>The most efficient way to obtain all headers of a given type is by using the
                    <interfacename>HeaderIterator</interfacename> interface.</para>
            <programlisting><![CDATA[
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
    HttpStatus.SC_OK, "OK");
response.addHeader("Set-Cookie",
    "c1=a; path=/; domain=localhost");
response.addHeader("Set-Cookie",
    "c2=b; path=\"/\", c3=c; domain=\"localhost\"");

HeaderIterator it = response.headerIterator("Set-Cookie");

while (it.hasNext()) {
    System.out.println(it.next());
}
]]></programlisting>
            <para>stdout ></para>
            <programlisting><![CDATA[
Set-Cookie: c1=a; path=/; domain=localhost
Set-Cookie: c2=b; path="/", c3=c; domain="localhost"
]]></programlisting>
            <para>It also provides convenience methods to parse HTTP messages into individual header
                elements.</para>
            <programlisting><![CDATA[
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
    HttpStatus.SC_OK, "OK");
response.addHeader("Set-Cookie",
    "c1=a; path=/; domain=localhost");
response.addHeader("Set-Cookie",
    "c2=b; path=\"/\", c3=c; domain=\"localhost\"");

HeaderElementIterator it = new BasicHeaderElementIterator(
    response.headerIterator("Set-Cookie"));

while (it.hasNext()) {
    HeaderElement elem = it.nextElement();
    System.out.println(elem.getName() + " = " + elem.getValue());
    NameValuePair[] params = elem.getParameters();
    for (int i = 0; i < params.length; i++) {
        System.out.println(" " + params[i]);
    }
}
]]></programlisting>
            <para>stdout ></para>
            <programlisting><![CDATA[
c1 = a
path=/
domain=localhost
c2 = b
path=/
c3 = c
domain=localhost
]]></programlisting>

            <title>HTTP entity</title>
            <para>HTTP messages can carry a content entity associated with the request or response.
                Entities can be found in some requests and in some responses, as they are optional.
                Requests that use entities are referred to as entity enclosing requests. The HTTP
                specification defines two entity enclosing request methods: <literal>POST</literal> and
                    <literal>PUT</literal>. Responses are usually expected to enclose a content
                entity. There are exceptions to this rule such as responses to
                    <literal>HEAD</literal> method and <literal>204 No Content</literal>,
                    <literal>304 Not Modified</literal>, <literal>205 Reset Content</literal>
                responses.</para>
            <para>HttpClient distinguishes three kinds of entities, depending on where their content
                originates:</para>
            <itemizedlist>
                <listitem>
                    <formalpara>
                        <title>streamed:</title>
                        <para>The content is received from a stream, or generated on the fly. In
                            particular, this category includes entities being received from HTTP
                            responses. Streamed entities are generally not repeatable.</para>
                    </formalpara>
                </listitem>
                <listitem>
                    <formalpara>
                        <title>self-contained:</title>
                        <para>The content is in memory or obtained by means that are independent
                            from a connection or other entity. Self-contained entities are generally
                            repeatable. This type of entities will be mostly used for entity
                            enclosing HTTP requests.</para>
                    </formalpara>
                </listitem>
                <listitem>
                    <formalpara>
                        <title>wrapping:</title>
                        <para>The content is obtained from another entity.</para>
                    </formalpara>
                </listitem>
            </itemizedlist>
            <para>This distinction is important for connection management when streaming out content
                from an HTTP response. For request entities that are created by an application and
                only sent using HttpClient, the difference between streamed and self-contained is of
                little importance. In that case, it is suggested to consider non-repeatable entities
                as streamed, and those that are repeatable as self-contained.</para>

                <title>Repeatable entities</title>
                <para>An entity can be repeatable, meaning its content can be read more than once.
                    This is only possible with self contained entities (like
                        <classname>ByteArrayEntity</classname> or
                        <classname>StringEntity</classname>)</para>

                <title>Using HTTP entities</title>
                <para>Since an entity can represent both binary and character content, it has
                    support for character encodings (to support the latter, ie. character
                    content).</para>
                <para>The entity is created when executing a request with enclosed content or when
                    the request was successful and the response body is used to send the result back
                    to the client.</para>
                <para>To read the content from the entity, one can either retrieve the input stream
                    via the <methodname>HttpEntity#getContent()</methodname> method, which returns
                    an <classname>java.io.InputStream</classname>, or one can supply an output
                    stream to the <methodname>HttpEntity#writeTo(OutputStream)</methodname> method,
                    which will return once all content has been written to the given stream.</para>
                <para>When the entity has been received with an incoming message, the methods
                        <methodname>HttpEntity#getContentType()</methodname> and
                        <methodname>HttpEntity#getContentLength()</methodname> methods can be used
                    for reading the common metadata such as <literal>Content-Type</literal> and
                        <literal>Content-Length</literal> headers (if they are available). Since the
                        <literal>Content-Type</literal> header can contain a character encoding for
                    text mime-types like text/plain or text/html, the
                        <methodname>HttpEntity#getContentEncoding()</methodname> method is used to
                    read this information. If the headers aren't available, a length of -1 will be
                    returned, and NULL for the content type. If the <literal>Content-Type</literal>
                    header is available, a <interfacename>Header</interfacename> object will be
                    returned.</para>
                <para>When creating an entity for a outgoing message, this meta data has to be
                    supplied by the creator of the entity.</para>
                <programlisting><![CDATA[
StringEntity myEntity = new StringEntity("important message",
   ContentType.create("text/plain", "UTF-8"));

System.out.println(myEntity.getContentType());
System.out.println(myEntity.getContentLength());
System.out.println(EntityUtils.toString(myEntity));
System.out.println(EntityUtils.toByteArray(myEntity).length);]]></programlisting>
                <para>stdout ></para>
                <programlisting><![CDATA[
Content-Type: text/plain; charset=utf-8
17
important message
17
]]></programlisting>

            <title>Ensuring release of low level resources</title>
            <para> In order to ensure proper release of system resources one must close either
                the content stream associated with the entity or the response itself</para>
            <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/");
CloseableHttpResponse response = httpclient.execute(httpget);
try {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        try {
            // do something useful
        } finally {
            instream.close();
        }
    }
} finally {
    response.close();
}
]]></programlisting>
            <para>The difference between closing the content stream and closing the response
                is that the former will attempt to keep the underlying connection alive
                by consuming the entity content while the latter immediately shuts down
                and discards the connection.</para>
            <para>Please note that the <methodname>HttpEntity#writeTo(OutputStream)</methodname>
                method is also required to ensure proper release of system resources once the
                entity has been fully written out. If this method obtains an instance of
                <classname>java.io.InputStream</classname> by calling
                <methodname>HttpEntity#getContent()</methodname>, it is also expected to close
                the stream in a finally clause.</para>
            <para>When working with streaming entities, one can use the
                <methodname>EntityUtils#consume(HttpEntity)</methodname> method to ensure that
                the entity content has been fully consumed and the underlying stream has been
                closed.</para>
            <para>There can be situations, however, when only a small portion of the entire response
                content needs to be retrieved and the performance penalty for consuming the
                remaining content and making the connection reusable is too high, in which case
                one can terminate the content stream by closing the response.</para>
            <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/");
CloseableHttpResponse response = httpclient.execute(httpget);
try {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        int byteOne = instream.read();
        int byteTwo = instream.read();
        // Do not need the rest
    }
} finally {
    response.close();
}
]]></programlisting>
            <para>The connection will not be reused, but all level resources held by it will be
                correctly deallocated.</para>

            <title>Consuming entity content</title>
            <para>The recommended way to consume the content of an entity is by using its
                    <methodname>HttpEntity#getContent()</methodname> or
                    <methodname>HttpEntity#writeTo(OutputStream)</methodname> methods. HttpClient
                also comes with the <classname>EntityUtils</classname> class, which exposes several
                static methods to more easily read the content or information from an entity.
                Instead of reading the <classname>java.io.InputStream</classname> directly, one can
                retrieve the whole content body in a string / byte array by using the methods from
                this class. However, the use of <classname>EntityUtils</classname> is
                strongly discouraged unless the response entities originate from a trusted HTTP
                server and are known to be of limited length.</para>
            <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/");
CloseableHttpResponse response = httpclient.execute(httpget);
try {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        long len = entity.getContentLength();
        if (len != -1 && len < 2048) {
            System.out.println(EntityUtils.toString(entity));
        } else {
            // Stream content out
        }
    }
} finally {
    response.close();
}
]]></programlisting>
            <para>In some situations it may be necessary to be able to read entity content more than
                once. In this case entity content must be buffered in some way, either in memory or
                on disk. The simplest way to accomplish that is by wrapping the original entity with
                the <classname>BufferedHttpEntity</classname> class. This will cause the content of
                the original entity to be read into a in-memory buffer. In all other ways the entity
                wrapper will be have the original one.</para>
            <programlisting><![CDATA[
CloseableHttpResponse response = <...>
HttpEntity entity = response.getEntity();
if (entity != null) {
    entity = new BufferedHttpEntity(entity);
}
]]></programlisting>

            <title>Producing entity content</title>
            <para>HttpClient provides several classes that can be used to efficiently stream out
                content throught HTTP connections. Instances of those classes can be associated with
                entity enclosing requests such as <literal>POST</literal> and <literal>PUT</literal>
                in order to enclose entity content into outgoing HTTP requests. HttpClient provides
                several classes for most common data containers such as string, byte array, input
                stream, and file: <classname>StringEntity</classname>,
                    <classname>ByteArrayEntity</classname>,
                <classname>InputStreamEntity</classname>, and
                <classname>FileEntity</classname>.</para>
            <programlisting><![CDATA[
File file = new File("somefile.txt");
FileEntity entity = new FileEntity(file,
    ContentType.create("text/plain", "UTF-8"));

HttpPost httppost = new HttpPost("http://localhost/action.do");
httppost.setEntity(entity);
]]></programlisting>
            <para>Please note <classname>InputStreamEntity</classname> is not repeatable, because it
                can only read from the underlying data stream once. Generally it is recommended to
                implement a custom <interfacename>HttpEntity</interfacename> class which is
                self-contained instead of using the generic <classname>InputStreamEntity</classname>.
                    <classname>FileEntity</classname> can be a good starting point.</para>

                <title>HTML forms</title>
                <para>Many applications need to simulate the process of submitting an
                    HTML form, for instance, in order to log in to a web application or submit input
                    data. HttpClient provides the entity class
                        <classname>UrlEncodedFormEntity</classname> to facilitate the
                    process.</para>
                <programlisting><![CDATA[
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("param1", "value1"));
formparams.add(new BasicNameValuePair("param2", "value2"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
HttpPost httppost = new HttpPost("http://localhost/handler.do");
httppost.setEntity(entity);
]]></programlisting>
                <para>The <classname>UrlEncodedFormEntity</classname> instance will use the so
                    called URL encoding to encode parameters and produce the following
                    content:</para>
                <programlisting><![CDATA[
param1=value1&param2=value2
]]></programlisting>

                <title>Content chunking</title>
                <para>Generally it is recommended to let HttpClient choose the most appropriate
                    transfer encoding based on the properties of the HTTP message being transferred.
                    It is possible, however, to inform HttpClient that chunk coding is preferred
                    by setting <methodname>HttpEntity#setChunked()</methodname> to true. Please note
                    that HttpClient will use this flag as a hint only. This value will be ignored
                    when using HTTP protocol versions that do not support chunk coding, such as
                    HTTP/1.0.</para>
                <programlisting><![CDATA[
StringEntity entity = new StringEntity("important message",
        ContentType.create("plain/text", Consts.UTF_8));
entity.setChunked(true);
HttpPost httppost = new HttpPost("http://localhost/acrtion.do");
httppost.setEntity(entity);
]]></programlisting>

            <title>Response handlers</title>
            <para>The simplest and the most convenient way to handle responses is by using
                the <interfacename>ResponseHandler</interfacename> interface, which includes
                the <methodname>handleResponse(HttpResponse response)</methodname> method.
                This method completely
                relieves the user from having to worry about connection management. When using a
                    <interfacename>ResponseHandler</interfacename>, HttpClient will automatically
                take care of ensuring release of the connection back to the connection manager
                regardless whether the request execution succeeds or causes an exception.</para>
            <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/json");

ResponseHandler<MyJsonObject> rh = new ResponseHandler<MyJsonObject>() {

    @Override
    public JsonObject handleResponse(
            final HttpResponse response) throws IOException {
        StatusLine statusLine = response.getStatusLine();
        HttpEntity entity = response.getEntity();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(
                    statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }
        if (entity == null) {
            throw new ClientProtocolException("Response contains no content");
        }
        Gson gson = new GsonBuilder().create();
        ContentType contentType = ContentType.getOrDefault(entity);
        Charset charset = contentType.getCharset();
        Reader reader = new InputStreamReader(entity.getContent(), charset);
        return gson.fromJson(reader, MyJsonObject.class);
    }
};
MyJsonObject myjson = client.execute(httpget, rh);
]]></programlisting>

        <title>HttpClient interface</title>
        <para><interfacename>HttpClient</interfacename> interface represents the most essential
            contract for HTTP request execution. It imposes no restrictions or particular details on
            the request execution process and leaves the specifics of connection management, state
            management, authentication and redirect handling up to individual implementations. This
            should make it easier to decorate the interface with additional functionality such as
            response content caching.</para>
        <para>Generally <interfacename>HttpClient</interfacename> implementations act as a facade
            to a number of special purpose handler or strategy interface implementations
            responsible for handling of a particular aspect of the HTTP protocol such as redirect
            or authentication handling or making decision about connection persistence and keep
            alive duration. This enables the users to selectively replace default implementation
            of those aspects with custom, application specific ones.</para>
        <programlisting><![CDATA[
ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy() {

    @Override
    public long getKeepAliveDuration(
            HttpResponse response,
            HttpContext context) {
        long keepAlive = super.getKeepAliveDuration(response, context);
        if (keepAlive == -1) {
            // Keep connections alive 5 seconds if a keep-alive value
            // has not be explicitly set by the server
            keepAlive = 5000;
        }
        return keepAlive;
    }

};
CloseableHttpClient httpclient = HttpClients.custom()
        .setKeepAliveStrategy(keepAliveStrat)
        .build();
]]></programlisting>

            <title>HttpClient thread safety</title>
            <para><interfacename>HttpClient</interfacename> implementations are expected to be
                thread safe. It is recommended that the same instance of this class is reused for
                multiple request executions.</para>

            <title>HttpClient resource deallocation</title>
            <para>When an instance <classname>CloseableHttpClient</classname> is no longer needed
                and is about to go out of scope the connection manager associated with it must
                be shut down by calling the <methodname>CloseableHttpClient#close()</methodname>
                method.</para>
            <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
    <...>
} finally {
    httpclient.close();
}
]]></programlisting>

        <title>HTTP execution context</title>
        <para>Originally HTTP has been designed as a stateless, response-request oriented protocol.
            However, real world applications often need to be able to persist state information
            through several logically related request-response exchanges. In order to enable
            applications to maintain a processing state HttpClient allows HTTP requests to be
            executed within a particular execution context, referred to as HTTP context. Multiple
            logically related requests can participate in a logical session if the same context is
            reused between consecutive requests. HTTP context functions similarly to
            a  <interfacename>java.util.Map<String, Object></interfacename>. It is
            simply a collection of arbitrary named values. An application can populate context
            attributes prior to request execution or examine the context after the execution has
            been completed.</para>
        <para><interfacename>HttpContext</interfacename> can contain arbitrary objects and
            therefore may be unsafe to share between multiple threads. It is recommended that
            each thread of execution maintains its own context.</para>
        <para>In the course of HTTP request execution HttpClient adds the following attributes to
            the execution context:</para>
        <itemizedlist>
            <listitem>
                <formalpara>
                    <para><interfacename>HttpConnection</interfacename> instance representing the
                        actual connection to the target server.</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><classname>HttpHost</classname> instance representing the connection
                        target.</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><classname>HttpRoute</classname> instance representing the complete
                        connection route</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><interfacename>HttpRequest</interfacename> instance representing the
                        actual HTTP request. The final HttpRequest object in the execution context
                        always represents the state of the message <emphasis>exactly</emphasis>
                        as it was sent to the target server. Per default HTTP/1.0 and HTTP/1.1
                        use relative request URIs. However if the request is sent via a proxy
                        in a non-tunneling mode then the URI will be absolute.</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><interfacename>HttpResponse</interfacename> instance representing the
                        actual HTTP response.</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><classname>java.lang.Boolean</classname> object representing the flag
                        indicating whether the actual request has been fully transmitted to the
                        connection target.</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><classname>RequestConfig</classname> object representing the actual
                        request configuation.</para>
                </formalpara>
            </listitem>
            <listitem>
                <formalpara>
                    <para><classname>java.util.List<URI></classname> object representing a collection
                        of all redirect locations received in the process of request
                        execution.</para>
                </formalpara>
            </listitem>
        </itemizedlist>
        <para>One can use <classname>HttpClientContext</classname> adaptor class to simplify
            interractions with the context state.</para>
        <programlisting><![CDATA[
HttpContext context = <...>
HttpClientContext clientContext = HttpClientContext.adapt(context);
HttpHost target = clientContext.getTargetHost();
HttpRequest request = clientContext.getRequest();
HttpResponse response = clientContext.getResponse();
RequestConfig config = clientContext.getRequestConfig();
]]></programlisting>
        <para>Multiple request sequences that represent a logically related session should be
            executed with the same <interfacename>HttpContext</interfacename> instance to ensure
            automatic propagation of conversation context and state information between
            requests.</para>
        <para>In the following example the request configuration set by the initial request will be
            kept in the execution context and get propagated to the consecutive requests sharing
            the same context.</para>
        <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom()
        .setSocketTimeout(1000)
        .setConnectTimeout(1000)
        .build();

HttpGet httpget1 = new HttpGet("http://localhost/1");
httpget1.setConfig(requestConfig);
CloseableHttpResponse response1 = httpclient.execute(httpget1, context);
try {
    HttpEntity entity1 = response1.getEntity();
} finally {
    response1.close();
}
HttpGet httpget2 = new HttpGet("http://localhost/2");
CloseableHttpResponse response2 = httpclient.execute(httpget2, context);
try {
    HttpEntity entity2 = response2.getEntity();
} finally {
    response2.close();
}
]]></programlisting>

    <title>HTTP protocol interceptors</title>
    <para>The HTTP protocol interceptor is a routine that implements a specific aspect of the HTTP
      protocol. Usually protocol interceptors are expected to act upon one specific header or
      a group of related headers of the incoming message, or populate the outgoing message with
      one specific header or a group of related headers. Protocol interceptors can also
      manipulate content entities enclosed with messages - transparent content compression /
      decompression being a good example. Usually this is accomplished by using the
      'Decorator' pattern where a wrapper entity class is used to decorate the original
      entity. Several protocol interceptors can be combined to form one logical unit.</para>
    <para>Protocol interceptors can collaborate by sharing information - such as a processing
      state - through the HTTP execution context. Protocol interceptors can use HTTP context
      to store a processing state for one request or several consecutive requests.</para>
    <para>Usually the order in which interceptors are executed should not matter as long as they
      do not depend on a particular state of the execution context. If protocol interceptors
      have interdependencies and therefore must be executed in a particular order, they should
      be added to the protocol processor in the same sequence as their expected execution
      order.</para>
    <para>Protocol interceptors must be implemented as thread-safe. Similarly to servlets,
      protocol interceptors should not use instance variables unless access to those variables
      is synchronized.</para>
    <para>This is an example of how local context can be used to persist a processing state
      between consecutive requests:</para>
    <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.custom()
        .addInterceptorLast(new HttpRequestInterceptor() {

            public void process(
                    final HttpRequest request,
                    final HttpContext context) throws HttpException, IOException {
                AtomicInteger count = (AtomicInteger) context.getAttribute("count");
                request.addHeader("Count", Integer.toString(count.getAndIncrement()));
            }

        })
        .build();

AtomicInteger count = new AtomicInteger(1);
HttpClientContext localContext = HttpClientContext.create();
localContext.setAttribute("count", count);

HttpGet httpget = new HttpGet("http://localhost/");
for (int i = 0; i < 10; i++) {
    CloseableHttpResponse response = httpclient.execute(httpget, localContext);
    try {
        HttpEntity entity = response.getEntity();
    } finally {
        response.close();
    }
}
]]></programlisting>

        <title>Exception handling</title>
        <para>HTTP protocol processors can throw two types of exceptions:
            <exceptionname>java.io.IOException</exceptionname> in case of an I/O failure such as
            socket timeout or an socket reset and <exceptionname>HttpException</exceptionname> that
            signals an HTTP failure such as a violation of the HTTP protocol. Usually I/O errors are
            considered non-fatal and recoverable, whereas HTTP protocol errors are considered fatal
            and cannot be automatically recovered from. Please note that <interfacename>HttpClient
            </interfacename> implementations re-throw <exceptionname>HttpException</exceptionname>s
            as <exceptionname>ClientProtocolException</exceptionname>, which is a subclass
            of <exceptionname>java.io.IOException</exceptionname>. This enables the users
            of <interfacename>HttpClient</interfacename> to handle both I/O errors and protocol
            violations from a single catch clause.</para>

            <title>HTTP transport safety</title>
            <para>It is important to understand that the HTTP protocol is not well suited to all
                types of applications. HTTP is a simple request/response oriented protocol which was
                initially designed to support static or dynamically generated content retrieval. It
                has never been intended to support transactional operations. For instance, the HTTP
                server will consider its part of the contract fulfilled if it succeeds in receiving
                and processing the request, generating a response and sending a status code back to
                the client. The server will make no attempt to roll back the transaction if the
                client fails to receive the response in its entirety due to a read timeout, a
                request cancellation or a system crash. If the client decides to retry the same
                request, the server will inevitably end up executing the same transaction more than
                once. In some cases this may lead to application data corruption or inconsistent
                application state.</para>
            <para>Even though HTTP has never been designed to support transactional processing, it
                can still be used as a transport protocol for mission critical applications provided
                certain conditions are met. To ensure HTTP transport layer safety the system must
                ensure the idempotency of HTTP methods on the application layer.</para>

            <title>Idempotent methods</title>
            <para>HTTP/1.1 specification defines an idempotent method as</para>
            <para>
                <citation>Methods can also have the property of "idempotence" in
                    that (aside from error or expiration issues) the side-effects of N > 0
                    identical requests is the same as for a single request</citation>
            </para>
            <para>In other words the application ought to ensure that it is prepared to deal with
                the implications of multiple execution of the same method. This can be achieved, for
                instance, by providing a unique transaction id and by other means of avoiding
                execution of the same logical operation.</para>
            <para>Please note that this problem is not specific to HttpClient. Browser based
                applications are subject to exactly the same issues related to HTTP methods
                non-idempotency.</para>
            <para>By default HttpClient assumes only non-entity enclosing methods such as
                <literal>GET</literal> and <literal>HEAD</literal> to be idempotent and entity
                enclosing methods such as <literal>POST</literal> and <literal>PUT</literal> to be
                not for compatibility reasons.</para>

            <title>Automatic exception recovery</title>
            <para>By default HttpClient attempts to automatically recover from I/O exceptions. The
                default auto-recovery mechanism is limited to just a few exceptions that are known
                to be safe.</para>
            <itemizedlist>
                <listitem>
                    <para>HttpClient will make no attempt to recover from any logical or HTTP
                        protocol errors (those derived from
                            <exceptionname>HttpException</exceptionname> class).</para>
                </listitem>
                <listitem>
                    <para>HttpClient will automatically retry those methods that are assumed to be
                        idempotent.</para>
                </listitem>
                <listitem>
                    <para>HttpClient will automatically retry those methods that fail with a
                        transport exception while the HTTP request is still being transmitted to the
                        target server (i.e. the request has not been fully transmitted to the
                        server).</para>
                </listitem>
            </itemizedlist>

            <title>Request retry handler</title>
            <para>In order to enable a custom exception recovery mechanism one should provide an
                implementation of the <interfacename>HttpRequestRetryHandler</interfacename>
                interface.</para>
            <programlisting><![CDATA[
HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {

    public boolean retryRequest(
            IOException exception,
            int executionCount,
            HttpContext context) {
        if (executionCount >= 5) {
            // Do not retry if over max retry count
            return false;
        }
        if (exception instanceof InterruptedIOException) {
            // Timeout
            return false;
        }
        if (exception instanceof UnknownHostException) {
            // Unknown host
            return false;
        }
        if (exception instanceof ConnectTimeoutException) {
            // Connection refused
            return false;
        }
        if (exception instanceof SSLException) {
            // SSL handshake exception
            return false;
        }
        HttpClientContext clientContext = HttpClientContext.adapt(context);
        HttpRequest request = clientContext.getRequest();
        boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
        if (idempotent) {
            // Retry if the request is considered idempotent
            return true;
        }
        return false;
    }

};
CloseableHttpClient httpclient = HttpClients.custom()
        .setRetryHandler(myRetryHandler)
        .build();
]]></programlisting>
          <para>Please note that one can use <classname>StandardHttpRequestRetryHandler</classname>
              instead of the one used by default in order to treat those request methods defined
              as idempotent by RFC-2616 as safe to retry automatically: <literal>GET</literal>,
              <literal>HEAD</literal>, <literal>PUT</literal>, <literal>DELETE</literal>, <literal>
              OPTIONS</literal>, and <literal>TRACE</literal>.</para>

        <title>Aborting requests</title>
        <para>In some situations HTTP request execution fails to complete within the expected time
            frame due to high load on the target server or too many concurrent requests issued on
            the client side. In such cases it may be necessary to terminate the request prematurely
            and unblock the execution thread blocked in a I/O operation. HTTP requests being
            executed by HttpClient can be aborted at any stage of execution by invoking
                <methodname>HttpUriRequest#abort()</methodname> method. This method is thread-safe
            and can be called from any thread. When an HTTP request is aborted its execution thread
            - even if currently blocked in an I/O operation - is guaranteed to unblock by throwing a
                <exceptionname>InterruptedIOException</exceptionname></para>

        <title>Redirect handling</title>
        <para>HttpClient handles all types of redirects automatically, except those explicitly
            prohibited by the HTTP specification as requiring user intervention. <literal>See
                Other</literal> (status code 303) redirects on <literal>POST</literal> and
            <literal>PUT</literal> requests are converted to <literal>GET</literal> requests as
            required by the HTTP specification. One can use a custom redirect strategy to relaxe
            restrictions on automatic redirection of POST methods imposed by the HTTP
            specification.</para>
        <programlisting><![CDATA[
LaxRedirectStrategy redirectStrategy = new LaxRedirectStrategy();
CloseableHttpClient httpclient = HttpClients.custom()
        .setRedirectStrategy(redirectStrategy)
        .build();
]]></programlisting>
        <para>HttpClient often has to rewrite the request message in the process of its execution.
            Per default HTTP/1.0 and HTTP/1.1 generally use relative request URIs. Likewise,
            original request may get redirected from location to another multiple times. The final
            interpreted absolute HTTP location can be built using the original request and
            the context. The utility method <classname>URIUtils#resolve</classname> can be used
            to build the interpreted absolute URI used to generate the final request. This method
            includes the last fragment identifier from the redirect requests or the original
            request.</para>
        <programlisting><![CDATA[
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpClientContext context = HttpClientContext.create();
HttpGet httpget = new HttpGet("http://localhost:8080/");
CloseableHttpResponse response = httpclient.execute(httpget, context);
try {
    HttpHost target = context.getTargetHost();
    List<URI> redirectLocations = context.getRedirectLocations();
    URI location = URIUtils.resolve(httpget.getURI(), target, redirectLocations);
    System.out.println("Final HTTP location: " + location.toASCIIString());
    // Expected to be an absolute URI
} finally {
    response.close();
}
]]></programlisting>

</chapter>


text:
module.exports = {

    $container: null,
    $element: null,
    $button: null,

    SETTINGS: {
        open: false,
    },

    start: function(data) {
        var self = this;

        $.extend( self.SETTINGS, data );

        var debugBoxClass = 'debug-box debug-box--console';
        if (!self.SETTINGS.open) {
            debugBoxClass += ' debug-box--hide';
        }

        var debugBox = $(`<div class='${debugBoxClass}' id='debug-box-console'></div>`);
        var debugBoxButton = $("
FrontBox console
");
        var debugBoxContainer = $("

");

        ELEMENTS.$body.append(debugBox);
        self.$element = $("#debug-box-console");

        self.$element.append(debugBoxButton);
        self.$element.append(debugBoxContainer);

        self.$button = $("#debug-box-console-button");
        self.$container = $("#debug-box-console-container");

        var toggleDebugBox = () => {
            console.log("a");
            self.$element.toggleClass("debug-box--hide");
        };

        self.$button.on("click", toggleDebugBox);

    },

    add: function(addString, addonClass = '') {
        var self = this;

        self.$container.prepend("
"+addString+"
");
    },

};