From d2893ace068d11f6ad88828ee1cb7bcfdbfe1a33 Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Fri, 28 Jun 2024 16:41:36 +0200 Subject: [PATCH] revert: read / write timeouts --- net/http/roundtripware/circuitbreaker_test.go | 17 +++++------- service/http.go | 26 ++++++++++--------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/net/http/roundtripware/circuitbreaker_test.go b/net/http/roundtripware/circuitbreaker_test.go index 79ce7ec..36804b4 100644 --- a/net/http/roundtripware/circuitbreaker_test.go +++ b/net/http/roundtripware/circuitbreaker_test.go @@ -14,6 +14,7 @@ import ( keelhttp "github.com/foomo/keel/net/http" "github.com/foomo/keel/net/http/roundtripware" "github.com/sony/gobreaker" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" ) @@ -138,11 +139,9 @@ func TestCircuitBreakerCopyBodies(t *testing.T) { // create http server with handler svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { data, err := io.ReadAll(r.Body) - require.NoError(t, err) - require.Equal(t, string(data), requestData) - _, err = w.Write([]byte(responseData)) - if err != nil { - panic(err) + if assert.NoError(t, err) && assert.Equal(t, string(data), requestData) { + _, err = w.Write([]byte(responseData)) + assert.NoError(t, err) } })) defer svr.Close() @@ -194,11 +193,9 @@ func TestCircuitBreakerReadFromNotCopiedBodies(t *testing.T) { // create http server with handler svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { data, err := io.ReadAll(r.Body) - require.NoError(t, err) - require.Equal(t, string(data), requestData) - _, err = w.Write([]byte(responseData)) - if err != nil { - panic(err) + if assert.NoError(t, err) && assert.Equal(t, string(data), requestData) { + _, err = w.Write([]byte(responseData)) + assert.NoError(t, err) } })) defer svr.Close() diff --git a/service/http.go b/service/http.go index 0e31523..5655467 100644 --- a/service/http.go +++ b/service/http.go @@ -18,10 +18,10 @@ import ( // HTTP struct type HTTP struct { - running atomic.Bool - server *http.Server - name string l *zap.Logger + name string + server *http.Server + running atomic.Bool } // ------------------------------------------------------------------------------------------------ @@ -39,16 +39,14 @@ func NewHTTP(l *zap.Logger, name, addr string, handler http.Handler, middlewares ) return &HTTP{ - server: &http.Server{ - Addr: addr, - ErrorLog: zap.NewStdLog(l), - IdleTimeout: 5 * time.Second, - ReadTimeout: 5 * time.Second, - WriteTimeout: 5 * time.Second, - Handler: middleware.Compose(l, name, handler, middlewares...), - }, - name: name, l: l, + name: name, + server: &http.Server{ + Addr: addr, + Handler: middleware.Compose(l, name, handler, middlewares...), + ErrorLog: zap.NewStdLog(l), + IdleTimeout: 30 * time.Second, + }, } } @@ -60,6 +58,10 @@ func (s *HTTP) Name() string { return s.name } +func (s *HTTP) Server() *http.Server { + return s.server +} + // ------------------------------------------------------------------------------------------------ // ~ Public methods // ------------------------------------------------------------------------------------------------