예제 #1
0
func NewProxy(args ProxyArgs) Proxy {
	routeServiceConfig := routeservice.NewRouteServiceConfig(args.Logger, args.RouteServiceEnabled, args.RouteServiceTimeout, args.Crypto, args.CryptoPrev, args.RouteServiceRecommendHttps)

	p := &proxy{
		accessLogger: args.AccessLogger,
		traceKey:     args.TraceKey,
		ip:           args.Ip,
		logger:       args.Logger,
		registry:     args.Registry,
		reporter:     args.Reporter,
		transport: &http.Transport{
			Dial: func(network, addr string) (net.Conn, error) {
				conn, err := net.DialTimeout(network, addr, 5*time.Second)
				if err != nil {
					return conn, err
				}
				if args.EndpointTimeout > 0 {
					err = conn.SetDeadline(time.Now().Add(args.EndpointTimeout))
				}
				return conn, err
			},
			DisableKeepAlives:  true,
			DisableCompression: true,
			TLSClientConfig:    args.TLSConfig,
		},
		secureCookies:              args.SecureCookies,
		heartbeatOK:                args.HeartbeatOK, // 1->true, 0->false
		routeServiceConfig:         routeServiceConfig,
		extraHeadersToLog:          args.ExtraHeadersToLog,
		routeServiceRecommendHttps: args.RouteServiceRecommendHttps,
		healthCheckUserAgent:       args.HealthCheckUserAgent,
		forceForwardedProtoHttps:   args.ForceForwardedProtoHttps,
		defaultLoadBalance:         args.DefaultLoadBalance,
	}

	n := negroni.New()
	n.Use(&proxyWriterHandler{})
	n.Use(handlers.NewAccessLog(args.AccessLogger, args.ExtraHeadersToLog))
	n.Use(handlers.NewHealthcheck(args.HealthCheckUserAgent, p.heartbeatOK, args.Logger))
	n.Use(handlers.NewZipkin(args.EnableZipkin, args.ExtraHeadersToLog, args.Logger))

	n.UseHandler(p)
	handlers := &proxyHandler{
		handlers: n,
		proxy:    p,
	}

	return handlers
}
예제 #2
0
		nextCalled = true
	})

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("zipkin")
		body := bytes.NewBufferString("What are you?")
		req = test_util.NewRequest("GET", "example.com", "/", body)
		resp = httptest.NewRecorder()
		proxyWriter = utils.NewProxyResponseWriter(resp)

		extraHeadersToLog = []string{}

		accessLogger = &fakes.FakeAccessLogger{}

		handler = handlers.NewAccessLog(accessLogger, &extraHeadersToLog)

		nextCalled = false
	})

	AfterEach(func() {
		Expect(nextCalled).To(BeTrue(), "Expected the next handler to be called.")
	})

	It("sets an access log record on the context", func() {
		handler.ServeHTTP(proxyWriter, req, nextHandler)
		alr := proxyWriter.Context().Value("AccessLogRecord")
		Expect(alr).ToNot(BeNil())
		Expect(alr).To(BeAssignableToTypeOf(&schema.AccessLogRecord{}))
	})