@@ -3,7 +3,6 @@ package upstream
7 "encoding/json"
6 "encoding/json"
@@ -23,9 +22,8 @@ import (
25var _ = Describe("HTTP Upstream Suite", func() {
24var _ = Describe("HTTP Upstream Suite", func() {
26−
25+ defaultFlushInterval := options.Duration(options.DefaultUpstreamFlushInterval)
27− const flushInterval5s = options.Duration(5 * time.Second)
26+ defaultTimeout := options.Duration(options.DefaultUpstreamTimeout)
28− const flushInterval1s = options.Duration(1 * time.Second)
29 truth := true
27 truth := true
30 falsum := false
28 falsum := false
@@ -62,12 +60,15 @@ var _ = Describe("HTTP Upstream Suite", func() {
63 flush := options.Duration(1 * time.Second)
61 flush := options.Duration(1 * time.Second)
63+ timeout := options.Duration(options.DefaultUpstreamTimeout)
65 upstream := options.Upstream{
65 upstream := options.Upstream{
66 ID: in.id,
66 ID: in.id,
67 PassHostHeader: &in.passUpstreamHostHeader,
67 PassHostHeader: &in.passUpstreamHostHeader,
68 ProxyWebSockets: &falsum,
68 ProxyWebSockets: &falsum,
69 InsecureSkipTLSVerify: false,
69 InsecureSkipTLSVerify: false,
70 FlushInterval: &flush,
70 FlushInterval: &flush,
73 Expect(in.serverAddr).ToNot(BeNil())
74 Expect(in.serverAddr).ToNot(BeNil())
@@ -318,13 +319,13 @@ var _ = Describe("HTTP Upstream Suite", func() {
318 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
319 req = middlewareapi.AddRequestScope(req, &middlewareapi.RequestScope{})
319 rw := httptest.NewRecorder()
320 rw := httptest.NewRecorder()
321− flush := options.Duration(1 * time.Second)
322 upstream := options.Upstream{
322 upstream := options.Upstream{
323 ID: "noPassHost",
323 ID: "noPassHost",
324 PassHostHeader: &falsum,
324 PassHostHeader: &falsum,
325 ProxyWebSockets: &falsum,
325 ProxyWebSockets: &falsum,
326 InsecureSkipTLSVerify: false,
326 InsecureSkipTLSVerify: false,
327− FlushInterval: &flush,
327+ FlushInterval: &defaultFlushInterval,
328+ Timeout: &defaultTimeout,
330 u, err := url.Parse(serverAddr)
331 u, err := url.Parse(serverAddr)
@@ -354,6 +355,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
354 skipVerify bool
355 skipVerify bool
355 sigData *options.SignatureData
356 sigData *options.SignatureData
356 errorHandler func(http.ResponseWriter, *http.Request, error)
357 errorHandler func(http.ResponseWriter, *http.Request, error)
358+ timeout options.Duration
359 DescribeTable("newHTTPUpstreamProxy",
361 DescribeTable("newHTTPUpstreamProxy",
@@ -366,6 +368,7 @@ var _ = Describe("HTTP Upstream Suite", func() {
366 FlushInterval: &in.flushInterval,
368 FlushInterval: &in.flushInterval,
367 InsecureSkipTLSVerify: in.skipVerify,
369 InsecureSkipTLSVerify: in.skipVerify,
368 ProxyWebSockets: &in.proxyWebSockets,
370 ProxyWebSockets: &in.proxyWebSockets,
371+ Timeout: &in.timeout,
371 handler := newHTTPUpstreamProxy(upstream, u, in.sigData, in.errorHandler)
374 handler := newHTTPUpstreamProxy(upstream, u, in.sigData, in.errorHandler)
@@ -380,49 +383,63 @@ var _ = Describe("HTTP Upstream Suite", func() {
380 proxy, ok := upstreamProxy.handler.(*httputil.ReverseProxy)
383 proxy, ok := upstreamProxy.handler.(*httputil.ReverseProxy)
381 Expect(ok).To(BeTrue())
384 Expect(ok).To(BeTrue())
382 Expect(proxy.FlushInterval).To(Equal(in.flushInterval.Duration()))
385 Expect(proxy.FlushInterval).To(Equal(in.flushInterval.Duration()))
386+ transport, ok := proxy.Transport.(*http.Transport)
387+ Expect(ok).To(BeTrue())
388+ Expect(transport.ResponseHeaderTimeout).To(Equal(in.timeout.Duration()))
383 Expect(proxy.ErrorHandler != nil).To(Equal(in.errorHandler != nil))
389 Expect(proxy.ErrorHandler != nil).To(Equal(in.errorHandler != nil))
384 if in.skipVerify {
390 if in.skipVerify {
385− Expect(proxy.Transport).To(Equal(&http.Transport{
391+ Expect(transport.TLSClientConfig.InsecureSkipVerify).To(Equal(true))
386− TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
390 Entry("with proxy websockets", &newUpstreamTableInput{
394 Entry("with proxy websockets", &newUpstreamTableInput{
391 proxyWebSockets: true,
395 proxyWebSockets: true,
392− flushInterval: flushInterval1s,
396+ flushInterval: defaultFlushInterval,
393 skipVerify: false,
397 skipVerify: false,
394 sigData: nil,
398 sigData: nil,
395 errorHandler: nil,
399 errorHandler: nil,
400+ timeout: defaultTimeout,
397 Entry("with a non standard flush interval", &newUpstreamTableInput{
402 Entry("with a non standard flush interval", &newUpstreamTableInput{
398 proxyWebSockets: false,
403 proxyWebSockets: false,
399− flushInterval: flushInterval5s,
404+ flushInterval: options.Duration(5 * time.Second),
400 skipVerify: false,
405 skipVerify: false,
401 sigData: nil,
406 sigData: nil,
402 errorHandler: nil,
407 errorHandler: nil,
408+ timeout: defaultTimeout,
404 Entry("with a InsecureSkipTLSVerify", &newUpstreamTableInput{
410 Entry("with a InsecureSkipTLSVerify", &newUpstreamTableInput{
405 proxyWebSockets: false,
411 proxyWebSockets: false,
406− flushInterval: flushInterval1s,
412+ flushInterval: defaultFlushInterval,
407 skipVerify: true,
413 skipVerify: true,
408 sigData: nil,
414 sigData: nil,
409 errorHandler: nil,
415 errorHandler: nil,
416+ timeout: defaultTimeout,
411 Entry("with a SignatureData", &newUpstreamTableInput{
418 Entry("with a SignatureData", &newUpstreamTableInput{
412 proxyWebSockets: false,
419 proxyWebSockets: false,
413− flushInterval: flushInterval1s,
420+ flushInterval: defaultFlushInterval,
414 skipVerify: false,
421 skipVerify: false,
415 sigData: &options.SignatureData{Hash: crypto.SHA256, Key: "secret"},
422 sigData: &options.SignatureData{Hash: crypto.SHA256, Key: "secret"},
416 errorHandler: nil,
423 errorHandler: nil,
424+ timeout: defaultTimeout,
418 Entry("with an error handler", &newUpstreamTableInput{
426 Entry("with an error handler", &newUpstreamTableInput{
419 proxyWebSockets: false,
427 proxyWebSockets: false,
420− flushInterval: flushInterval1s,
428+ flushInterval: defaultFlushInterval,
421 skipVerify: false,
429 skipVerify: false,
422 sigData: nil,
430 sigData: nil,
423 errorHandler: func(rw http.ResponseWriter, req *http.Request, arg3 error) {
431 errorHandler: func(rw http.ResponseWriter, req *http.Request, arg3 error) {
424 rw.WriteHeader(502)
432 rw.WriteHeader(502)
434+ timeout: defaultTimeout,
436+ Entry("with a non-default timeout", &newUpstreamTableInput{
437+ proxyWebSockets: false,
438+ flushInterval: defaultFlushInterval,
442+ timeout: options.Duration(5 * time.Second),
@@ -431,12 +448,14 @@ var _ = Describe("HTTP Upstream Suite", func() {
432 BeforeEach(func() {
449 BeforeEach(func() {
433 flush := options.Duration(1 * time.Second)
450 flush := options.Duration(1 * time.Second)
451+ timeout := options.Duration(options.DefaultUpstreamTimeout)
434 upstream := options.Upstream{
452 upstream := options.Upstream{
435 ID: "websocketProxy",
453 ID: "websocketProxy",
436 PassHostHeader: &truth,
454 PassHostHeader: &truth,
437 ProxyWebSockets: &truth,
455 ProxyWebSockets: &truth,
438 InsecureSkipTLSVerify: false,
456 InsecureSkipTLSVerify: false,
439 FlushInterval: &flush,
457 FlushInterval: &flush,
442 u, err := url.Parse(serverAddr)
461 u, err := url.Parse(serverAddr)