Skip to content

Commit

Permalink
feat(server): get write timeout from config
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoTechnicguy committed Dec 4, 2024
1 parent 3b067e0 commit fd5be7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"time"

"github.com/0xERR0R/blocky/config"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
)
Expand All @@ -16,18 +17,21 @@ type httpServer struct {
name string
}

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

var (
writeTimeout = cfg.Blocking.Loading.Downloads.WriteTimeout
)

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

Handler: withCommonMiddleware(handler),
},
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ func NewServer(ctx context.Context, cfg *config.Config) (server *Server, err err
server.registerDoHEndpoints(httpRouter)

if len(cfg.Ports.HTTP) != 0 {
srv := newHTTPServer("http", httpRouter)
srv := newHTTPServer("http", httpRouter, cfg)

for _, l := range httpListeners {
server.servers[l] = srv
}
}

if len(cfg.Ports.HTTPS) != 0 {
srv := newHTTPServer("https", httpRouter)
srv := newHTTPServer("https", httpRouter, cfg)

for _, l := range httpsListeners {
server.servers[l] = srv
Expand Down

0 comments on commit fd5be7a

Please sign in to comment.