Skip to content

Commit

Permalink
fix: don't overwrite write_timeout in transport URL if set (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Apr 20, 2023
1 parent 4f8b36d commit f4b3713
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ func (m *Mercure) Provision(ctx caddy.Context) error { //nolint:funlen

if m.WriteTimeout != nil {
query := u.Query()
query.Set("write_timeout", time.Duration(*m.WriteTimeout).String())
u.RawQuery = query.Encode()
if !query.Has("write_timeout") {
query.Set("write_timeout", time.Duration(*m.WriteTimeout).String())
u.RawQuery = query.Encode()
}
}

transport, err := mercure.NewTransport(u, m.logger)
Expand Down
12 changes: 9 additions & 3 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"go.uber.org/zap"
)

const (
DefaultWriteTimeout = 600 * time.Second
DefaultDispatchTimeout = 5 * time.Second
DefaultHeartbeat = 40 * time.Second
)

// ErrUnsupportedProtocolVersion is returned when the version passed is unsupported.
var ErrUnsupportedProtocolVersion = errors.New("compatibility mode only supports protocol version 7")

Expand Down Expand Up @@ -285,9 +291,9 @@ type Hub struct {
// NewHub creates a new Hub instance.
func NewHub(options ...Option) (*Hub, error) {
opt := &opt{
writeTimeout: 600 * time.Second,
dispatchTimeout: 5 * time.Second,
heartbeat: 40 * time.Second,
writeTimeout: DefaultWriteTimeout,
dispatchTimeout: DefaultDispatchTimeout,
heartbeat: DefaultHeartbeat,
}

for _, o := range options {
Expand Down

0 comments on commit f4b3713

Please sign in to comment.