Beispiel #1
0
func makeGHEntryForSingleBackendRoute(r route) guardAndHandler {
	guardFn := makeGuardFunction(r)

	tlsConfig := &tls.Config{RootCAs: r.Backends[0].CACert}

	requestHandler := &requestHandler{
		Transport:    &http.Transport{DisableKeepAlives: false, DisableCompression: false},
		TLSTransport: &http.Transport{DisableKeepAlives: false, DisableCompression: false, TLSClientConfig: tlsConfig},
		Backend:      r.Backends[0],
	}

	handlerFn := requestHandler.toHandlerFunc()

	handler := plugin.WrapHandlerFunc(handlerFn, r.WrapperFactories)

	ghEntry := guardAndHandler{Guard: guardFn, HandlerFn: handler}

	return ghEntry
}
Beispiel #2
0
func makeGHEntryForMultipleBackends(r route) guardAndHandler {
	guardFn := makeGuardFunction(r)

	//Create a backend handler map that will map the backend name to the
	//wrapped handler for the backend
	var handlerMap plugin.BackendHandlerMap = make(plugin.BackendHandlerMap)

	//Lookup the factory for the multiroute handler
	factoryName := r.MultiBackendPluginName
	factory, err := plugin.LookupMultiBackendAdapterFactory(factoryName)
	if err != nil {
		//Note: this panic is at start up/configuration time, and is meant to prevent the startup
		//of a misconfigured listener.
		panic("Cannot configure service - no such MultiRoutePluginName: " + factoryName)
	}

	//Go through the backends and build a handler for each
	for _, backend := range r.Backends {
		log.Debug("handler for ", backend.Name)

		tlsConfig := &tls.Config{RootCAs: backend.CACert}
		requestHandler := &requestHandler{
			Transport:    &http.Transport{DisableKeepAlives: false, DisableCompression: false},
			TLSTransport: &http.Transport{DisableKeepAlives: false, DisableCompression: false, TLSClientConfig: tlsConfig},
			Backend:      backend,
		}

		handlerFn := requestHandler.toHandlerFunc()

		handlerMap[backend.Name] = http.HandlerFunc(handlerFn)
	}

	//Use the factory to create a wrapped handler that can service the requests
	log.Info("creating handler via factory using", handlerMap)
	multiRouteHandler := factory(handlerMap)

	//Now wrap the handler function with the plugins.
	handler := plugin.WrapHandlerFunc(multiRouteHandler.ToHandlerFunc(), r.WrapperFactories)

	return guardAndHandler{Guard: guardFn, HandlerFn: handler}
}