Skip to content

Commit

Permalink
fix: make it possible to disable the timeout (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Mar 1, 2021
1 parent bcc4200 commit 491fe0c
Show file tree
Hide file tree
Showing 4 changed files with 558 additions and 6 deletions.
13 changes: 7 additions & 6 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Mercure struct {
Demo string `json:"demo,omitempty"`

// Maximum duration before closing the connection, defaults to 600s, set to 0 to disable.
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
WriteTimeout *caddy.Duration `json:"write_timeout,omitempty"`

// Maximum dispatch duration of an update.
DispatchTimeout caddy.Duration `json:"dispatch_timeout,omitempty"`
Expand Down Expand Up @@ -145,8 +145,8 @@ func (m *Mercure) Provision(ctx caddy.Context) error { //nolint:funlen
return nil, fmt.Errorf("invalid transport url: %w", err)
}

if m.WriteTimeout != 0 {
u.Query().Set("write_timeout", time.Duration(m.WriteTimeout).String())
if m.WriteTimeout != nil {
u.Query().Set("write_timeout", time.Duration(*m.WriteTimeout).String())
}

transport, err := mercure.NewTransport(u, m.logger, tss)
Expand Down Expand Up @@ -192,8 +192,8 @@ func (m *Mercure) Provision(ctx caddy.Context) error { //nolint:funlen
if m.Subscriptions {
opts = append(opts, mercure.WithSubscriptions())
}
if d := m.WriteTimeout; d != 0 {
opts = append(opts, mercure.WithWriteTimeout(time.Duration(d)))
if d := m.WriteTimeout; d != nil {
opts = append(opts, mercure.WithWriteTimeout(time.Duration(*d)))
}
if d := m.DispatchTimeout; d != 0 {
opts = append(opts, mercure.WithDispatchTimeout(time.Duration(d)))
Expand Down Expand Up @@ -262,7 +262,8 @@ func (m *Mercure) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { //nolint:fu
return err //nolint:wrapcheck
}

m.WriteTimeout = caddy.Duration(d)
cd := caddy.Duration(d)
m.WriteTimeout = &cd

case "dispatch_timeout":
if !d.NextArg() {
Expand Down
1 change: 1 addition & 0 deletions caddy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dunglas/mercure/caddy v0.0.0-20210118203145-496b5d4b0853/go.mod h1:ZRBC/rBW0xn4Nrr58xMGpPNrto9LBOQ/aYVddFUwIhs=
github.com/dunglas/mercure/caddy v0.0.0-20210215213405-dc6a34ff0fee/go.mod h1:IzheXEsVT6DadQuDdxUz6Y8GFaNF+UIqidFl8xWhP/Y=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac h1:opbrjaN/L8gg6Xh5D04Tem+8xVcz6ajZlGCs49mQgyg=
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/dgraph-io/ristretto v0.0.3
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dunglas/mercure/caddy v0.0.0-20210215213405-dc6a34ff0fee // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gofrs/uuid v4.0.0+incompatible
Expand Down

0 comments on commit 491fe0c

Please sign in to comment.