revert: read / write timeouts

This commit is contained in:
Kevin Franklin Kim 2024-06-28 16:41:36 +02:00
parent 9d38e438ce
commit d2893ace06
No known key found for this signature in database
2 changed files with 21 additions and 22 deletions

View File

@ -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()

View File

@ -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
// ------------------------------------------------------------------------------------------------