Skip to content

Commit

Permalink
feat: configurable request header read timeout (#1664)
Browse files Browse the repository at this point in the history
* feat(config): read read header timeout value

This commit adds a request header read timeout configuration parameter.
As it is part of the downloading cycle, it is available under
`blocking/loading/downloads`.
The default value comes from `server/http.go` line 21.

Refs: #1653

* feat(server): get read header timeout from config

* feat(docs): document additional config parameter
  • Loading branch information
TheoTechnicguy authored Jan 1, 2025
1 parent 11a910a commit 49581ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@ func recoverToError(do func(context.Context) error, onPanic func(any) error) fun
}

type Downloader struct {
Timeout Duration `yaml:"timeout" default:"5s"`
ReadTimeout Duration `yaml:"readTimeout" default:"20s"`
WriteTimeout Duration `yaml:"writeTimeout" default:"20s"`
Attempts uint `yaml:"attempts" default:"3"`
Cooldown Duration `yaml:"cooldown" default:"500ms"`
Timeout Duration `yaml:"timeout" default:"5s"`
ReadTimeout Duration `yaml:"readTimeout" default:"20s"`
ReadHeaderTimeout Duration `yaml:"readHeaderTimeout" default:"20s"`
WriteTimeout Duration `yaml:"writeTimeout" default:"20s"`
Attempts uint `yaml:"attempts" default:"3"`
Cooldown Duration `yaml:"cooldown" default:"500ms"`
}

func (c *Downloader) LogConfig(logger *logrus.Entry) {
Expand Down
4 changes: 4 additions & 0 deletions docs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ blocking:
# To disable this timeout, set to 0.
# default: 20s
readTimeout: 60s
# optional: timeout for reading request headers for the download (each url). Use large values for slow internet connections
# to disable, set to -1.
# default: 20s
readHeaderTimeout: 60s
# optional: Maximum download attempts
# default: 3
attempts: 5
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ Configures how HTTP(S) sources are downloaded:
| timeout | duration | no | 5s | Download attempt timeout |
| writeTimeout | duration | no | 20s | File write attempt timeout |
| readTimeout | duration | no | 20s | Download request read timeout |
| readHeaderTimeout | duration | no | 20s | Download request header read timeout |
| attempts | int | no | 3 | How many download attempts should be performed |
| cooldown | duration | no | 500ms | Time between the download attempts |

Expand Down
14 changes: 5 additions & 9 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ type httpServer struct {
}

func newHTTPServer(name string, handler http.Handler, cfg *config.Config) *httpServer {
const (
readHeaderTimeout = 20 * time.Second
)

var (
writeTimeout = cfg.Blocking.Loading.Downloads.WriteTimeout
readTimeout = cfg.Blocking.Loading.Downloads.ReadTimeout
writeTimeout = cfg.Blocking.Loading.Downloads.WriteTimeout
readTimeout = cfg.Blocking.Loading.Downloads.ReadTimeout
readHeaderTimeout = cfg.Blocking.Loading.Downloads.ReadHeaderTimeout
)

return &httpServer{
inner: http.Server{
ReadTimeout: time.Duration(readTimeout),
ReadHeaderTimeout: readHeaderTimeout,
ReadHeaderTimeout: time.Duration(readHeaderTimeout),
WriteTimeout: time.Duration(writeTimeout),

Handler: withCommonMiddleware(handler),
Handler: withCommonMiddleware(handler),
},

name: name,
Expand Down

0 comments on commit 49581ff

Please sign in to comment.